From 8ff1b0d10850f27a61cad9d0c17b6f1522c41b6d Mon Sep 17 00:00:00 2001 From: Geometrically <18202329+Geometrically@users.noreply.github.com> Date: Tue, 23 May 2023 11:14:22 -0700 Subject: [PATCH] Code signing + auto updater (#122) * Code signing + auto updater * remove dist * update actions * fixes * fix more * commit * fix cache dir * quotes * fix hopefully? * why yaml * Fix cache dep path * Fix updating artifacts * fix ubuntu ver * enable autoupdater * fix pubkey * fix invalid config * pass in signing vars * update pubkey * Improve compile times --- .github/workflows/cli-build.yml | 26 ++++---- .github/workflows/gui-build.yml | 21 +++--- .github/workflows/tauri-build.yml | 92 ++++++++++++++++++--------- Cargo.lock | 27 ++++++++ Cargo.toml | 19 +++++- theseus/src/api/profile.rs | 1 - theseus_gui/.gitignore | 1 + theseus_gui/index.html | 2 +- theseus_gui/src-tauri/Cargo.toml | 2 +- theseus_gui/src-tauri/tauri.conf.json | 13 ++-- theseus_macros/src/lib.rs | 19 +++--- 11 files changed, 148 insertions(+), 75 deletions(-) diff --git a/.github/workflows/cli-build.yml b/.github/workflows/cli-build.yml index b20e0c436..49367bd7f 100644 --- a/.github/workflows/cli-build.yml +++ b/.github/workflows/cli-build.yml @@ -13,28 +13,30 @@ jobs: run: working-directory: ./theseus_cli steps: - - uses: actions/checkout@v2 - - name: install dependencies (ubuntu only) + - name: Checkout + uses: actions/checkout@v3 + + - name: install dependencies run: | sudo apt-get update sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf - - name: Get build cache - id: cache-build - uses: actions/cache@v2 + + - name: Rust setup + uses: dtolnay/rust-toolchain@stable with: - path: ../target/** - key: ${{ runner.os }}-theseus - - name: Install toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true components: rustfmt, clippy + + - name: Rust cache + uses: swatinem/rust-cache@v2 + with: + workspaces: './src-tauri -> target' + - uses: actions-rs/cargo@v1 name: Build program with: command: build args: --bin theseus_cli + - name: Run Lint uses: actions-rs/clippy-check@v1 with: diff --git a/.github/workflows/gui-build.yml b/.github/workflows/gui-build.yml index 54cd43258..7efe5719c 100644 --- a/.github/workflows/gui-build.yml +++ b/.github/workflows/gui-build.yml @@ -13,22 +13,19 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - - name: Use Node.js + + - name: Sync node version and setup cache uses: actions/setup-node@v3 with: - node-version: 18.x - - name: Get yarn cache - id: yarn-cache - run: echo "::set-output name=dir::$(yarn cache dir)" - - uses: actions/cache@v3 - with: - path: ${{ steps.yarn-cache.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- + node-version: 16 + cache: 'yarn' + cache-dependency-path: "theseus_gui" + - name: Install dependencies run: yarn install --immutable --immutable-cache --check-cache + - name: Run Lint run: yarn run lint + - name: Build - run: yarn run build + run: yarn run build \ No newline at end of file diff --git a/.github/workflows/tauri-build.yml b/.github/workflows/tauri-build.yml index 161c01d1a..f0ca47f61 100644 --- a/.github/workflows/tauri-build.yml +++ b/.github/workflows/tauri-build.yml @@ -14,46 +14,80 @@ jobs: defaults: run: working-directory: ./theseus_gui + steps: - uses: actions/checkout@v3 - - name: setup node + + - name: Rust setup (mac) + if: startsWith(matrix.platform, 'macos') + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt, clippy + targets: aarch64-apple-darwin + + - name: Rust setup + if: "!startsWith(matrix.platform, 'macos')" + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt, clippy + + - name: Rust cache + uses: swatinem/rust-cache@v2 + with: + workspaces: './src-tauri -> target' + + - name: Sync node version and setup cache uses: actions/setup-node@v3 with: node-version: 16 - - name: Install toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - components: rustfmt, clippy + cache: 'yarn' + cache-dependency-path: "theseus_gui" + - name: install dependencies (ubuntu only) - if: matrix.platform == 'ubuntu-20.04' + if: startsWith(matrix.platform, 'ubuntu') run: | sudo apt-get update sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf - - name: Get build cache - id: cache-build - uses: actions/cache@v2 - with: - path: ../target/** - key: ${{ runner.os }}-theseus - - name: Get yarn cache - id: yarn-cache - run: echo "::set-output name=dir::$(yarn cache dir)" - - uses: actions/cache@v3 - with: - path: ${{ steps.yarn-cache.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- + - name: install frontend dependencies run: yarn install --immutable --immutable-cache --check-cache - - uses: tauri-apps/tauri-action@v0 + + - name: build app (macos) + uses: tauri-apps/tauri-action@v0 + id: build_os_mac + if: startsWith(matrix.platform, 'macos') env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Run Lint - if: matrix.platform == 'ubuntu-20.04' - uses: actions-rs/clippy-check@v1 + ENABLE_CODE_SIGNING: ${{ secrets.APPLE_CERTIFICATE }} + APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }} + APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }} + APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }} + APPLE_ID: ${{ secrets.APPLE_ID }} + APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }} + TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }} + TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }} with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --bin theseus_cli \ No newline at end of file + args: --target universal-apple-darwin + + - name: build app + uses: tauri-apps/tauri-action@v0 + id: build_os + if: "!startsWith(matrix.platform, 'macos')" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }} + TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }} + + - name: upload ${{ matrix.platform }} + uses: actions/upload-artifact@v3 + if: startsWith(matrix.platform, 'macos') + with: + name: ${{ matrix.platform }} + path: "${{ join(fromJSON(steps.build_os_mac.outputs.artifactPaths), '\n') }}" + + - name: upload ${{ matrix.platform }} + uses: actions/upload-artifact@v3 + if: "!startsWith(matrix.platform, 'macos')" + with: + name: ${{ matrix.platform }} + path: "${{ join(fromJSON(steps.build_os.outputs.artifactPaths), '\n') }}" diff --git a/Cargo.lock b/Cargo.lock index 1bd9f004a..d7f8bec82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -179,6 +179,22 @@ dependencies = [ "system-deps 6.0.4", ] +[[package]] +name = "attohttpc" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fcf00bc6d5abb29b5f97e3c61a90b6d3caa12f3faf897d4a3e3607c050a35a7" +dependencies = [ + "flate2", + "http", + "log", + "native-tls", + "serde", + "serde_json", + "serde_urlencoded", + "url", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -2048,6 +2064,12 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minisign-verify" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "933dca44d65cdd53b355d0b73d380a2ff5da71f87f036053188bf1eab6a19881" + [[package]] name = "miniz_oxide" version = "0.6.2" @@ -3540,6 +3562,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe7e0f1d535e7cbbbab43c82be4fc992b84f9156c16c160955617e0260ebc449" dependencies = [ "anyhow", + "attohttpc", + "base64 0.13.1", "cocoa", "dirs-next", "embed_plist", @@ -3552,6 +3576,7 @@ dependencies = [ "heck 0.4.1", "http", "ignore", + "minisign-verify", "objc", "once_cell", "open", @@ -3573,12 +3598,14 @@ dependencies = [ "tauri-utils", "tempfile", "thiserror", + "time 0.3.20", "tokio", "url", "uuid 1.3.0", "webkit2gtk", "webview2-com", "windows 0.39.0", + "zip", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3d0c76f31..7fea9d1ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,21 @@ members = [ "theseus_macros" ] +[profile.dev] +opt-level = 0 +debug = true +debug-assertions = true +overflow-checks = true +lto = false +panic = 'unwind' +incremental = true +codegen-units = 256 +rpath = false + # Optimize for speed and reduce size on release builds [profile.release] -codegen-units = 1 -lto = true -strip = true \ No newline at end of file +panic = "abort" # Strip expensive panic clean-up logic +codegen-units = 1 # Compile crates one after another so the compiler can optimize better +lto = true # Enables link to optimizations +opt-level = "s" # Optimize for binary size +strip = true # Remove debug symbols diff --git a/theseus/src/api/profile.rs b/theseus/src/api/profile.rs index 28b6da903..b9c394336 100644 --- a/theseus/src/api/profile.rs +++ b/theseus/src/api/profile.rs @@ -6,7 +6,6 @@ use crate::state::ProjectMetadata; use crate::{ auth::{self, refresh}, event::{emit::emit_profile, ProfilePayloadType}, - profile, state::MinecraftChild, }; pub use crate::{ diff --git a/theseus_gui/.gitignore b/theseus_gui/.gitignore index bedd035f5..a343f1d61 100644 --- a/theseus_gui/.gitignore +++ b/theseus_gui/.gitignore @@ -22,3 +22,4 @@ node_modules *.njsproj *.sln *.sw? +dist diff --git a/theseus_gui/index.html b/theseus_gui/index.html index 1e1698142..c27c868e5 100644 --- a/theseus_gui/index.html +++ b/theseus_gui/index.html @@ -4,7 +4,7 @@ - Modrinth Launcher + Modrinth App diff --git a/theseus_gui/src-tauri/Cargo.toml b/theseus_gui/src-tauri/Cargo.toml index 7371495d0..1d572e2c6 100644 --- a/theseus_gui/src-tauri/Cargo.toml +++ b/theseus_gui/src-tauri/Cargo.toml @@ -19,7 +19,7 @@ theseus = { path = "../../theseus", features = ["tauri"] } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.2", features = ["dialog", "dialog-open", "protocol-asset", "shell-open", "window-close", "window-create"] } +tauri = { version = "1.2", features = ["dialog", "dialog-open", "protocol-asset", "shell-open", "updater", "window-close", "window-create"] } tokio = { version = "1", features = ["full"] } thiserror = "1.0" tokio-stream = { version = "0.1", features = ["fs"] } diff --git a/theseus_gui/src-tauri/tauri.conf.json b/theseus_gui/src-tauri/tauri.conf.json index d0b179d8b..df3e76c7a 100644 --- a/theseus_gui/src-tauri/tauri.conf.json +++ b/theseus_gui/src-tauri/tauri.conf.json @@ -7,8 +7,8 @@ "withGlobalTauri": false }, "package": { - "productName": "theseus", - "version": "0.0.0" + "productName": "Modrinth App", + "version": "0.0.1" }, "tauri": { "allowlist": { @@ -33,7 +33,7 @@ }, "bundle": { "active": true, - "category": "DeveloperTool", + "category": "Entertainment", "copyright": "", "deb": { "depends": [] @@ -68,14 +68,17 @@ "csp": "default-src 'self'; connect-src https://modrinth.com https://*.modrinth.com; font-src https://cdn-raw.modrinth.com/fonts/inter/; img-src tauri: https: data: blob: 'unsafe-inline' asset: https://asset.localhost" }, "updater": { - "active": false + "active": true, + "endpoints": ["https://launcher-files.modrinth.com/updates.json"], + "dialog": true, + "pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDIwMzM5QkE0M0FCOERBMzkKUldRNTJyZzZwSnN6SUdPRGdZREtUUGxMblZqeG9OVHYxRUlRTzJBc2U3MUNJaDMvZDQ1UytZZmYK" }, "windows": [ { "fullscreen": false, "height": 650, "resizable": true, - "title": "Modrinth Launcher", + "title": "Modrinth App", "width": 1140, "minHeight": 630, "minWidth": 1100 diff --git a/theseus_macros/src/lib.rs b/theseus_macros/src/lib.rs index f2aa05fca..aae98f29c 100644 --- a/theseus_macros/src/lib.rs +++ b/theseus_macros/src/lib.rs @@ -13,22 +13,19 @@ pub fn debug_pin(_attr: TokenStream, item: TokenStream) -> TokenStream { let sig = &input.sig; let body = &input.block; - // Generate tokens for the common part - let common_tokens = quote! { - #(#attrs)* - #vis #sig - }; - + #[cfg(debug_assertions)] let result = quote! { - #[cfg(debug_assertions)] - #common_tokens { + #(#attrs)* + #vis #sig { Box::pin(async move { #body }).await } - - #[cfg(not(debug_assertions))] - #common_tokens { + }; + #[cfg(not(debug_assertions))] + let result = quote! { + #(#attrs)* + #vis #sig { #body } };