Update README.md #2
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: Backend Test and Coverage | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| paths: | |
| - "backend/**" | |
| - "shared/**" | |
| workflow_dispatch: | |
| jobs: | |
| test: | |
| name: Node ${{ matrix.node-version }} Test | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: backend | |
| needs: set-matrix | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJSON(needs.set-matrix.outputs.matrix) }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: Start Redis | |
| uses: supercharge/redis-github-action@1.7.0 | |
| with: | |
| redis-version: ${{ matrix.redis-version }} | |
| - name: Start MongoDB | |
| uses: supercharge/mongodb-github-action@1.12.0 | |
| with: | |
| mongodb-version: ${{ matrix.mongodb-version }} | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: 10 | |
| run_install: false | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build shared | |
| run: pnpm --filter shared build | |
| - name: Run tests | |
| run: pnpm test | |
| env: | |
| CI: true | |
| - name: Run coverage | |
| if: matrix.node-version == '22' | |
| run: pnpm coverage | |
| env: | |
| CI: true | |
| - name: Upload coverage artifacts | |
| if: matrix.node-version == '22' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: backend/coverage.lcov | |
| set-matrix: | |
| name: Decide matrix | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set.outputs.matrix }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Detect backend changes | |
| id: detect | |
| run: | | |
| if git diff --quiet HEAD^ HEAD -- backend shared; then | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Set matrix | |
| id: set | |
| run: | | |
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| echo 'matrix={"node-version":[22,24],"redis-version":[7],"mongodb-version":["8.0"]}' >> $GITHUB_OUTPUT | |
| elif [[ "${{ steps.detect.outputs.changed }}" == "true" ]]; then | |
| echo 'matrix={"node-version":[22,24],"redis-version":[7],"mongodb-version":["8.0"]}' >> $GITHUB_OUTPUT | |
| else | |
| echo 'matrix={"node-version":[22],"redis-version":[7],"mongodb-version":["8.0"]}' >> $GITHUB_OUTPUT | |
| fi | |
| coverage: | |
| name: Upload Coverage | |
| runs-on: ubuntu-latest | |
| needs: test | |
| if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' | |
| defaults: | |
| run: | |
| working-directory: backend | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download coverage artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: backend/coverage.lcov | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| fail_ci_if_error: true | |
| verbose: true | |
| env: | |
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |