feat(scripts): simplify git hooks with conditional checks and color output #19
Workflow file for this run
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: review | |
| on: | |
| pull_request: { branches: ["main"] } | |
| jobs: | |
| detect-changes: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| has-rust-changes: ${{ steps.detect.outputs.has-rust-changes }} | |
| has-test-changes: ${{ steps.detect.outputs.has-test-changes }} | |
| has-frontend-changes: ${{ steps.detect.outputs.has-frontend-changes }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 2 # Fetch current commit + base branch commit for comparison | |
| - name: Detect file changes | |
| id: detect | |
| run: | | |
| git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1 | |
| chmod +x scripts/detect-changes.sh | |
| scripts/detect-changes.sh \ | |
| "origin/${{ github.event.pull_request.base.ref }}" \ | |
| "HEAD" | |
| pnpm: | |
| runs-on: ubuntu-latest | |
| needs: detect-changes | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: actions/setup-node@v4 | |
| - uses: pnpm/action-setup@v4 | |
| with: { version: 10 } | |
| - run: pnpm install | |
| - run: pnpm review | |
| # Conditional test: only if test files changed. | |
| - if: needs.detect-changes.outputs.has-test-changes == 'true' | |
| run: pnpm test | |
| # Conditional build: only if frontend files changed. | |
| - if: needs.detect-changes.outputs.has-frontend-changes == 'true' | |
| run: pnpm build | |
| # Conditional: only if Rust files changed. | |
| cargo: | |
| runs-on: ubuntu-latest | |
| needs: detect-changes | |
| if: needs.detect-changes.outputs.has-rust-changes == 'true' | |
| steps: | |
| - uses: actions/checkout@v5 | |
| # Update rust toolchain before cache, or it won't work. | |
| - run: rustup toolchain install stable --profile minimal | |
| - uses: Swatinem/rust-cache@v2 | |
| # Tauri prerequisites on Linux (Debian/Ubuntu). | |
| # see https://tauri.app/start/prerequisites/#linux | |
| - run: sudo apt-get update | |
| - run: sudo apt-get install | |
| libwebkit2gtk-4.1-dev | |
| build-essential | |
| curl | |
| wget | |
| file | |
| libxdo-dev | |
| libssl-dev | |
| libayatana-appindicator3-dev | |
| librsvg2-dev | |
| - run: cargo build | |
| - run: cargo check | |
| - run: cargo test |