Skip to content

Commit

Permalink
feat: config schema generator (#5193)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
  • Loading branch information
amrbashir and lucasfernog committed Oct 28, 2022
1 parent cc186c7 commit a178f95
Show file tree
Hide file tree
Showing 37 changed files with 3,127 additions and 157 deletions.
5 changes: 4 additions & 1 deletion .changes/config.json
Expand Up @@ -232,7 +232,10 @@
"path": "./tooling/cli/node",
"manager": "javascript",
"dependencies": ["cli.rs"],
"postversion": "node ../../../.scripts/covector/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }",
"postversion": [
"node ../../../.scripts/covector/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }",
"cargo build --manifest-path ../../core/config-schema/Cargo.toml"
],
"prepublish": [],
"publish": [],
"postpublish": []
Expand Down
5 changes: 5 additions & 0 deletions .changes/isolation-pattern-config.md
@@ -0,0 +1,5 @@
---
"tauri-utils": minor
---

`PatternKind::Isolation` is now defined even without the `isolation` feature.
2 changes: 2 additions & 0 deletions .github/workflows/artifacts-updater.yml
Expand Up @@ -128,6 +128,7 @@ jobs:
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
# Updater signature is exposed here to make sure it works in PR's
TAURI_PRIVATE_KEY: dW50cnVzdGVkIGNvbW1lbnQ6IHJzaWduIGVuY3J5cHRlZCBzZWNyZXQga2V5ClJXUlRZMEl5YTBGV3JiTy9lRDZVd3NkL0RoQ1htZmExNDd3RmJaNmRMT1ZGVjczWTBKZ0FBQkFBQUFBQUFBQUFBQUlBQUFBQWdMekUzVkE4K0tWQ1hjeGt1Vkx2QnRUR3pzQjVuV0ZpM2czWXNkRm9hVUxrVnB6TUN3K1NheHJMREhQbUVWVFZRK3NIL1VsMDBHNW5ET1EzQno0UStSb21nRW4vZlpTaXIwZFh5ZmRlL1lSN0dKcHdyOUVPclVvdzFhVkxDVnZrbHM2T1o4Tk1NWEU9Cg==
TAURI_KEY_PASSWORD:
# run on PRs and forks
- name: build sample artifacts (updater)
if: steps.enablecodesigning.outputs.enabled != 'true'
Expand All @@ -137,6 +138,7 @@ jobs:
cargo tauri build --verbose
env:
TAURI_PRIVATE_KEY: dW50cnVzdGVkIGNvbW1lbnQ6IHJzaWduIGVuY3J5cHRlZCBzZWNyZXQga2V5ClJXUlRZMEl5YTBGV3JiTy9lRDZVd3NkL0RoQ1htZmExNDd3RmJaNmRMT1ZGVjczWTBKZ0FBQkFBQUFBQUFBQUFBQUlBQUFBQWdMekUzVkE4K0tWQ1hjeGt1Vkx2QnRUR3pzQjVuV0ZpM2czWXNkRm9hVUxrVnB6TUN3K1NheHJMREhQbUVWVFZRK3NIL1VsMDBHNW5ET1EzQno0UStSb21nRW4vZlpTaXIwZFh5ZmRlL1lSN0dKcHdyOUVPclVvdzFhVkxDVnZrbHM2T1o4Tk1NWEU9Cg==
TAURI_KEY_PASSWORD:
# upload assets
- uses: actions/upload-artifact@v2
if: matrix.platform == 'ubuntu-latest'
Expand Down
36 changes: 16 additions & 20 deletions .github/workflows/check-generated-files.yml
Expand Up @@ -12,6 +12,7 @@ on:
- 'core/tauri/scripts/bundle.global.js'
- 'core/tauri-utils/src/config.rs'
- 'tooling/cli/schema.json'
- 'core/config-schema/schema.json'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -35,6 +36,7 @@ jobs:
schema:
- 'core/tauri-utils/src/config.rs'
- 'tooling/cli/schema.json'
- 'core/config-schema/schema.json'
check-bundle:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -63,18 +65,12 @@ jobs:
override: true

- name: install Linux dependencies
if: matrix.platform == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev
- name: Get current date
run: echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
if: matrix.platform == 'macos-latest' || matrix.platform == 'ubuntu-latest'

- name: Get current date
if: matrix.platform == 'windows-latest'
run: echo "CURRENT_DATE=$(Get-Date -Format "yyyy-MM-dd")" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Cache cargo state
uses: actions/cache@v2
Expand All @@ -85,33 +81,33 @@ jobs:
~/.cargo/registry
~/.cargo/git
~/.cargo/bin
key: ${{ matrix.platform }}-stable-${{ env.cache-name }}-${{ hashFiles('**/Cargo.toml') }}-${{ env.CURRENT_DATE }}
key: ubuntu-latest-stable-${{ env.cache-name }}-${{ hashFiles('**/Cargo.toml') }}-${{ env.CURRENT_DATE }}
restore-keys: |
${{ matrix.platform }}-stable-${{ env.cache-name }}-${{ hashFiles('**/Cargo.toml') }}-
${{ matrix.platform }}-stable-${{ env.cache-name }}-
${{ matrix.platform }}-stable-
${{ matrix.platform }}-
ubuntu-latest-stable-${{ env.cache-name }}-${{ hashFiles('**/Cargo.toml') }}-
ubuntu-latest-stable-${{ env.cache-name }}-
ubuntu-latest-stable-
ubuntu-latest-
- name: Cache CLI cargo target
- name: Cache core cargo target
uses: actions/cache@v2
env:
cache-name: cargo_cli
cache-name: cargo-core
with:
path: tooling/cli/target
path: target
# Add date to the cache to keep it up to date
key: ${{ matrix.platform }}-stable-${{ env.cache-name }}-${{ hashFiles('tooling/cli/Cargo.lock') }}-${{ env.CURRENT_DATE }}
key: ubuntu-latest-stable-${{ env.cache-name }}-${{ hashFiles('core/**/Cargo.toml') }}-${{ env.CURRENT_DATE }}
# Restore from outdated cache for speed
restore-keys: |
${{ matrix.platform }}-stable-${{ env.cache-name }}-${{ hashFiles('tooling/cli/Cargo.lock') }}
${{ matrix.platform }}-stable-${{ env.cache-name }}-
${{ matrix.platform }}-stable-
${{ matrix.platform }}-
ubuntu-latest-stable-${{ env.cache-name }}-${{ hashFiles('core/**/Cargo.toml') }}
ubuntu-latest-stable-${{ env.cache-name }}-
ubuntu-latest-stable-
ubuntu-latest-
- name: generate schema.json
uses: actions-rs/cargo@v1
with:
command: build
args: --manifest-path ./tooling/cli/Cargo.toml
args: --manifest-path ./core/config-schema/Cargo.toml

- name: check schema
run: ./.scripts/ci/has-diff.sh
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -8,6 +8,7 @@ members = [
"core/tauri-utils",
"core/tauri-build",
"core/tauri-codegen",
"core/config-schema",

# integration tests
"core/tests/restart",
Expand Down
13 changes: 13 additions & 0 deletions core/config-schema/Cargo.toml
@@ -0,0 +1,13 @@
[package]
name = "config-schema"
version = "0.0.0"
edition = "2021"
publish = false

[build-dependencies]
tauri-utils = { version = "1.0.0", features = [ "schema" ], path = "../tauri-utils" }
schemars = { version = "0.8", features = [ "url", "preserve_order" ] }
serde = { version = "1.0", features = [ "derive" ] }
serde_json = "1.0"
serde_with = "1.12"
url = { version = "2.3", features = [ "serde" ] }
25 changes: 25 additions & 0 deletions core/config-schema/build.rs
@@ -0,0 +1,25 @@
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

use std::{
error::Error,
fs::File,
io::{BufWriter, Write},
path::PathBuf,
};

pub fn main() -> Result<(), Box<dyn Error>> {
let schema = schemars::schema_for!(tauri_utils::config::Config);
let schema_str = serde_json::to_string_pretty(&schema).unwrap();
let crate_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR")?);
for file in [
crate_dir.join("schema.json"),
crate_dir.join("../../tooling/cli/schema.json"),
] {
let mut schema_file = BufWriter::new(File::create(&file)?);
write!(schema_file, "{}", schema_str)?;
}

Ok(())
}

0 comments on commit a178f95

Please sign in to comment.