Run github actions only for affected apps/pacakges #56
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: test & build" | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| push: | |
| branches: | |
| - master | |
| - dev | |
| jobs: | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| # "node_js: - stable" logic (Node 24 is current LTS/stable) | |
| node-version: [24.x] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: "yarn" # Automatic caching for Yarn | |
| - name: Install dependencies | |
| # --frozen-lockfile ensures yarn.lock is respected exactly | |
| run: yarn install --frozen-lockfile | |
| - name: Derive Nx SHAs | |
| uses: nrwl/nx-set-shas@v4 | |
| - name: Detect if library is affected | |
| id: affected | |
| run: | | |
| AFFECTED=$(npx nx print-affected --select=projects) | |
| if echo "$AFFECTED" | tr ',' ' ' | tr ' ' '\n' | grep -xq "sequelize-guard"; then | |
| echo "library=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "library=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Run lint | |
| # This runs lint with eslint | |
| run: npx nx affected -t lint --parallel=3 | |
| - name: Run tests and generate coverage | |
| if: steps.affected.outputs.library == 'true' | |
| # This runs vitest with coverage enabled | |
| run: npx nx affected -t test:coverage --parallel=3 | |
| - name: Upload coverage to Coveralls | |
| if: steps.affected.outputs.library == 'true' | |
| uses: coverallsapp/github-action@v2 | |
| with: | |
| base-path: packages/sequelize-guard | |
| - name: Build the library | |
| run: npx nx affected -t build --parallel=3 |