name: Lint, Test and Build

on:
  push:
  pull_request:

permissions:
  actions: read
  contents: read

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  NX_BRANCH: ${{ github.event.number || github.ref_name }}
  NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}

jobs:
  main:
    name: Nx Cloud - Main Job
    uses: nrwl/ci/.github/workflows/nx-cloud-main.yml@v0.14.0
    with:
      main-branch-name: main
      number-of-agents: 3
      init-commands: |
        pnpm exec nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3
      parallel-commands: |
        pnpm exec nx-cloud record -- pnpm exec nx format:check
      parallel-commands-on-agents: |
        pnpm exec nx affected --target=lint --parallel=3
        pnpm exec nx affected --target=test --parallel=3 --ci --code-coverage
        pnpm exec nx affected --target=build --parallel=3

  agents:
    name: Nx Cloud - Agents
    uses: nrwl/ci/.github/workflows/nx-cloud-agents.yml@v0.14.0
    with:
      number-of-agents: 3
