diff --git a/docs/shared/core-features/distribute-task-execution.md b/docs/shared/core-features/distribute-task-execution.md index b47f988053..75a17ee7cf 100644 --- a/docs/shared/core-features/distribute-task-execution.md +++ b/docs/shared/core-features/distribute-task-execution.md @@ -46,7 +46,7 @@ If you have a new workspace, you can generate the CI configuration as follows: nx generate @nx/workspace:ci-workflow --ci=github ``` -The `--ci` flag can be `github`, `circleci` or `azure`. +The `--ci` flag can be `github`, `circleci`, `azure`, `gitlab`, or `bitbucket`. For existing workspaces you would probably want to adjust your configuration by hand. See below for examples. diff --git a/packages/workspace/src/generators/ci-workflow/__snapshots__/ci-workflow.spec.ts.snap b/packages/workspace/src/generators/ci-workflow/__snapshots__/ci-workflow.spec.ts.snap index 4a592754aa..f5c1557b7b 100644 --- a/packages/workspace/src/generators/ci-workflow/__snapshots__/ci-workflow.spec.ts.snap +++ b/packages/workspace/src/generators/ci-workflow/__snapshots__/ci-workflow.spec.ts.snap @@ -10,7 +10,6 @@ pr: variables: CI: 'true' - NX_CLOUD_DISTRIBUTED_EXECUTION: 'true' \${{ if eq(variables['Build.Reason'], 'PullRequest') }}: NX_BRANCH: $(System.PullRequest.PullRequestNumber) TARGET_BRANCH: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')] @@ -21,63 +20,24 @@ variables: HEAD_SHA: $(git rev-parse HEAD) jobs: - - job: agents - strategy: - parallel: 3 - displayName: Nx Cloud Agent - pool: - vmImage: 'ubuntu-latest' - steps: - - script: npm install --prefix=$HOME/.local -g pnpm@8.2.0 - displayName: Install PNPM - - script: pnpm install --frozen-lockfile - displayName: NPM Install Dependencies - - script: npx nx-cloud start-agent - displayName: Start Nx-Cloud agent - - job: main - displayName: Nx Cloud Main pool: vmImage: 'ubuntu-latest' steps: - - script: npm install --prefix=$HOME/.local -g pnpm@8.2.0 - displayName: Install PNPM - - script: pnpm install --frozen-lockfile - displayName: NPM Install Dependencies - - script: pnpm exec nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3 - displayName: Start CI run - - script: pnpm exec nx-cloud record -- pnpm exec nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA) - displayName: Check format - - script: pnpm exec nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=lint --parallel=3 - displayName: Run lint - - script: pnpm exec nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=test --parallel=3 --ci --code-coverage - displayName: Run test - - script: pnpm exec nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=build --parallel=3 - displayName: Run build - - script: pnpm exec nx-cloud stop-all-agents - condition: always() - displayName: Stop all Nx-Cloud agents + - script: npm ci + # uncomment to enable task distribution + # - script: npx nx-cloud start-ci-run --distributes-on="5 linux-medium" + - script: npx nx-cloud record -- nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA) + - script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t=lint,test,build --parallel=3 " `; exports[`CI Workflow generator with npm should generate bitbucket pipelines config 1`] = ` -"image: node:16.18 +"image: node:20 clone: depth: full -definitions: - steps: - - step: &agent - name: Agent - script: - - export NX_BRANCH=$BITBUCKET_PR_ID - - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - - pnpm install --frozen-lockfile - - pnpm exec nx-cloud start-agent - pipelines: pull-requests: '**': @@ -87,16 +47,11 @@ pipelines: script: - export NX_BRANCH=$BITBUCKET_PR_ID - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - - pnpm install --frozen-lockfile - - pnpm exec nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3 - - pnpm exec nx-cloud record -- pnpm exec nx format:check - - pnpm exec nx affected --target=lint & pnpm exec nx affected --target=test & pnpm exec nx affected --target=build - - pnpm exec nx-cloud stop-all-agents - - step: *agent - - step: *agent - - step: *agent + - npm ci + # uncomment to enable task distribution + # - npx nx-cloud start-ci-run --distributes-on="5 linux-medium" + - npx nx-cloud record -- nx format:check + - npx nx affected -t=lint,test,build --parallel=3 " `; @@ -104,76 +59,28 @@ exports[`CI Workflow generator with npm should generate circleci CI config 1`] = "version: 2.1 orbs: - nx: nrwl/nx@1.6.1 + nx: nrwl/nx@1.6.2 jobs: - agent: - docker: - - image: cimg/node:lts-browsers - parameters: - ordinal: - type: integer - steps: - - checkout - - - run: - name: Install PNPM - command: npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - run: - name: Install dependencies - command: pnpm install --frozen-lockfile - - run: - name: Start the agent << parameters.ordinal >> - command: pnpm exec nx-cloud start-agent - no_output_timeout: 60m main: docker: - image: cimg/node:lts-browsers - environment: - NX_CLOUD_DISTRIBUTED_EXECUTION: 'true' steps: - checkout - - - run: - name: Install PNPM - command: npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - run: - name: Install dependencies - command: pnpm install --frozen-lockfile + - run: npm ci - nx/set-shas: main-branch-name: 'main' - - run: - name: Initialize the Nx Cloud distributed CI run - command: pnpm exec nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3 - - run: - name: Check format - command: pnpm exec nx-cloud record -- pnpm exec nx format:check --base=$NX_BASE --head=$NX_HEAD - - run: - name: Run lint - command: pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=lint --parallel=3 - - run: - name: Run test - command: pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=test --parallel=3 --ci --code-coverage - - run: - name: Run build - command: pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=build --parallel=3 - - run: - name: Stop all agents - command: pnpm exec nx-cloud stop-all-agents - when: always + # uncomment to enable task distribution + # - run: npx nx-cloud start-ci-run --distributes-on="5 linux-medium" + - run: npx nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD + - run: npx nx affected --base=$NX_BASE --head=$NX_HEAD -t=lint,test,build --parallel=3 workflows: version: 2 ci: jobs: - - agent: - name: Nx Cloud Agent << matrix.ordinal >> - matrix: - parameters: - ordinal: [1, 2, 3] - - main: - name: Nx Cloud Main + - main " `; @@ -186,32 +93,30 @@ on: - main pull_request: -# Needed for nx-set-shas within nx-cloud-main.yml, when run on the main branch permissions: actions: read contents: read jobs: main: - name: Nx Cloud - Main Job - uses: nrwl/ci/.github/workflows/nx-cloud-main.yml@v0.13.1 - 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 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + # Cache node_modules + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: 'npm' + - run: npm ci + - uses: nrwl/nx-set-shas@v4 - agents: - name: Nx Cloud - Agents - uses: nrwl/ci/.github/workflows/nx-cloud-agents.yml@v0.13.1 - with: - number-of-agents: 3 + # uncomment to enable task distribution + # - run: npx nx-cloud start-ci-run --distributes-on="5 linux-medium" + + - run: npx nx-cloud record -- nx format:check + - run: npx nx affected -t=lint,test,build --parallel=3 " `; @@ -224,81 +129,52 @@ on: - main pull_request: -# Needed for nx-set-shas within nx-cloud-main.yml, when run on the main branch permissions: actions: read contents: read jobs: main: - name: Nx Cloud - Main Job - uses: nrwl/ci/.github/workflows/nx-cloud-main.yml@v0.13.1 - 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 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + # Cache node_modules + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: 'npm' + - run: npm ci + - uses: nrwl/nx-set-shas@v4 - agents: - name: Nx Cloud - Agents - uses: nrwl/ci/.github/workflows/nx-cloud-agents.yml@v0.13.1 - with: - number-of-agents: 3 + # uncomment to enable task distribution + # - run: npx nx-cloud start-ci-run --distributes-on="5 linux-medium" + + - run: npx nx-cloud record -- nx format:check + - run: npx nx affected -t=lint,test,build --parallel=3 " `; exports[`CI Workflow generator with npm should generate gitlab config 1`] = ` -"image: node:18 +"image: node:20 variables: CI: 'true' -# Creating template for DTE agents -.dte-agent: - interruptible: true - script: - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - - pnpm install --frozen-lockfile - - pnpm exec nx-cloud start-agent - -# Creating template for a job running DTE (orchestrator) -.base-pipeline: +# Main job +CI: interruptible: true only: - main - merge_requests - before_script: - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - - pnpm install --frozen-lockfile + script: + - npm ci - NX_HEAD=$CI_COMMIT_SHA - NX_BASE=\${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA} - -# Main job running DTE -CI: - stage: affected - extends: .base-pipeline - script: - - pnpm exec nx-cloud start-ci-run --stop-agents-after="build" - - pnpm exec nx-cloud record -- pnpm exec nx format:check --base=$NX_BASE --head=$NX_HEAD - - pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=lint --parallel=3 & pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=test --parallel=3 --ci --code-coverage & pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=e2e --parallel=3 --ci --code-coverage & pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=build --parallel=3 - -# Create as many agents as you want -nx-dte-agent1: - extends: .dte-agent - stage: affected -nx-dte-agent2: - extends: .dte-agent - stage: affected -nx-dte-agent3: - extends: .dte-agent - stage: affected + # uncomment to enable task distribution + # - npx nx-cloud start-ci-run --distributes-on="5 linux-medium" + - npx nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD + - npx nx affected --base=$NX_BASE --head=$NX_HEAD -t=lint,test,build --parallel=3 " `; @@ -314,7 +190,6 @@ pr: variables: CI: 'true' - NX_CLOUD_DISTRIBUTED_EXECUTION: 'true' \${{ if eq(variables['Build.Reason'], 'PullRequest') }}: NX_BRANCH: $(System.PullRequest.PullRequestNumber) TARGET_BRANCH: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')] @@ -325,63 +200,26 @@ variables: HEAD_SHA: $(git rev-parse HEAD) jobs: - - job: agents - strategy: - parallel: 3 - displayName: Nx Cloud Agent - pool: - vmImage: 'ubuntu-latest' - steps: - - script: npm install --prefix=$HOME/.local -g pnpm@8.2.0 - displayName: Install PNPM - - script: pnpm install --frozen-lockfile - displayName: NPM Install Dependencies - - script: npx nx-cloud start-agent - displayName: Start Nx-Cloud agent - - job: main - displayName: Nx Cloud Main pool: vmImage: 'ubuntu-latest' steps: - - script: npm install --prefix=$HOME/.local -g pnpm@8.2.0 + - script: npm install --prefix=$HOME/.local -g pnpm@8 displayName: Install PNPM - script: pnpm install --frozen-lockfile - displayName: NPM Install Dependencies - - script: pnpm exec nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3 - displayName: Start CI run - - script: pnpm exec nx-cloud record -- pnpm exec nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA) - displayName: Check format - - script: pnpm exec nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=lint --parallel=3 - displayName: Run lint - - script: pnpm exec nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=test --parallel=3 --ci --code-coverage - displayName: Run test - - script: pnpm exec nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=build --parallel=3 - displayName: Run build - - script: pnpm exec nx-cloud stop-all-agents - condition: always() - displayName: Stop all Nx-Cloud agents + # uncomment to enable task distribution + # - script: pnpm exec nx-cloud start-ci-run --distributes-on="5 linux-medium" + - script: pnpm exec nx-cloud record -- nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA) + - script: pnpm exec nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t=lint,test,build --parallel=3 " `; exports[`CI Workflow generator with pnpm should generate bitbucket pipelines config 1`] = ` -"image: node:16.18 +"image: node:20 clone: depth: full -definitions: - steps: - - step: &agent - name: Agent - script: - - export NX_BRANCH=$BITBUCKET_PR_ID - - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - - pnpm install --frozen-lockfile - - pnpm exec nx-cloud start-agent - pipelines: pull-requests: '**': @@ -391,16 +229,13 @@ pipelines: script: - export NX_BRANCH=$BITBUCKET_PR_ID - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 + - npm install --prefix=$HOME/.local -g pnpm@8 - pnpm install --frozen-lockfile - - pnpm exec nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3 - - pnpm exec nx-cloud record -- pnpm exec nx format:check - - pnpm exec nx affected --target=lint & pnpm exec nx affected --target=test & pnpm exec nx affected --target=build - - pnpm exec nx-cloud stop-all-agents - - step: *agent - - step: *agent - - step: *agent + # uncomment to enable task distribution + # - pnpm exec nx-cloud start-ci-run --distributes-on="5 linux-medium" + - pnpm exec nx-cloud record -- nx format:check + - pnpm exec nx affected -t=lint,test,build --parallel=3 " `; @@ -408,76 +243,32 @@ exports[`CI Workflow generator with pnpm should generate circleci CI config 1`] "version: 2.1 orbs: - nx: nrwl/nx@1.6.1 + nx: nrwl/nx@1.6.2 jobs: - agent: - docker: - - image: cimg/node:lts-browsers - parameters: - ordinal: - type: integer - steps: - - checkout - - - run: - name: Install PNPM - command: npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - run: - name: Install dependencies - command: pnpm install --frozen-lockfile - - run: - name: Start the agent << parameters.ordinal >> - command: pnpm exec nx-cloud start-agent - no_output_timeout: 60m main: docker: - image: cimg/node:lts-browsers - environment: - NX_CLOUD_DISTRIBUTED_EXECUTION: 'true' steps: - checkout - run: name: Install PNPM - command: npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - run: - name: Install dependencies - command: pnpm install --frozen-lockfile + command: npm install --prefix=$HOME/.local -g pnpm@8 + - run: pnpm install --frozen-lockfile - nx/set-shas: main-branch-name: 'main' - - run: - name: Initialize the Nx Cloud distributed CI run - command: pnpm exec nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3 - - run: - name: Check format - command: pnpm exec nx-cloud record -- pnpm exec nx format:check --base=$NX_BASE --head=$NX_HEAD - - run: - name: Run lint - command: pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=lint --parallel=3 - - run: - name: Run test - command: pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=test --parallel=3 --ci --code-coverage - - run: - name: Run build - command: pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=build --parallel=3 - - run: - name: Stop all agents - command: pnpm exec nx-cloud stop-all-agents - when: always + # uncomment to enable task distribution + # - run: pnpm exec nx-cloud start-ci-run --distributes-on="5 linux-medium" + - run: pnpm exec nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD + - run: pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD -t=lint,test,build --parallel=3 workflows: version: 2 ci: jobs: - - agent: - name: Nx Cloud Agent << matrix.ordinal >> - matrix: - parameters: - ordinal: [1, 2, 3] - - main: - name: Nx Cloud Main + - main " `; @@ -490,32 +281,34 @@ on: - main pull_request: -# Needed for nx-set-shas within nx-cloud-main.yml, when run on the main branch permissions: actions: read contents: read jobs: main: - name: Nx Cloud - Main Job - uses: nrwl/ci/.github/workflows/nx-cloud-main.yml@v0.13.1 - 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 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 - agents: - name: Nx Cloud - Agents - uses: nrwl/ci/.github/workflows/nx-cloud-agents.yml@v0.13.1 - with: - number-of-agents: 3 + - uses: pnpm/action-setup@v2 + with: + version: 8 + # Cache node_modules + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: 'pnpm' + - run: pnpm install --frozen-lockfile + - uses: nrwl/nx-set-shas@v4 + + # uncomment to enable task distribution + # - run: pnpm exec nx-cloud start-ci-run --distributes-on="5 linux-medium" + + - run: pnpm exec nx-cloud record -- nx format:check + - run: pnpm exec nx affected -t=lint,test,build --parallel=3 " `; @@ -528,81 +321,58 @@ on: - main pull_request: -# Needed for nx-set-shas within nx-cloud-main.yml, when run on the main branch permissions: actions: read contents: read jobs: main: - name: Nx Cloud - Main Job - uses: nrwl/ci/.github/workflows/nx-cloud-main.yml@v0.13.1 - 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 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 - agents: - name: Nx Cloud - Agents - uses: nrwl/ci/.github/workflows/nx-cloud-agents.yml@v0.13.1 - with: - number-of-agents: 3 + - uses: pnpm/action-setup@v2 + with: + version: 8 + # Cache node_modules + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: 'pnpm' + - run: pnpm install --frozen-lockfile + - uses: nrwl/nx-set-shas@v4 + + # uncomment to enable task distribution + # - run: pnpm exec nx-cloud start-ci-run --distributes-on="5 linux-medium" + + - run: pnpm exec nx-cloud record -- nx format:check + - run: pnpm exec nx affected -t=lint,test,build --parallel=3 " `; exports[`CI Workflow generator with pnpm should generate gitlab config 1`] = ` -"image: node:18 +"image: node:20 variables: CI: 'true' -# Creating template for DTE agents -.dte-agent: - interruptible: true - script: - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - - pnpm install --frozen-lockfile - - pnpm exec nx-cloud start-agent - -# Creating template for a job running DTE (orchestrator) -.base-pipeline: +# Main job +CI: interruptible: true only: - main - merge_requests - before_script: - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 + script: + - npm install --prefix=$HOME/.local -g pnpm@8 - pnpm install --frozen-lockfile - NX_HEAD=$CI_COMMIT_SHA - NX_BASE=\${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA} - -# Main job running DTE -CI: - stage: affected - extends: .base-pipeline - script: - - pnpm exec nx-cloud start-ci-run --stop-agents-after="build" - - pnpm exec nx-cloud record -- pnpm exec nx format:check --base=$NX_BASE --head=$NX_HEAD - - pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=lint --parallel=3 & pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=test --parallel=3 --ci --code-coverage & pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=e2e --parallel=3 --ci --code-coverage & pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=build --parallel=3 - -# Create as many agents as you want -nx-dte-agent1: - extends: .dte-agent - stage: affected -nx-dte-agent2: - extends: .dte-agent - stage: affected -nx-dte-agent3: - extends: .dte-agent - stage: affected + # uncomment to enable task distribution + # - pnpm exec nx-cloud start-ci-run --distributes-on="5 linux-medium" + - pnpm exec nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD + - pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD -t=lint,test,build --parallel=3 " `; @@ -618,7 +388,6 @@ pr: variables: CI: 'true' - NX_CLOUD_DISTRIBUTED_EXECUTION: 'true' \${{ if eq(variables['Build.Reason'], 'PullRequest') }}: NX_BRANCH: $(System.PullRequest.PullRequestNumber) TARGET_BRANCH: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')] @@ -629,63 +398,24 @@ variables: HEAD_SHA: $(git rev-parse HEAD) jobs: - - job: agents - strategy: - parallel: 3 - displayName: Nx Cloud Agent - pool: - vmImage: 'ubuntu-latest' - steps: - - script: npm install --prefix=$HOME/.local -g pnpm@8.2.0 - displayName: Install PNPM - - script: pnpm install --frozen-lockfile - displayName: NPM Install Dependencies - - script: npx nx-cloud start-agent - displayName: Start Nx-Cloud agent - - job: main - displayName: Nx Cloud Main pool: vmImage: 'ubuntu-latest' steps: - - script: npm install --prefix=$HOME/.local -g pnpm@8.2.0 - displayName: Install PNPM - - script: pnpm install --frozen-lockfile - displayName: NPM Install Dependencies - - script: pnpm exec nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3 - displayName: Start CI run - - script: pnpm exec nx-cloud record -- pnpm exec nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA) - displayName: Check format - - script: pnpm exec nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=lint --parallel=3 - displayName: Run lint - - script: pnpm exec nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=test --parallel=3 --ci --code-coverage - displayName: Run test - - script: pnpm exec nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=build --parallel=3 - displayName: Run build - - script: pnpm exec nx-cloud stop-all-agents - condition: always() - displayName: Stop all Nx-Cloud agents + - script: yarn install --frozen-lockfile + # uncomment to enable task distribution + # - script: yarn nx-cloud start-ci-run --distributes-on="5 linux-medium" + - script: yarn nx-cloud record -- nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA) + - script: yarn nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t=lint,test,build --parallel=3 " `; exports[`CI Workflow generator with yarn should generate bitbucket pipelines config 1`] = ` -"image: node:16.18 +"image: node:20 clone: depth: full -definitions: - steps: - - step: &agent - name: Agent - script: - - export NX_BRANCH=$BITBUCKET_PR_ID - - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - - pnpm install --frozen-lockfile - - pnpm exec nx-cloud start-agent - pipelines: pull-requests: '**': @@ -695,16 +425,11 @@ pipelines: script: - export NX_BRANCH=$BITBUCKET_PR_ID - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - - pnpm install --frozen-lockfile - - pnpm exec nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3 - - pnpm exec nx-cloud record -- pnpm exec nx format:check - - pnpm exec nx affected --target=lint & pnpm exec nx affected --target=test & pnpm exec nx affected --target=build - - pnpm exec nx-cloud stop-all-agents - - step: *agent - - step: *agent - - step: *agent + - yarn install --frozen-lockfile + # uncomment to enable task distribution + # - yarn nx-cloud start-ci-run --distributes-on="5 linux-medium" + - yarn nx-cloud record -- nx format:check + - yarn nx affected -t=lint,test,build --parallel=3 " `; @@ -712,76 +437,28 @@ exports[`CI Workflow generator with yarn should generate circleci CI config 1`] "version: 2.1 orbs: - nx: nrwl/nx@1.6.1 + nx: nrwl/nx@1.6.2 jobs: - agent: - docker: - - image: cimg/node:lts-browsers - parameters: - ordinal: - type: integer - steps: - - checkout - - - run: - name: Install PNPM - command: npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - run: - name: Install dependencies - command: pnpm install --frozen-lockfile - - run: - name: Start the agent << parameters.ordinal >> - command: pnpm exec nx-cloud start-agent - no_output_timeout: 60m main: docker: - image: cimg/node:lts-browsers - environment: - NX_CLOUD_DISTRIBUTED_EXECUTION: 'true' steps: - checkout - - - run: - name: Install PNPM - command: npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - run: - name: Install dependencies - command: pnpm install --frozen-lockfile + - run: yarn install --frozen-lockfile - nx/set-shas: main-branch-name: 'main' - - run: - name: Initialize the Nx Cloud distributed CI run - command: pnpm exec nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3 - - run: - name: Check format - command: pnpm exec nx-cloud record -- pnpm exec nx format:check --base=$NX_BASE --head=$NX_HEAD - - run: - name: Run lint - command: pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=lint --parallel=3 - - run: - name: Run test - command: pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=test --parallel=3 --ci --code-coverage - - run: - name: Run build - command: pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=build --parallel=3 - - run: - name: Stop all agents - command: pnpm exec nx-cloud stop-all-agents - when: always + # uncomment to enable task distribution + # - run: yarn nx-cloud start-ci-run --distributes-on="5 linux-medium" + - run: yarn nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD + - run: yarn nx affected --base=$NX_BASE --head=$NX_HEAD -t=lint,test,build --parallel=3 workflows: version: 2 ci: jobs: - - agent: - name: Nx Cloud Agent << matrix.ordinal >> - matrix: - parameters: - ordinal: [1, 2, 3] - - main: - name: Nx Cloud Main + - main " `; @@ -794,32 +471,30 @@ on: - main pull_request: -# Needed for nx-set-shas within nx-cloud-main.yml, when run on the main branch permissions: actions: read contents: read jobs: main: - name: Nx Cloud - Main Job - uses: nrwl/ci/.github/workflows/nx-cloud-main.yml@v0.13.1 - 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 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + # Cache node_modules + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: 'yarn' + - run: yarn install --frozen-lockfile + - uses: nrwl/nx-set-shas@v4 - agents: - name: Nx Cloud - Agents - uses: nrwl/ci/.github/workflows/nx-cloud-agents.yml@v0.13.1 - with: - number-of-agents: 3 + # uncomment to enable task distribution + # - run: yarn nx-cloud start-ci-run --distributes-on="5 linux-medium" + + - run: yarn nx-cloud record -- nx format:check + - run: yarn nx affected -t=lint,test,build --parallel=3 " `; @@ -832,81 +507,52 @@ on: - main pull_request: -# Needed for nx-set-shas within nx-cloud-main.yml, when run on the main branch permissions: actions: read contents: read jobs: main: - name: Nx Cloud - Main Job - uses: nrwl/ci/.github/workflows/nx-cloud-main.yml@v0.13.1 - 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 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + # Cache node_modules + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: 'yarn' + - run: yarn install --frozen-lockfile + - uses: nrwl/nx-set-shas@v4 - agents: - name: Nx Cloud - Agents - uses: nrwl/ci/.github/workflows/nx-cloud-agents.yml@v0.13.1 - with: - number-of-agents: 3 + # uncomment to enable task distribution + # - run: yarn nx-cloud start-ci-run --distributes-on="5 linux-medium" + + - run: yarn nx-cloud record -- nx format:check + - run: yarn nx affected -t=lint,test,build --parallel=3 " `; exports[`CI Workflow generator with yarn should generate gitlab config 1`] = ` -"image: node:18 +"image: node:20 variables: CI: 'true' -# Creating template for DTE agents -.dte-agent: - interruptible: true - script: - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - - pnpm install --frozen-lockfile - - pnpm exec nx-cloud start-agent - -# Creating template for a job running DTE (orchestrator) -.base-pipeline: +# Main job +CI: interruptible: true only: - main - merge_requests - before_script: - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 - - - pnpm install --frozen-lockfile + script: + - yarn install --frozen-lockfile - NX_HEAD=$CI_COMMIT_SHA - NX_BASE=\${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA} - -# Main job running DTE -CI: - stage: affected - extends: .base-pipeline - script: - - pnpm exec nx-cloud start-ci-run --stop-agents-after="build" - - pnpm exec nx-cloud record -- pnpm exec nx format:check --base=$NX_BASE --head=$NX_HEAD - - pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=lint --parallel=3 & pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=test --parallel=3 --ci --code-coverage & pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=e2e --parallel=3 --ci --code-coverage & pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD --target=build --parallel=3 - -# Create as many agents as you want -nx-dte-agent1: - extends: .dte-agent - stage: affected -nx-dte-agent2: - extends: .dte-agent - stage: affected -nx-dte-agent3: - extends: .dte-agent - stage: affected + # uncomment to enable task distribution + # - yarn nx-cloud start-ci-run --distributes-on="5 linux-medium" + - yarn nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD + - yarn nx affected --base=$NX_BASE --head=$NX_HEAD -t=lint,test,build --parallel=3 " `; diff --git a/packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts b/packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts index b1c3cb24df..5660502210 100644 --- a/packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts +++ b/packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts @@ -1,5 +1,6 @@ import { NxJsonConfiguration, + PackageManager, readJson, Tree, updateJson, @@ -7,6 +8,24 @@ import { } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import { ciWorkflowGenerator } from './ci-workflow'; +import { vol } from 'memfs'; + +jest.mock('@nx/devkit', () => ({ + ...jest.requireActual('@nx/devkit'), + workspaceRoot: '/root', +})); + +jest.mock('fs', () => { + const memFs = require('memfs').fs; + const actualFs = jest.requireActual('fs'); + return { + ...jest.requireActual('fs'), + existsSync: (p) => + p.endsWith('yarn.lock') || p.endsWith('pnpm-lock.yaml') + ? memFs.existsSync(p) + : actualFs.existsSync(p), + }; +}); describe('CI Workflow generator', () => { let tree: Tree; @@ -15,15 +34,22 @@ describe('CI Workflow generator', () => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); }); - ['npm', 'yarn', 'pnpm'].forEach((packageManager) => { + afterEach(() => { + vol.reset(); + }); + + ['npm', 'yarn', 'pnpm'].forEach((packageManager: PackageManager) => { describe(`with ${packageManager}`, () => { beforeEach(() => { - jest.mock('@nx/devkit', () => ({ - ...jest.requireActual('@nx/devkit'), - detectPackageManager: jest - .fn() - .mockImplementation(() => packageManager), - })); + let fileSys; + if (packageManager === 'yarn') { + fileSys = { 'yarn.lock': '' }; + } else if (packageManager === 'pnpm') { + fileSys = { 'pnpm-lock.yaml': '' }; + } else { + fileSys = { 'package-lock.json': '' }; + } + vol.fromJSON(fileSys, ''); }); it('should generate github CI config', async () => { diff --git a/packages/workspace/src/generators/ci-workflow/ci-workflow.ts b/packages/workspace/src/generators/ci-workflow/ci-workflow.ts index a2a9e59f50..b036d5e427 100644 --- a/packages/workspace/src/generators/ci-workflow/ci-workflow.ts +++ b/packages/workspace/src/generators/ci-workflow/ci-workflow.ts @@ -7,6 +7,7 @@ import { NxJsonConfiguration, formatFiles, writeJson, + detectPackageManager, } from '@nx/devkit'; import { deduceDefaultBase } from '../../utilities/default-base'; import { join } from 'path'; @@ -42,6 +43,7 @@ interface Substitutes { mainBranch: string; workflowName: string; workflowFileName: string; + packageManager: string; packageManagerInstall: string; packageManagerPrefix: string; tmpl: ''; @@ -51,11 +53,13 @@ function normalizeOptions(options: Schema): Substitutes { const { name: workflowName, fileName: workflowFileName } = names( options.name ); + const packageManager = detectPackageManager(); const { exec: packageManagerPrefix, ciInstall: packageManagerInstall } = - getPackageManagerCommand(); + getPackageManagerCommand(packageManager); return { workflowName, workflowFileName, + packageManager, packageManagerInstall, packageManagerPrefix, mainBranch: deduceDefaultBase(), diff --git a/packages/workspace/src/generators/ci-workflow/files/azure/azure-pipelines.yml__tmpl__ b/packages/workspace/src/generators/ci-workflow/files/azure/azure-pipelines.yml__tmpl__ index 2e21dfa3e4..6a06f06631 100644 --- a/packages/workspace/src/generators/ci-workflow/files/azure/azure-pipelines.yml__tmpl__ +++ b/packages/workspace/src/generators/ci-workflow/files/azure/azure-pipelines.yml__tmpl__ @@ -7,7 +7,6 @@ pr: variables: CI: 'true' - NX_CLOUD_DISTRIBUTED_EXECUTION: 'true' ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: NX_BRANCH: $(System.PullRequest.PullRequestNumber) TARGET_BRANCH: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')] @@ -18,41 +17,15 @@ variables: HEAD_SHA: $(git rev-parse HEAD) jobs: - - job: agents - strategy: - parallel: 3 - displayName: Nx Cloud Agent - pool: - vmImage: 'ubuntu-latest' - steps: - <% if(packageManagerPrefix == 'pnpm exec'){ %> - - script: npm install --prefix=$HOME/.local -g pnpm@8.2.0 - displayName: Install PNPM - <% } %>- script: <%= packageManagerInstall %> - displayName: NPM Install Dependencies - - script: npx nx-cloud start-agent - displayName: Start Nx-Cloud agent - - job: main - displayName: Nx Cloud Main pool: vmImage: 'ubuntu-latest' steps: - <% if(packageManagerPrefix == 'pnpm exec'){ %> - - script: npm install --prefix=$HOME/.local -g pnpm@8.2.0 + <% if(packageManager == 'pnpm'){ %> + - script: npm install --prefix=$HOME/.local -g pnpm@8 displayName: Install PNPM <% } %>- script: <%= packageManagerInstall %> - displayName: NPM Install Dependencies - - script: <%= packageManagerPrefix %> nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3 - displayName: Start CI run - - script: <%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA) - displayName: Check format - - script: <%= packageManagerPrefix %> nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=lint --parallel=3 - displayName: Run lint - - script: <%= packageManagerPrefix %> nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=test --parallel=3 --ci --code-coverage - displayName: Run test - - script: <%= packageManagerPrefix %> nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=build --parallel=3 - displayName: Run build - - script: <%= packageManagerPrefix %> nx-cloud stop-all-agents - condition: always() - displayName: Stop all Nx-Cloud agents + # uncomment to enable task distribution + # - script: <%= packageManagerPrefix %> nx-cloud start-ci-run --distributes-on="5 linux-medium" + - script: <%= packageManagerPrefix %> nx-cloud record -- nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA) + - script: <%= packageManagerPrefix %> nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t=lint,test,build --parallel=3 diff --git a/packages/workspace/src/generators/ci-workflow/files/bitbucket-pipelines/bitbucket-pipelines.yml__tmpl__ b/packages/workspace/src/generators/ci-workflow/files/bitbucket-pipelines/bitbucket-pipelines.yml__tmpl__ index 1dedbf5b68..885c3a19c4 100644 --- a/packages/workspace/src/generators/ci-workflow/files/bitbucket-pipelines/bitbucket-pipelines.yml__tmpl__ +++ b/packages/workspace/src/generators/ci-workflow/files/bitbucket-pipelines/bitbucket-pipelines.yml__tmpl__ @@ -1,20 +1,8 @@ -image: node:16.18 +image: node:20 clone: depth: full -definitions: - steps: - - step: &agent - name: Agent - script: - - export NX_BRANCH=$BITBUCKET_PR_ID - <% if(packageManagerPrefix == 'pnpm exec'){ %> - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 - <% } %> - - <%= packageManagerInstall %> - - <%= packageManagerPrefix %> nx-cloud start-agent - pipelines: pull-requests: '**': @@ -23,14 +11,11 @@ pipelines: name: <%= workflowName %> script: - export NX_BRANCH=$BITBUCKET_PR_ID - <% if(packageManagerPrefix == 'pnpm exec'){ %> - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 + <% if(packageManager == 'pnpm'){ %> + - npm install --prefix=$HOME/.local -g pnpm@8 <% } %> - <%= packageManagerInstall %> - - <%= packageManagerPrefix %> nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3 - - <%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx format:check - - <%= packageManagerPrefix %> nx affected --target=lint & <%= packageManagerPrefix %> nx affected --target=test & <%= packageManagerPrefix %> nx affected --target=build - - <%= packageManagerPrefix %> nx-cloud stop-all-agents - - step: *agent - - step: *agent - - step: *agent + # uncomment to enable task distribution + # - <%= packageManagerPrefix %> nx-cloud start-ci-run --distributes-on="5 linux-medium" + - <%= packageManagerPrefix %> nx-cloud record -- nx format:check + - <%= packageManagerPrefix %> nx affected -t=lint,test,build --parallel=3 diff --git a/packages/workspace/src/generators/ci-workflow/files/circleci/.circleci/config.yml__tmpl__ b/packages/workspace/src/generators/ci-workflow/files/circleci/.circleci/config.yml__tmpl__ index e26122f351..949e0e3166 100644 --- a/packages/workspace/src/generators/ci-workflow/files/circleci/.circleci/config.yml__tmpl__ +++ b/packages/workspace/src/generators/ci-workflow/files/circleci/.circleci/config.yml__tmpl__ @@ -1,73 +1,29 @@ version: 2.1 orbs: - nx: nrwl/nx@1.6.1 + nx: nrwl/nx@1.6.2 jobs: - agent: - docker: - - image: cimg/node:lts-browsers - parameters: - ordinal: - type: integer - steps: - - checkout - <% if(packageManagerPrefix == 'pnpm exec'){ %> - - run: - name: Install PNPM - command: npm install --prefix=$HOME/.local -g pnpm@8.2.0 - <% } %>- run: - name: Install dependencies - command: <%= packageManagerInstall %> - - run: - name: Start the agent << parameters.ordinal >> - command: <%= packageManagerPrefix %> nx-cloud start-agent - no_output_timeout: 60m main: docker: - image: cimg/node:lts-browsers - environment: - NX_CLOUD_DISTRIBUTED_EXECUTION: 'true' steps: - checkout - <% if(packageManagerPrefix == 'pnpm exec'){ %> + <% if(packageManager == 'pnpm'){ %> - run: name: Install PNPM - command: npm install --prefix=$HOME/.local -g pnpm@8.2.0 - <% } %>- run: - name: Install dependencies - command: <%= packageManagerInstall %> + command: npm install --prefix=$HOME/.local -g pnpm@8 + <% } %>- run: <%= packageManagerInstall %> - nx/set-shas: main-branch-name: '<%= mainBranch %>' - - run: - name: Initialize the Nx Cloud distributed CI run - command: <%= packageManagerPrefix %> nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3 - - run: - name: Check format - command: <%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx format:check --base=$NX_BASE --head=$NX_HEAD - - run: - name: Run lint - command: <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=lint --parallel=3 - - run: - name: Run test - command: <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=test --parallel=3 --ci --code-coverage - - run: - name: Run build - command: <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=build --parallel=3 - - run: - name: Stop all agents - command: <%= packageManagerPrefix %> nx-cloud stop-all-agents - when: always + # uncomment to enable task distribution + # - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distributes-on="5 linux-medium" + - run: <%= packageManagerPrefix %> nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD + - run: <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD -t=lint,test,build --parallel=3 workflows: version: 2 <%= workflowFileName %>: jobs: - - agent: - name: Nx Cloud Agent << matrix.ordinal >> - matrix: - parameters: - ordinal: [1, 2, 3] - - main: - name: Nx Cloud Main + - main diff --git a/packages/workspace/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml__tmpl__ b/packages/workspace/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml__tmpl__ index cce752af66..12b5b43d26 100644 --- a/packages/workspace/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml__tmpl__ +++ b/packages/workspace/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml__tmpl__ @@ -6,29 +6,31 @@ on: - <%= mainBranch %> pull_request: -# Needed for nx-set-shas within nx-cloud-main.yml, when run on the <%= mainBranch %> branch permissions: actions: read contents: read jobs: main: - name: Nx Cloud - Main Job - uses: nrwl/ci/.github/workflows/nx-cloud-main.yml@v0.13.1 - with: - main-branch-name: <%= mainBranch %> - number-of-agents: 3 - init-commands: | - <%= packageManagerPrefix %> nx-cloud start-ci-run --stop-agents-after="build" --agent-count=3 - parallel-commands: | - <%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx format:check - parallel-commands-on-agents: | - <%= packageManagerPrefix %> nx affected --target=lint --parallel=3 - <%= packageManagerPrefix %> nx affected --target=test --parallel=3 --ci --code-coverage - <%= packageManagerPrefix %> nx affected --target=build --parallel=3 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + <% if(packageManager == 'pnpm'){ %> + - uses: pnpm/action-setup@v2 + with: + version: 8 + <% } %># Cache node_modules + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: '<%= packageManager %>' + - run: <%= packageManagerInstall %> + - uses: nrwl/nx-set-shas@v4 - agents: - name: Nx Cloud - Agents - uses: nrwl/ci/.github/workflows/nx-cloud-agents.yml@v0.13.1 - with: - number-of-agents: 3 + # uncomment to enable task distribution + # - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distributes-on="5 linux-medium" + + - run: <%= packageManagerPrefix %> nx-cloud record -- nx format:check + - run: <%= packageManagerPrefix %> nx affected -t=lint,test,build --parallel=3 diff --git a/packages/workspace/src/generators/ci-workflow/files/gitlab/.gitlab-ci.yml__tmpl__ b/packages/workspace/src/generators/ci-workflow/files/gitlab/.gitlab-ci.yml__tmpl__ index 9b0d1a24c7..3c004b8841 100644 --- a/packages/workspace/src/generators/ci-workflow/files/gitlab/.gitlab-ci.yml__tmpl__ +++ b/packages/workspace/src/generators/ci-workflow/files/gitlab/.gitlab-ci.yml__tmpl__ @@ -1,47 +1,21 @@ -image: node:18 +image: node:20 variables: CI: 'true' -# Creating template for DTE agents -.dte-agent: - interruptible: true - script: - <% if(packageManagerPrefix == 'pnpm exec'){ %> - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 - <% } %> - - <%= packageManagerInstall %> - - <%= packageManagerPrefix %> nx-cloud start-agent - -# Creating template for a job running DTE (orchestrator) -.base-pipeline: +# Main job +<%= workflowName %>: interruptible: true only: - main - merge_requests - before_script: - <% if(packageManagerPrefix == 'pnpm exec'){ %> - - npm install --prefix=$HOME/.local -g pnpm@8.2.0 + script: + <% if(packageManager == 'pnpm'){ %> + - npm install --prefix=$HOME/.local -g pnpm@8 <% } %> - <%= packageManagerInstall %> - NX_HEAD=$CI_COMMIT_SHA - NX_BASE=${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA} - -# Main job running DTE -<%= workflowName %>: - stage: affected - extends: .base-pipeline - script: - - <%= packageManagerPrefix %> nx-cloud start-ci-run --stop-agents-after="build" - - <%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx format:check --base=$NX_BASE --head=$NX_HEAD - - <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=lint --parallel=3 & <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=test --parallel=3 --ci --code-coverage & <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=e2e --parallel=3 --ci --code-coverage & <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=build --parallel=3 - -# Create as many agents as you want -nx-dte-agent1: - extends: .dte-agent - stage: affected -nx-dte-agent2: - extends: .dte-agent - stage: affected -nx-dte-agent3: - extends: .dte-agent - stage: affected + # uncomment to enable task distribution + # - <%= packageManagerPrefix %> nx-cloud start-ci-run --distributes-on="5 linux-medium" + - <%= packageManagerPrefix %> nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD + - <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD -t=lint,test,build --parallel=3