ci: 修复 Windows 和 Android 构建 #39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [master] | |
| pull_request: | |
| branches: [master] | |
| workflow_dispatch: | |
| env: | |
| CARGO_TERM_COLOR: always | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| jobs: | |
| windows: | |
| name: Windows | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| components: rustfmt, clippy | |
| - uses: Swatinem/rust-cache@v2 | |
| - name: Format check | |
| run: cargo fmt --all --check | |
| - name: Test (core) | |
| run: | | |
| cargo build --workspace --exclude cicada-client | |
| cargo test --workspace --exclude cicada-client | |
| cargo clippy --workspace --exclude cicada-client -- -D warnings | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Build frontend | |
| working-directory: crates/cicada-client/ui | |
| run: npm ci && npm run build | |
| - name: Install Tauri CLI | |
| run: cargo install tauri-cli --version "1.6.6" --locked | |
| - name: Build Tauri (Windows) | |
| working-directory: crates/cicada-client | |
| env: | |
| GIT_HASH: ${{ github.sha }} | |
| BUILD_DATE: ${{ github.event.repository.updated_at }} | |
| run: cargo tauri build --bundles nsis | |
| - name: Make zip (portable) | |
| shell: pwsh | |
| run: | | |
| $release = "target/release" | |
| $exe = Get-ChildItem $release -Filter *.exe | Select-Object -First 1 | |
| if (-not $exe) { | |
| throw "No portable executable found in $release" | |
| } | |
| New-Item -ItemType Directory -Force -Path portable-windows | Out-Null | |
| Copy-Item $exe.FullName "portable-windows/Cicada.exe" | |
| Compress-Archive -Path "portable-windows/*" -DestinationPath "Cicada_windows_portable.zip" -Force | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: cicada-windows | |
| path: | | |
| target/release/bundle/nsis/*.exe | |
| Cicada_windows_portable.zip | |
| linux: | |
| name: Linux | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| components: rustfmt, clippy | |
| - uses: Swatinem/rust-cache@v2 | |
| - name: Format check | |
| run: cargo fmt --all --check | |
| - name: Test (core) | |
| run: | | |
| cargo build --workspace --exclude cicada-client | |
| cargo test --workspace --exclude cicada-client | |
| cargo clippy --workspace --exclude cicada-client -- -D warnings | |
| - name: Build mock server (release) | |
| run: cargo build --release -p cicada-mock-server | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: cicada-linux | |
| path: target/release/cicada-mock-server | |
| android: | |
| name: Android | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| cache-dependency-path: mobile/package-lock.json | |
| - uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: 21 | |
| - uses: android-actions/setup-android@v3 | |
| - name: Build mobile PWA | |
| working-directory: mobile | |
| run: npm ci && npm run build | |
| - name: Build Android APK | |
| run: | | |
| mkdir mobile-android | |
| cd mobile-android | |
| npm init -y | |
| npm install @capacitor/core @capacitor/cli @capacitor/android | |
| cat > capacitor.config.json <<'EOF' | |
| { | |
| "appId": "com.cicada.app", | |
| "appName": "知了", | |
| "webDir": "../mobile/dist" | |
| } | |
| EOF | |
| npx cap add android | |
| npx cap copy android | |
| cd android | |
| ./gradlew assembleDebug | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: cicada-android | |
| path: mobile-android/android/app/build/outputs/apk/debug/*.apk | |
| macos: | |
| name: macOS | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| with: | |
| components: rustfmt, clippy | |
| - uses: Swatinem/rust-cache@v2 | |
| - name: Format check | |
| run: cargo fmt --all --check | |
| - name: Test (core) | |
| run: | | |
| cargo build --workspace --exclude cicada-client | |
| cargo test --workspace --exclude cicada-client | |
| cargo clippy --workspace --exclude cicada-client -- -D warnings | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Build frontend | |
| working-directory: crates/cicada-client/ui | |
| run: npm ci && npm run build | |
| - name: Install Tauri CLI | |
| run: cargo install tauri-cli --version "1.6.6" --locked | |
| - name: Build Tauri | |
| working-directory: crates/cicada-client | |
| env: | |
| GIT_HASH: ${{ github.sha }} | |
| BUILD_DATE: ${{ github.event.repository.updated_at }} | |
| run: cargo tauri build | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: cicada-macos | |
| path: | | |
| target/release/bundle/dmg/*.dmg | |
| target/release/bundle/macos/*.dmg |