|
| 1 | +name: CI Agents |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +env: |
| 10 | + NX_NON_NATIVE_HASHER: true |
| 11 | + NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} |
| 12 | + |
| 13 | +jobs: |
| 14 | + # Main CI job that orchestrates and executes all tasks with Nx Agents |
| 15 | + main: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + name: CI with Nx Agents |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Set up Node.js |
| 25 | + uses: actions/setup-node@v4 |
| 26 | + with: |
| 27 | + node-version-file: .nvmrc |
| 28 | + cache: npm |
| 29 | + |
| 30 | + - name: Set base and head for Nx affected commands |
| 31 | + uses: nrwl/nx-set-shas@v4 |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + run: npm ci |
| 35 | + |
| 36 | + - name: Start Nx Cloud CI run with agents |
| 37 | + run: npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="build" |
| 38 | + |
| 39 | + # Run format check |
| 40 | + - name: Check formatting of affected files |
| 41 | + run: npx nx format:check |
| 42 | + |
| 43 | + # Run linting on affected projects |
| 44 | + - name: Lint affected projects |
| 45 | + run: npx nx affected:lint --parallel=3 |
| 46 | + |
| 47 | + # Run unit tests on affected projects |
| 48 | + - name: Unit test affected projects |
| 49 | + run: npx nx affected -t unit-test --parallel=3 --coverage.enabled |
| 50 | + |
| 51 | + # Run integration tests on affected projects |
| 52 | + - name: Integration test affected projects |
| 53 | + run: npx nx affected -t int-test --parallel=3 --coverage.enabled |
| 54 | + |
| 55 | + # Run e2e tests on affected projects |
| 56 | + - name: E2E test affected projects |
| 57 | + run: npx nx affected -t e2e-test --parallel=1 |
| 58 | + |
| 59 | + # Build all projects for package publishing |
| 60 | + - name: Build all projects |
| 61 | + run: npx nx run-many --target=build --parallel=3 --configuration=ci |
| 62 | + |
| 63 | + # Test-release packages |
| 64 | + - name: Test-release packages |
| 65 | + run: npx pkg-pr-new publish "packages/**/dist" |
| 66 | + |
| 67 | + # Nx Cloud Agents for distributed task execution |
| 68 | + agents: |
| 69 | + runs-on: ubuntu-latest |
| 70 | + name: Nx Cloud Agent |
| 71 | + timeout-minutes: 60 |
| 72 | + strategy: |
| 73 | + matrix: |
| 74 | + agent: [1, 2, 3] |
| 75 | + steps: |
| 76 | + - name: Checkout repository |
| 77 | + uses: actions/checkout@v4 |
| 78 | + with: |
| 79 | + fetch-depth: 0 |
| 80 | + |
| 81 | + - name: Start Nx Cloud Agent ${{ matrix.agent }} |
| 82 | + run: npx nx-cloud start-agent --with-deps |
| 83 | + |
| 84 | + # Optional: Stop agent after completion |
| 85 | + - name: Stop Nx Cloud Agent ${{ matrix.agent }} |
| 86 | + if: always() |
| 87 | + run: npx nx-cloud stop-agent |
| 88 | + continue-on-error: true |
0 commit comments