|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, next, develop] |
| 6 | + tags: ['v*'] |
| 7 | + pull_request: |
| 8 | + branches: [main, next, develop] |
| 9 | + |
| 10 | +env: |
| 11 | + CARGO_TERM_COLOR: always |
| 12 | + RUST_BACKTRACE: 1 |
| 13 | + |
| 14 | +jobs: |
| 15 | + # ============================================ |
| 16 | + # Frontend Code Quality |
| 17 | + # ============================================ |
| 18 | + frontend-lint: |
| 19 | + name: Frontend Lint & Type Check |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + - uses: pnpm/action-setup@v4 |
| 24 | + with: { version: 9 } |
| 25 | + - uses: actions/setup-node@v4 |
| 26 | + with: { node-version: 22, cache: 'pnpm' } |
| 27 | + - run: pnpm install --frozen-lockfile |
| 28 | + - run: pnpm tsc --noEmit |
| 29 | + - run: pnpm lint |
| 30 | + - run: pnpm lint:complexity |
| 31 | + |
| 32 | + # ============================================ |
| 33 | + # Rust Code Quality |
| 34 | + # ============================================ |
| 35 | + rust-lint: |
| 36 | + name: Rust Lint & Format |
| 37 | + runs-on: ubuntu-latest |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - name: Cache apt packages |
| 42 | + uses: awalsh128/cache-apt-pkgs-action@latest |
| 43 | + with: |
| 44 | + packages: libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev patchelf libgtk-3-dev |
| 45 | + version: 1.0 |
| 46 | + |
| 47 | + - uses: dtolnay/rust-toolchain@stable |
| 48 | + with: |
| 49 | + components: clippy, rustfmt |
| 50 | + - uses: Swatinem/rust-cache@v2 |
| 51 | + with: |
| 52 | + workspaces: src-tauri |
| 53 | + shared-key: rust-lint |
| 54 | + save-if: ${{ github.ref == 'refs/heads/main' }} |
| 55 | + |
| 56 | + - run: cargo fmt --all -- --check |
| 57 | + working-directory: src-tauri |
| 58 | + - run: cargo clippy --all-targets --all-features -- -D warnings |
| 59 | + working-directory: src-tauri |
| 60 | + |
| 61 | + # ============================================ |
| 62 | + # Rust Tests |
| 63 | + # ============================================ |
| 64 | + rust-test: |
| 65 | + name: Rust Tests |
| 66 | + runs-on: ubuntu-latest |
| 67 | + needs: rust-lint # Run after lint to reuse cache |
| 68 | + steps: |
| 69 | + - uses: actions/checkout@v4 |
| 70 | + |
| 71 | + - name: Cache apt packages |
| 72 | + uses: awalsh128/cache-apt-pkgs-action@latest |
| 73 | + with: |
| 74 | + packages: libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev patchelf libgtk-3-dev |
| 75 | + version: 1.0 |
| 76 | + |
| 77 | + - uses: dtolnay/rust-toolchain@stable |
| 78 | + - uses: Swatinem/rust-cache@v2 |
| 79 | + with: |
| 80 | + workspaces: src-tauri |
| 81 | + shared-key: rust-lint |
| 82 | + save-if: false # Only read, lint job saves |
| 83 | + |
| 84 | + - run: cargo test --all-features |
| 85 | + working-directory: src-tauri |
| 86 | + |
| 87 | + # ============================================ |
| 88 | + # Security Audit |
| 89 | + # ============================================ |
| 90 | + security: |
| 91 | + name: Security Audit |
| 92 | + runs-on: ubuntu-latest |
| 93 | + steps: |
| 94 | + - uses: actions/checkout@v4 |
| 95 | + - uses: pnpm/action-setup@v4 |
| 96 | + with: { version: 9 } |
| 97 | + - uses: actions/setup-node@v4 |
| 98 | + with: { node-version: 22, cache: 'pnpm' } |
| 99 | + - run: pnpm install --frozen-lockfile |
| 100 | + - run: pnpm audit --audit-level=high |
| 101 | + continue-on-error: true |
| 102 | + |
| 103 | + # Use cargo-binstall for faster installation |
| 104 | + - name: Install cargo-binstall |
| 105 | + uses: cargo-bins/cargo-binstall@main |
| 106 | + |
| 107 | + - name: Install cargo-audit |
| 108 | + run: cargo binstall cargo-audit --no-confirm |
| 109 | + |
| 110 | + - run: cargo audit |
| 111 | + working-directory: src-tauri |
| 112 | + continue-on-error: true |
| 113 | + |
| 114 | + # ============================================ |
| 115 | + # Build (Cross-platform) |
| 116 | + # ============================================ |
| 117 | + build: |
| 118 | + name: Build (${{ matrix.os }}) |
| 119 | + needs: [frontend-lint, rust-lint] |
| 120 | + strategy: |
| 121 | + fail-fast: false |
| 122 | + matrix: |
| 123 | + include: |
| 124 | + - os: ubuntu-24.04 |
| 125 | + target: x86_64-unknown-linux-gnu |
| 126 | + - os: windows-latest |
| 127 | + target: x86_64-pc-windows-msvc |
| 128 | + - os: macos-latest |
| 129 | + target: aarch64-apple-darwin |
| 130 | + |
| 131 | + runs-on: ${{ matrix.os }} |
| 132 | + steps: |
| 133 | + - uses: actions/checkout@v4 |
| 134 | + |
| 135 | + - name: Cache apt packages |
| 136 | + if: matrix.os == 'ubuntu-24.04' |
| 137 | + uses: awalsh128/cache-apt-pkgs-action@latest |
| 138 | + with: |
| 139 | + packages: libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev patchelf libgtk-3-dev |
| 140 | + version: 1.0 |
| 141 | + |
| 142 | + - uses: pnpm/action-setup@v4 |
| 143 | + with: { version: 9 } |
| 144 | + - uses: actions/setup-node@v4 |
| 145 | + with: { node-version: 22, cache: 'pnpm' } |
| 146 | + - uses: dtolnay/rust-toolchain@stable |
| 147 | + with: { targets: '${{ matrix.target }}' } |
| 148 | + - uses: Swatinem/rust-cache@v2 |
| 149 | + with: |
| 150 | + workspaces: src-tauri |
| 151 | + shared-key: build-${{ matrix.target }} |
| 152 | + |
| 153 | + - run: pnpm install --frozen-lockfile |
| 154 | + - run: pnpm tauri build --target ${{ matrix.target }} |
| 155 | + |
| 156 | + - name: Upload artifacts (Linux) |
| 157 | + if: matrix.os == 'ubuntu-24.04' |
| 158 | + uses: actions/upload-artifact@v4 |
| 159 | + with: |
| 160 | + name: ctfcracktools-linux |
| 161 | + path: src-tauri/target/${{ matrix.target }}/release/ctfcracktools-x |
| 162 | + if-no-files-found: warn |
| 163 | + |
| 164 | + - name: Upload artifacts (Windows) |
| 165 | + if: matrix.os == 'windows-latest' |
| 166 | + uses: actions/upload-artifact@v4 |
| 167 | + with: |
| 168 | + name: ctfcracktools-windows |
| 169 | + path: src-tauri/target/${{ matrix.target }}/release/ctfcracktools-x.exe |
| 170 | + if-no-files-found: warn |
| 171 | + |
| 172 | + - name: Upload artifacts (macOS) |
| 173 | + if: matrix.os == 'macos-latest' |
| 174 | + uses: actions/upload-artifact@v4 |
| 175 | + with: |
| 176 | + name: ctfcracktools-macos |
| 177 | + path: src-tauri/target/${{ matrix.target }}/release/ctfcracktools-x |
| 178 | + if-no-files-found: warn |
| 179 | + |
| 180 | + # ============================================ |
| 181 | + # Summary |
| 182 | + # ============================================ |
| 183 | + ci-success: |
| 184 | + name: CI Success |
| 185 | + needs: [frontend-lint, rust-lint, rust-test, security, build] |
| 186 | + runs-on: ubuntu-latest |
| 187 | + if: always() |
| 188 | + steps: |
| 189 | + - name: Check all jobs |
| 190 | + run: | |
| 191 | + if [[ "${{ needs.frontend-lint.result }}" == "failure" ]]; then |
| 192 | + echo "Frontend lint failed"; exit 1 |
| 193 | + fi |
| 194 | + if [[ "${{ needs.rust-lint.result }}" == "failure" ]]; then |
| 195 | + echo "Rust lint failed"; exit 1 |
| 196 | + fi |
| 197 | + if [[ "${{ needs.rust-test.result }}" == "failure" ]]; then |
| 198 | + echo "Rust tests failed"; exit 1 |
| 199 | + fi |
| 200 | + if [[ "${{ needs.build.result }}" == "failure" ]]; then |
| 201 | + echo "Build failed"; exit 1 |
| 202 | + fi |
| 203 | + echo "All CI checks passed!" |
0 commit comments