snapshot of https://github.com/tauri-apps/tauri.git (dev, 2026-09-23; blobs > 131072B omitted)
Some checks failed
Audit / audit-js (push) Failing after 0s
bench / bench (map[os:ubuntu-latest runner:xvfb-run --auto-servernum target:x86_64-unknown-linux-gnu], nightly) (push) Failing after 0s
covector version or publish / run-integration-tests (ubuntu-latest) (push) Failing after 0s
Audit / audit-rust (push) Failing after 0s
test `@tauri-apps/cli` / test (ubuntu-latest) (push) Failing after 0s
test `tauri-cli` / test (map[os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
deploy schema worker / deploy (push) Failing after 0s
lint rust / clippy (map[cargo:cargo include: os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
lint rust / clippy (map[cargo:cross include:--package api os:ubuntu-latest target:aarch64-linux-android]) (push) Failing after 0s
supply chain health status / check rust dependencies with cargo vet (push) Failing after 0s
test `@tauri-apps/api` e2e (mobile) / android (push) Failing after 0s
test `@tauri-apps/api` e2e / test (map[name:Linux os:ubuntu-latest]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
Udeps / changes (push) Failing after 0s
Udeps / setup (push) Has been skipped
Udeps / udeps (push) Has been skipped
bench / bench (map[os:macos-latest runner: target:aarch64-apple-darwin], nightly) (push) Has been cancelled
bench / bench (map[os:windows-latest runner: target:x86_64-pc-windows-msvc], nightly) (push) Has been cancelled
covector version or publish / run-integration-tests (macos-latest) (push) Has been cancelled
covector version or publish / run-integration-tests (windows-latest) (push) Has been cancelled
covector version or publish / version-or-publish (push) Has been cancelled
test `@tauri-apps/cli` / test (macos-latest) (push) Has been cancelled
test `tauri-cli` / test (map[args:--no-default-features --features native-tls-vendored os:windows-latest restore-only:true target:aarch64-pc-windows-msvc]) (push) Has been cancelled
test `tauri-cli` / test (map[os:macos-latest target:x86_64-apple-darwin]) (push) Has been cancelled
test `tauri-cli` / test (map[os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:macos-latest target:aarch64-apple-darwin]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include:--package api os:macos-latest target:aarch64-apple-ios]) (push) Has been cancelled
test `@tauri-apps/api` e2e (mobile) / ios (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:Windows os:windows-latest]) (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:macOS os:macos-latest]) (push) Has been cancelled
test `@tauri-apps/cli` / test (windows-latest) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
Some checks failed
Audit / audit-js (push) Failing after 0s
bench / bench (map[os:ubuntu-latest runner:xvfb-run --auto-servernum target:x86_64-unknown-linux-gnu], nightly) (push) Failing after 0s
covector version or publish / run-integration-tests (ubuntu-latest) (push) Failing after 0s
Audit / audit-rust (push) Failing after 0s
test `@tauri-apps/cli` / test (ubuntu-latest) (push) Failing after 0s
test `tauri-cli` / test (map[os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
deploy schema worker / deploy (push) Failing after 0s
lint rust / clippy (map[cargo:cargo include: os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
lint rust / clippy (map[cargo:cross include:--package api os:ubuntu-latest target:aarch64-linux-android]) (push) Failing after 0s
supply chain health status / check rust dependencies with cargo vet (push) Failing after 0s
test `@tauri-apps/api` e2e (mobile) / android (push) Failing after 0s
test `@tauri-apps/api` e2e / test (map[name:Linux os:ubuntu-latest]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
Udeps / changes (push) Failing after 0s
Udeps / setup (push) Has been skipped
Udeps / udeps (push) Has been skipped
bench / bench (map[os:macos-latest runner: target:aarch64-apple-darwin], nightly) (push) Has been cancelled
bench / bench (map[os:windows-latest runner: target:x86_64-pc-windows-msvc], nightly) (push) Has been cancelled
covector version or publish / run-integration-tests (macos-latest) (push) Has been cancelled
covector version or publish / run-integration-tests (windows-latest) (push) Has been cancelled
covector version or publish / version-or-publish (push) Has been cancelled
test `@tauri-apps/cli` / test (macos-latest) (push) Has been cancelled
test `tauri-cli` / test (map[args:--no-default-features --features native-tls-vendored os:windows-latest restore-only:true target:aarch64-pc-windows-msvc]) (push) Has been cancelled
test `tauri-cli` / test (map[os:macos-latest target:x86_64-apple-darwin]) (push) Has been cancelled
test `tauri-cli` / test (map[os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:macos-latest target:aarch64-apple-darwin]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include:--package api os:macos-latest target:aarch64-apple-ios]) (push) Has been cancelled
test `@tauri-apps/api` e2e (mobile) / ios (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:Windows os:windows-latest]) (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:macOS os:macos-latest]) (push) Has been cancelled
test `@tauri-apps/cli` / test (windows-latest) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
This commit is contained in:
195
crates/tauri-schema-worker/src/config.rs
Normal file
195
crates/tauri-schema-worker/src/config.rs
Normal file
@@ -0,0 +1,195 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// axum Error is too large
|
||||
#![allow(clippy::result_large_err)]
|
||||
|
||||
use anyhow::Context;
|
||||
use axum::{
|
||||
Router,
|
||||
extract::Path,
|
||||
http::{HeaderValue, StatusCode, header},
|
||||
response::{IntoResponse, Result},
|
||||
routing::get,
|
||||
};
|
||||
use semver::{Version, VersionReq};
|
||||
use serde::Deserialize;
|
||||
use worker::*;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct CrateReleases {
|
||||
pub versions: Vec<CrateRelease>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct CrateRelease {
|
||||
#[serde(alias = "num")]
|
||||
pub version: Version,
|
||||
pub yanked: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct CrateMetadataFull {
|
||||
#[serde(rename = "crate")]
|
||||
pub crate_: CrateMetadata,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct CrateMetadata {
|
||||
pub max_stable_version: Version,
|
||||
}
|
||||
|
||||
const USERAGENT: &str = "tauri-schema-worker (contact@tauri.app)";
|
||||
|
||||
pub fn router() -> Router {
|
||||
Router::new()
|
||||
.route("/config", get(stable_schema))
|
||||
.route("/config/latest", get(stable_schema))
|
||||
.route("/config/stable", get(stable_schema))
|
||||
.route("/config/next", get(next_schema)) // pre-releases versions, (rc, alpha and beta)
|
||||
.route("/config/{version}", get(schema_for_version))
|
||||
}
|
||||
|
||||
async fn schema_for_version(Path(version): Path<String>) -> Result<JsonResponse> {
|
||||
try_schema_for_version(version)
|
||||
.await
|
||||
.map(JsonResponse)
|
||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
async fn stable_schema() -> Result<JsonResponse> {
|
||||
try_stable_schema()
|
||||
.await
|
||||
.map(JsonResponse)
|
||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
async fn next_schema() -> Result<JsonResponse> {
|
||||
try_next_schema()
|
||||
.await
|
||||
.map(JsonResponse)
|
||||
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
#[worker::send]
|
||||
async fn try_schema_for_version(version: String) -> anyhow::Result<String> {
|
||||
let version = version.parse::<VersionReq>()?;
|
||||
|
||||
let releases = crate_releases("tauri").await?;
|
||||
|
||||
if releases.is_empty() {
|
||||
return try_stable_schema().await;
|
||||
}
|
||||
|
||||
let Some(version) = releases.into_iter().find(|r| version.matches(&r.version)) else {
|
||||
return try_stable_schema().await;
|
||||
};
|
||||
|
||||
schema_file_for_version(version.version).await
|
||||
}
|
||||
|
||||
#[worker::send]
|
||||
async fn try_stable_schema() -> anyhow::Result<String> {
|
||||
let max = stable_version("tauri").await?;
|
||||
schema_file_for_version(max).await
|
||||
}
|
||||
|
||||
#[worker::send]
|
||||
async fn try_next_schema() -> anyhow::Result<String> {
|
||||
let releases = crate_releases("tauri").await?;
|
||||
let version = releases
|
||||
.into_iter()
|
||||
.filter(|r| !r.version.pre.is_empty())
|
||||
.map(|r| r.version)
|
||||
.max()
|
||||
.context("Couldn't find latest pre-release")?;
|
||||
schema_file_for_version(version).await
|
||||
}
|
||||
|
||||
async fn schema_file_for_version(version: Version) -> anyhow::Result<String> {
|
||||
let cache = Cache::open("schema".to_string()).await;
|
||||
let cache_key = format!("https://schema.tauri.app/config/{version}");
|
||||
if let Some(mut cached) = cache.get(cache_key.clone(), true).await? {
|
||||
console_log!("Serving schema for {version} from cache");
|
||||
return cached.text().await.map_err(Into::into);
|
||||
}
|
||||
|
||||
console_log!("Fetching schema for {version} from remote");
|
||||
|
||||
let path = if version.major >= 2 {
|
||||
"crates/tauri-schema-generator/schemas/config.schema.json"
|
||||
} else {
|
||||
"core/tauri-config-schema/schema.json"
|
||||
};
|
||||
let url = format!("https://raw.githubusercontent.com/tauri-apps/tauri/tauri-v{version}/{path}");
|
||||
let mut res = Fetch::Request(fetch_req(&url)?).send().await?;
|
||||
|
||||
cache.put(cache_key, res.cloned()?).await?;
|
||||
|
||||
res.text().await.map_err(Into::into)
|
||||
}
|
||||
|
||||
async fn crate_releases(crate_: &str) -> anyhow::Result<Vec<CrateRelease>> {
|
||||
let url = format!("https://crates.io/api/v1/crates/{crate_}/versions");
|
||||
let mut res = Fetch::Request(fetch_req(&url)?).send().await?;
|
||||
|
||||
let versions: CrateReleases = res.json().await?;
|
||||
let versions = versions.versions;
|
||||
|
||||
let flt = |r: &CrateRelease| r.yanked == Some(false);
|
||||
Ok(versions.into_iter().filter(flt).collect())
|
||||
}
|
||||
|
||||
async fn stable_version(crate_: &str) -> anyhow::Result<Version> {
|
||||
let url = format!("https://crates.io/api/v1/crates/{crate_}");
|
||||
let mut res = Fetch::Request(fetch_req(&url)?).send().await?;
|
||||
let metadata: CrateMetadataFull = res.json().await?;
|
||||
Ok(metadata.crate_.max_stable_version)
|
||||
}
|
||||
|
||||
fn fetch_req(url: &str) -> anyhow::Result<worker::Request> {
|
||||
let headers = Headers::new();
|
||||
headers.append(header::USER_AGENT.as_str(), USERAGENT)?;
|
||||
|
||||
worker::Request::new_with_init(
|
||||
url,
|
||||
&RequestInit {
|
||||
method: Method::Get,
|
||||
headers,
|
||||
cf: CfProperties {
|
||||
cache_ttl: Some(86400),
|
||||
cache_everything: Some(true),
|
||||
cache_ttl_by_status: Some(
|
||||
[
|
||||
("200-299".to_string(), 86400),
|
||||
("404".to_string(), 1),
|
||||
("500-599".to_string(), 0),
|
||||
]
|
||||
.into(),
|
||||
),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
struct JsonResponse(String);
|
||||
|
||||
impl IntoResponse for JsonResponse {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
(
|
||||
[(
|
||||
header::CONTENT_TYPE,
|
||||
HeaderValue::from_static("application/json"),
|
||||
)],
|
||||
self.0,
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
}
|
||||
27
crates/tauri-schema-worker/src/lib.rs
Normal file
27
crates/tauri-schema-worker/src/lib.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use axum::{Router, routing::get};
|
||||
use tower_service::Service;
|
||||
use worker::*;
|
||||
|
||||
mod config;
|
||||
|
||||
#[worker::event(fetch)]
|
||||
async fn main(
|
||||
req: HttpRequest,
|
||||
_env: Env,
|
||||
_ctx: Context,
|
||||
) -> worker::Result<axum::http::Response<axum::body::Body>> {
|
||||
console_error_panic_hook::set_once();
|
||||
Ok(router().call(req).await?)
|
||||
}
|
||||
|
||||
fn router() -> Router {
|
||||
Router::new().route("/", get(root)).merge(config::router())
|
||||
}
|
||||
|
||||
async fn root() -> &'static str {
|
||||
"tauri schema worker"
|
||||
}
|
||||
Reference in New Issue
Block a user