Skip to content

Commit a178f95

Browse files
feat: config schema generator (#5193)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
1 parent cc186c7 commit a178f95

37 files changed

Lines changed: 3127 additions & 157 deletions

File tree

‎.changes/config.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@
232232
"path": "./tooling/cli/node",
233233
"manager": "javascript",
234234
"dependencies": ["cli.rs"],
235-
"postversion": "node ../../../.scripts/covector/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }",
235+
"postversion": [
236+
"node ../../../.scripts/covector/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }",
237+
"cargo build --manifest-path ../../core/config-schema/Cargo.toml"
238+
],
236239
"prepublish": [],
237240
"publish": [],
238241
"postpublish": []
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-utils": minor
3+
---
4+
5+
`PatternKind::Isolation` is now defined even without the `isolation` feature.

‎.github/workflows/artifacts-updater.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ jobs:
128128
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
129129
# Updater signature is exposed here to make sure it works in PR's
130130
TAURI_PRIVATE_KEY: dW50cnVzdGVkIGNvbW1lbnQ6IHJzaWduIGVuY3J5cHRlZCBzZWNyZXQga2V5ClJXUlRZMEl5YTBGV3JiTy9lRDZVd3NkL0RoQ1htZmExNDd3RmJaNmRMT1ZGVjczWTBKZ0FBQkFBQUFBQUFBQUFBQUlBQUFBQWdMekUzVkE4K0tWQ1hjeGt1Vkx2QnRUR3pzQjVuV0ZpM2czWXNkRm9hVUxrVnB6TUN3K1NheHJMREhQbUVWVFZRK3NIL1VsMDBHNW5ET1EzQno0UStSb21nRW4vZlpTaXIwZFh5ZmRlL1lSN0dKcHdyOUVPclVvdzFhVkxDVnZrbHM2T1o4Tk1NWEU9Cg==
131+
TAURI_KEY_PASSWORD:
131132
# run on PRs and forks
132133
- name: build sample artifacts (updater)
133134
if: steps.enablecodesigning.outputs.enabled != 'true'
@@ -137,6 +138,7 @@ jobs:
137138
cargo tauri build --verbose
138139
env:
139140
TAURI_PRIVATE_KEY: dW50cnVzdGVkIGNvbW1lbnQ6IHJzaWduIGVuY3J5cHRlZCBzZWNyZXQga2V5ClJXUlRZMEl5YTBGV3JiTy9lRDZVd3NkL0RoQ1htZmExNDd3RmJaNmRMT1ZGVjczWTBKZ0FBQkFBQUFBQUFBQUFBQUlBQUFBQWdMekUzVkE4K0tWQ1hjeGt1Vkx2QnRUR3pzQjVuV0ZpM2czWXNkRm9hVUxrVnB6TUN3K1NheHJMREhQbUVWVFZRK3NIL1VsMDBHNW5ET1EzQno0UStSb21nRW4vZlpTaXIwZFh5ZmRlL1lSN0dKcHdyOUVPclVvdzFhVkxDVnZrbHM2T1o4Tk1NWEU9Cg==
141+
TAURI_KEY_PASSWORD:
140142
# upload assets
141143
- uses: actions/upload-artifact@v2
142144
if: matrix.platform == 'ubuntu-latest'

‎.github/workflows/check-generated-files.yml‎

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- 'core/tauri/scripts/bundle.global.js'
1313
- 'core/tauri-utils/src/config.rs'
1414
- 'tooling/cli/schema.json'
15+
- 'core/config-schema/schema.json'
1516

1617
concurrency:
1718
group: ${{ github.workflow }}-${{ github.ref }}
@@ -35,6 +36,7 @@ jobs:
3536
schema:
3637
- 'core/tauri-utils/src/config.rs'
3738
- 'tooling/cli/schema.json'
39+
- 'core/config-schema/schema.json'
3840
3941
check-bundle:
4042
runs-on: ubuntu-latest
@@ -63,18 +65,12 @@ jobs:
6365
override: true
6466

6567
- name: install Linux dependencies
66-
if: matrix.platform == 'ubuntu-latest'
6768
run: |
6869
sudo apt-get update
6970
sudo apt-get install -y libgtk-3-dev
7071
7172
- name: Get current date
7273
run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
73-
if: matrix.platform == 'macos-latest' || matrix.platform == 'ubuntu-latest'
74-
75-
- name: Get current date
76-
if: matrix.platform == 'windows-latest'
77-
run: echo "CURRENT_DATE=$(Get-Date -Format "yyyy-MM-dd")" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
7874

7975
- name: Cache cargo state
8076
uses: actions/cache@v2
@@ -85,33 +81,33 @@ jobs:
8581
~/.cargo/registry
8682
~/.cargo/git
8783
~/.cargo/bin
88-
key: ${{ matrix.platform }}-stable-${{ env.cache-name }}-${{ hashFiles('**/Cargo.toml') }}-${{ env.CURRENT_DATE }}
84+
key: ubuntu-latest-stable-${{ env.cache-name }}-${{ hashFiles('**/Cargo.toml') }}-${{ env.CURRENT_DATE }}
8985
restore-keys: |
90-
${{ matrix.platform }}-stable-${{ env.cache-name }}-${{ hashFiles('**/Cargo.toml') }}-
91-
${{ matrix.platform }}-stable-${{ env.cache-name }}-
92-
${{ matrix.platform }}-stable-
93-
${{ matrix.platform }}-
86+
ubuntu-latest-stable-${{ env.cache-name }}-${{ hashFiles('**/Cargo.toml') }}-
87+
ubuntu-latest-stable-${{ env.cache-name }}-
88+
ubuntu-latest-stable-
89+
ubuntu-latest-
9490
95-
- name: Cache CLI cargo target
91+
- name: Cache core cargo target
9692
uses: actions/cache@v2
9793
env:
98-
cache-name: cargo_cli
94+
cache-name: cargo-core
9995
with:
100-
path: tooling/cli/target
96+
path: target
10197
# Add date to the cache to keep it up to date
102-
key: ${{ matrix.platform }}-stable-${{ env.cache-name }}-${{ hashFiles('tooling/cli/Cargo.lock') }}-${{ env.CURRENT_DATE }}
98+
key: ubuntu-latest-stable-${{ env.cache-name }}-${{ hashFiles('core/**/Cargo.toml') }}-${{ env.CURRENT_DATE }}
10399
# Restore from outdated cache for speed
104100
restore-keys: |
105-
${{ matrix.platform }}-stable-${{ env.cache-name }}-${{ hashFiles('tooling/cli/Cargo.lock') }}
106-
${{ matrix.platform }}-stable-${{ env.cache-name }}-
107-
${{ matrix.platform }}-stable-
108-
${{ matrix.platform }}-
101+
ubuntu-latest-stable-${{ env.cache-name }}-${{ hashFiles('core/**/Cargo.toml') }}
102+
ubuntu-latest-stable-${{ env.cache-name }}-
103+
ubuntu-latest-stable-
104+
ubuntu-latest-
109105
110106
- name: generate schema.json
111107
uses: actions-rs/cargo@v1
112108
with:
113109
command: build
114-
args: --manifest-path ./tooling/cli/Cargo.toml
110+
args: --manifest-path ./core/config-schema/Cargo.toml
115111

116112
- name: check schema
117113
run: ./.scripts/ci/has-diff.sh

‎Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ members = [
88
"core/tauri-utils",
99
"core/tauri-build",
1010
"core/tauri-codegen",
11+
"core/config-schema",
1112

1213
# integration tests
1314
"core/tests/restart",

‎core/config-schema/Cargo.toml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "config-schema"
3+
version = "0.0.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[build-dependencies]
8+
tauri-utils = { version = "1.0.0", features = [ "schema" ], path = "../tauri-utils" }
9+
schemars = { version = "0.8", features = [ "url", "preserve_order" ] }
10+
serde = { version = "1.0", features = [ "derive" ] }
11+
serde_json = "1.0"
12+
serde_with = "1.12"
13+
url = { version = "2.3", features = [ "serde" ] }

‎core/config-schema/build.rs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
2+
// SPDX-License-Identifier: Apache-2.0
3+
// SPDX-License-Identifier: MIT
4+
5+
use std::{
6+
error::Error,
7+
fs::File,
8+
io::{BufWriter, Write},
9+
path::PathBuf,
10+
};
11+
12+
pub fn main() -> Result<(), Box<dyn Error>> {
13+
let schema = schemars::schema_for!(tauri_utils::config::Config);
14+
let schema_str = serde_json::to_string_pretty(&schema).unwrap();
15+
let crate_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR")?);
16+
for file in [
17+
crate_dir.join("schema.json"),
18+
crate_dir.join("../../tooling/cli/schema.json"),
19+
] {
20+
let mut schema_file = BufWriter::new(File::create(&file)?);
21+
write!(schema_file, "{}", schema_str)?;
22+
}
23+
24+
Ok(())
25+
}

0 commit comments

Comments
 (0)