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 2646ad13646e3..92f5d7461f6b0 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 @@ -1,5 +1,235 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`CI Workflow generator connected to nxCloud optional e2e should add e2e to azure CI config 1`] = ` +"name: CI + +trigger: + - main +pr: + - main + +variables: + CI: 'true' + \${{ if eq(variables['Build.Reason'], 'PullRequest') }}: + NX_BRANCH: $(System.PullRequest.PullRequestNumber) + TARGET_BRANCH: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')] + BASE_SHA: $(git merge-base $(TARGET_BRANCH) HEAD) + \${{ if ne(variables['Build.Reason'], 'PullRequest') }}: + NX_BRANCH: $(Build.SourceBranchName) + BASE_SHA: $(git rev-parse HEAD~1) + HEAD_SHA: $(git rev-parse HEAD) + +jobs: + - job: main + pool: + vmImage: 'ubuntu-latest' + steps: + - checkout: self + fetchDepth: 0 + # Set Azure Devops CLI default settings + - bash: az devops configure --defaults organization=$(System.TeamFoundationCollectionUri) project=$(System.TeamProject) + displayName: 'Set default Azure DevOps organization and project' + # Get last successfull commit from Azure Devops CLI + - bash: | + LAST_SHA=$(az pipelines build list --branch $(Build.SourceBranchName) --definition-ids $(System.DefinitionId) --result succeeded --top 1 --query "[0].triggerInfo.\\"ci.sourceSha\\"") + if [ -z "$LAST_SHA" ] + then + echo "Last successful commit not found. Using fallback 'HEAD~1': $BASE_SHA" + else + echo "Last successful commit SHA: $LAST_SHA" + echo "##vso[task.setvariable variable=BASE_SHA]$LAST_SHA" + fi + displayName: 'Get last successful commit SHA' + condition: ne(variables['Build.Reason'], 'PullRequest') + env: + AZURE_DEVOPS_EXT_PAT: $(System.AccessToken) + + # This enables task distribution via Nx Cloud + # Run this command as early as possible, before dependencies are installed + # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun + - script: npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" + + - script: npm ci --legacy-peer-deps + - script: git branch --track main origin/main + condition: eq(variables['Build.Reason'], 'PullRequest') + + # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud + # - script: npx nx-cloud record -- echo Hello World + # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected + - script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) lint test build + - script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --parallel 1 e2e-ci +" +`; + +exports[`CI Workflow generator connected to nxCloud optional e2e should add e2e to bitbucket pipelines config 1`] = ` +"image: node:20 + +clone: + depth: full + +pipelines: + pull-requests: + '**': + - step: + name: 'Build and test affected apps on Pull Requests' + script: + - export NX_BRANCH=$BITBUCKET_PR_ID + + # This enables task distribution via Nx Cloud + # Run this command as early as possible, before dependencies are installed + # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun + - npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" + + - npm ci --legacy-peer-deps + + - npx nx-cloud record -- nx format:check + # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected + - npx nx affected --base=origin/main -t lint test build + - npx nx affected --base=origin/main --parallel 1 -t e2e-ci + + branches: + main: + - step: + name: 'Build and test affected apps on "main" branch changes' + script: + - export NX_BRANCH=$BITBUCKET_BRANCH + # This enables task distribution via Nx Cloud + # Run this command as early as possible, before dependencies are installed + # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun + - npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" + + - npm ci --legacy-peer-deps + + # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud + # - npx nx-cloud record -- echo Hello World + # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected + - npx nx affected -t lint test build e2e-ci --base=HEAD~1 +" +`; + +exports[`CI Workflow generator connected to nxCloud optional e2e should add e2e to circleci CI config 1`] = ` +"version: 2.1 + +orbs: + nx: nrwl/nx@1.6.2 + +jobs: + main: + docker: + - image: cimg/node:lts-browsers + steps: + - checkout + + # This enables task distribution via Nx Cloud + # Run this command as early as possible, before dependencies are installed + # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun + - run: npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" + + - run: npm ci --legacy-peer-deps + - nx/set-shas: + main-branch-name: 'main' + + # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud + # - run: npx nx-cloud record -- echo Hello World + # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected + - run: npx nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build + - run: npx nx affected --base=$NX_BASE --head=$NX_HEAD --parallel 1 -t e2e-ci + +workflows: + version: 2 + + ci: + jobs: + - main +" +`; + +exports[`CI Workflow generator connected to nxCloud optional e2e should add e2e to github CI config 1`] = ` +"name: CI + +on: + push: + branches: + - main + pull_request: + +permissions: + actions: read + contents: read + +jobs: + main: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # This enables task distribution via Nx Cloud + # Run this command as early as possible, before dependencies are installed + # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun + - run: npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" + + # Cache node_modules + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: 'npm' + + - run: npm ci --legacy-peer-deps + - uses: nrwl/nx-set-shas@v4 + + # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud + # - run: npx nx-cloud record -- echo Hello World + # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected + - run: npx nx affected -t lint test build + - run: npx nx affected --parallel 1 -t e2e-ci +" +`; + +exports[`CI Workflow generator connected to nxCloud optional e2e should add e2e to github CI config with custom name 1`] = ` +"name: My custom-workflow + +on: + push: + branches: + - main + pull_request: + +permissions: + actions: read + contents: read + +jobs: + main: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # This enables task distribution via Nx Cloud + # Run this command as early as possible, before dependencies are installed + # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun + - run: npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" + + # Cache node_modules + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: 'npm' + + - run: npm ci --legacy-peer-deps + - uses: nrwl/nx-set-shas@v4 + + # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud + # - run: npx nx-cloud record -- echo Hello World + # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected + - run: npx nx affected -t lint test build + - run: npx nx affected --parallel 1 -t e2e-ci +" +`; + exports[`CI Workflow generator connected to nxCloud with bun should generate azure CI config 1`] = ` "name: CI @@ -1042,7 +1272,7 @@ CI: " `; -exports[`CI Workflow generator not connected to nxCloud with bun should generate azure CI config 1`] = ` +exports[`CI Workflow generator not connected to nxCloud optional e2e should add e2e to azure CI config 1`] = ` "name: CI trigger: @@ -1086,27 +1316,25 @@ jobs: env: AZURE_DEVOPS_EXT_PAT: $(System.AccessToken) - - script: npm install --prefix=$HOME/.local -g Bun - displayName: Install Bun - # This enables task distribution via Nx Cloud # Run this command as early as possible, before dependencies are installed # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun # Connect your workspace by running "nx connect" and uncomment this - # - script: bunx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="build" + # - script: npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" - - script: bun install --no-cache + - script: npm ci --legacy-peer-deps - script: git branch --track main origin/main condition: eq(variables['Build.Reason'], 'PullRequest') # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud - # - script: bun nx-cloud record -- echo Hello World + # - script: npx nx-cloud record -- echo Hello World # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected - - script: bun nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) lint test build + - script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) lint test build + - script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --parallel 1 e2e-ci " `; -exports[`CI Workflow generator not connected to nxCloud with bun should generate bitbucket pipelines config 1`] = ` +exports[`CI Workflow generator not connected to nxCloud optional e2e should add e2e to bitbucket pipelines config 1`] = ` "image: node:20 clone: @@ -1120,19 +1348,18 @@ pipelines: script: - export NX_BRANCH=$BITBUCKET_PR_ID - - npm install --prefix=$HOME/.local -g bun - # This enables task distribution via Nx Cloud # Run this command as early as possible, before dependencies are installed # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun # Connect your workspace by running "nx connect" and uncomment this - # - bunx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="build" + # - npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" - - bun install --no-cache + - npm ci --legacy-peer-deps - - bun nx-cloud record -- nx format:check + - npx nx-cloud record -- nx format:check # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected - - bun nx affected --base=origin/main -t lint test build + - npx nx affected --base=origin/main -t lint test build + - npx nx affected --base=origin/main --parallel 1 -t e2e-ci branches: main: @@ -1144,16 +1371,255 @@ pipelines: # Run this command as early as possible, before dependencies are installed # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun # Connect your workspace by running "nx connect" and uncomment this - # - bunx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="build" - - - npm install --prefix=$HOME/.local -g bun + # - npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" - - bun install --no-cache + - npm ci --legacy-peer-deps # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud - # - bun nx-cloud record -- echo Hello World + # - npx nx-cloud record -- echo Hello World # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected - - bun nx affected -t lint test build --base=HEAD~1 + - npx nx affected -t lint test build e2e-ci --base=HEAD~1 +" +`; + +exports[`CI Workflow generator not connected to nxCloud optional e2e should add e2e to circleci CI config 1`] = ` +"version: 2.1 + +orbs: + nx: nrwl/nx@1.6.2 + +jobs: + main: + docker: + - image: cimg/node:lts-browsers + steps: + - checkout + + # This enables task distribution via Nx Cloud + # Run this command as early as possible, before dependencies are installed + # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun + # Connect your workspace by running "nx connect" and uncomment this + # - run: npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" + + - run: npm ci --legacy-peer-deps + - nx/set-shas: + main-branch-name: 'main' + + # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud + # - run: npx nx-cloud record -- echo Hello World + # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected + - run: npx nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build + - run: npx nx affected --base=$NX_BASE --head=$NX_HEAD --parallel 1 -t e2e-ci + +workflows: + version: 2 + + ci: + jobs: + - main +" +`; + +exports[`CI Workflow generator not connected to nxCloud optional e2e should add e2e to github CI config 1`] = ` +"name: CI + +on: + push: + branches: + - main + pull_request: + +permissions: + actions: read + contents: read + +jobs: + main: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # This enables task distribution via Nx Cloud + # Run this command as early as possible, before dependencies are installed + # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun + # Connect your workspace by running "nx connect" and uncomment this + # - run: npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" + + # Cache node_modules + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: 'npm' + + - run: npm ci --legacy-peer-deps + - uses: nrwl/nx-set-shas@v4 + + # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud + # - run: npx nx-cloud record -- echo Hello World + # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected + - run: npx nx affected -t lint test build + - run: npx nx affected --parallel 1 -t e2e-ci +" +`; + +exports[`CI Workflow generator not connected to nxCloud optional e2e should add e2e to github CI config with custom name 1`] = ` +"name: My custom-workflow + +on: + push: + branches: + - main + pull_request: + +permissions: + actions: read + contents: read + +jobs: + main: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # This enables task distribution via Nx Cloud + # Run this command as early as possible, before dependencies are installed + # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun + # Connect your workspace by running "nx connect" and uncomment this + # - run: npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" + + # Cache node_modules + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: 'npm' + + - run: npm ci --legacy-peer-deps + - uses: nrwl/nx-set-shas@v4 + + # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud + # - run: npx nx-cloud record -- echo Hello World + # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected + - run: npx nx affected -t lint test build + - run: npx nx affected --parallel 1 -t e2e-ci +" +`; + +exports[`CI Workflow generator not connected to nxCloud with bun should generate azure CI config 1`] = ` +"name: CI + +trigger: + - main +pr: + - main + +variables: + CI: 'true' + \${{ if eq(variables['Build.Reason'], 'PullRequest') }}: + NX_BRANCH: $(System.PullRequest.PullRequestNumber) + TARGET_BRANCH: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')] + BASE_SHA: $(git merge-base $(TARGET_BRANCH) HEAD) + \${{ if ne(variables['Build.Reason'], 'PullRequest') }}: + NX_BRANCH: $(Build.SourceBranchName) + BASE_SHA: $(git rev-parse HEAD~1) + HEAD_SHA: $(git rev-parse HEAD) + +jobs: + - job: main + pool: + vmImage: 'ubuntu-latest' + steps: + - checkout: self + fetchDepth: 0 + # Set Azure Devops CLI default settings + - bash: az devops configure --defaults organization=$(System.TeamFoundationCollectionUri) project=$(System.TeamProject) + displayName: 'Set default Azure DevOps organization and project' + # Get last successfull commit from Azure Devops CLI + - bash: | + LAST_SHA=$(az pipelines build list --branch $(Build.SourceBranchName) --definition-ids $(System.DefinitionId) --result succeeded --top 1 --query "[0].triggerInfo.\\"ci.sourceSha\\"") + if [ -z "$LAST_SHA" ] + then + echo "Last successful commit not found. Using fallback 'HEAD~1': $BASE_SHA" + else + echo "Last successful commit SHA: $LAST_SHA" + echo "##vso[task.setvariable variable=BASE_SHA]$LAST_SHA" + fi + displayName: 'Get last successful commit SHA' + condition: ne(variables['Build.Reason'], 'PullRequest') + env: + AZURE_DEVOPS_EXT_PAT: $(System.AccessToken) + + - script: npm install --prefix=$HOME/.local -g Bun + displayName: Install Bun + + # This enables task distribution via Nx Cloud + # Run this command as early as possible, before dependencies are installed + # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun + # Connect your workspace by running "nx connect" and uncomment this + # - script: bunx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="build" + + - script: bun install --no-cache + - script: git branch --track main origin/main + condition: eq(variables['Build.Reason'], 'PullRequest') + + # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud + # - script: bun nx-cloud record -- echo Hello World + # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected + - script: bun nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) lint test build +" +`; + +exports[`CI Workflow generator not connected to nxCloud with bun should generate bitbucket pipelines config 1`] = ` +"image: node:20 + +clone: + depth: full + +pipelines: + pull-requests: + '**': + - step: + name: 'Build and test affected apps on Pull Requests' + script: + - export NX_BRANCH=$BITBUCKET_PR_ID + + - npm install --prefix=$HOME/.local -g bun + + # This enables task distribution via Nx Cloud + # Run this command as early as possible, before dependencies are installed + # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun + # Connect your workspace by running "nx connect" and uncomment this + # - bunx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="build" + + - bun install --no-cache + + - bun nx-cloud record -- nx format:check + # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected + - bun nx affected --base=origin/main -t lint test build + + branches: + main: + - step: + name: 'Build and test affected apps on "main" branch changes' + script: + - export NX_BRANCH=$BITBUCKET_BRANCH + # This enables task distribution via Nx Cloud + # Run this command as early as possible, before dependencies are installed + # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun + # Connect your workspace by running "nx connect" and uncomment this + # - bunx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="build" + + - npm install --prefix=$HOME/.local -g bun + + - bun install --no-cache + + # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud + # - bun nx-cloud record -- echo Hello World + # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected + - bun nx affected -t lint test build --base=HEAD~1 " `; @@ -2111,233 +2577,3 @@ CI: - yarn nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build " `; - -exports[`CI Workflow generator optional e2e should add e2e to azure CI config 1`] = ` -"name: CI - -trigger: - - main -pr: - - main - -variables: - CI: 'true' - \${{ if eq(variables['Build.Reason'], 'PullRequest') }}: - NX_BRANCH: $(System.PullRequest.PullRequestNumber) - TARGET_BRANCH: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')] - BASE_SHA: $(git merge-base $(TARGET_BRANCH) HEAD) - \${{ if ne(variables['Build.Reason'], 'PullRequest') }}: - NX_BRANCH: $(Build.SourceBranchName) - BASE_SHA: $(git rev-parse HEAD~1) - HEAD_SHA: $(git rev-parse HEAD) - -jobs: - - job: main - pool: - vmImage: 'ubuntu-latest' - steps: - - checkout: self - fetchDepth: 0 - # Set Azure Devops CLI default settings - - bash: az devops configure --defaults organization=$(System.TeamFoundationCollectionUri) project=$(System.TeamProject) - displayName: 'Set default Azure DevOps organization and project' - # Get last successfull commit from Azure Devops CLI - - bash: | - LAST_SHA=$(az pipelines build list --branch $(Build.SourceBranchName) --definition-ids $(System.DefinitionId) --result succeeded --top 1 --query "[0].triggerInfo.\\"ci.sourceSha\\"") - if [ -z "$LAST_SHA" ] - then - echo "Last successful commit not found. Using fallback 'HEAD~1': $BASE_SHA" - else - echo "Last successful commit SHA: $LAST_SHA" - echo "##vso[task.setvariable variable=BASE_SHA]$LAST_SHA" - fi - displayName: 'Get last successful commit SHA' - condition: ne(variables['Build.Reason'], 'PullRequest') - env: - AZURE_DEVOPS_EXT_PAT: $(System.AccessToken) - - # This enables task distribution via Nx Cloud - # Run this command as early as possible, before dependencies are installed - # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun - - script: npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" - - - script: npm ci --legacy-peer-deps - - script: git branch --track main origin/main - condition: eq(variables['Build.Reason'], 'PullRequest') - - # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud - # - script: npx nx-cloud record -- echo Hello World - # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected - - script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) lint test build - - script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --parallel 1 e2e-ci -" -`; - -exports[`CI Workflow generator optional e2e should add e2e to bitbucket pipelines config 1`] = ` -"image: node:20 - -clone: - depth: full - -pipelines: - pull-requests: - '**': - - step: - name: 'Build and test affected apps on Pull Requests' - script: - - export NX_BRANCH=$BITBUCKET_PR_ID - - # This enables task distribution via Nx Cloud - # Run this command as early as possible, before dependencies are installed - # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun - - npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" - - - npm ci --legacy-peer-deps - - - npx nx-cloud record -- nx format:check - # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected - - npx nx affected --base=origin/main -t lint test build - - npx nx affected --base=origin/main --parallel 1 -t e2e-ci - - branches: - main: - - step: - name: 'Build and test affected apps on "main" branch changes' - script: - - export NX_BRANCH=$BITBUCKET_BRANCH - # This enables task distribution via Nx Cloud - # Run this command as early as possible, before dependencies are installed - # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun - - npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" - - - npm ci --legacy-peer-deps - - # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud - # - npx nx-cloud record -- echo Hello World - # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected - - npx nx affected -t lint test build e2e-ci --base=HEAD~1 -" -`; - -exports[`CI Workflow generator optional e2e should add e2e to circleci CI config 1`] = ` -"version: 2.1 - -orbs: - nx: nrwl/nx@1.6.2 - -jobs: - main: - docker: - - image: cimg/node:lts-browsers - steps: - - checkout - - # This enables task distribution via Nx Cloud - # Run this command as early as possible, before dependencies are installed - # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun - - run: npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" - - - run: npm ci --legacy-peer-deps - - nx/set-shas: - main-branch-name: 'main' - - # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud - # - run: npx nx-cloud record -- echo Hello World - # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected - - run: npx nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build - - run: npx nx affected --base=$NX_BASE --head=$NX_HEAD --parallel 1 -t e2e-ci - -workflows: - version: 2 - - ci: - jobs: - - main -" -`; - -exports[`CI Workflow generator optional e2e should add e2e to github CI config 1`] = ` -"name: CI - -on: - push: - branches: - - main - pull_request: - -permissions: - actions: read - contents: read - -jobs: - main: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - # This enables task distribution via Nx Cloud - # Run this command as early as possible, before dependencies are installed - # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun - - run: npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" - - # Cache node_modules - - uses: actions/setup-node@v3 - with: - node-version: 20 - cache: 'npm' - - - run: npm ci --legacy-peer-deps - - uses: nrwl/nx-set-shas@v4 - - # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud - # - run: npx nx-cloud record -- echo Hello World - # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected - - run: npx nx affected -t lint test build - - run: npx nx affected --parallel 1 -t e2e-ci -" -`; - -exports[`CI Workflow generator optional e2e should add e2e to github CI config with custom name 1`] = ` -"name: My custom-workflow - -on: - push: - branches: - - main - pull_request: - -permissions: - actions: read - contents: read - -jobs: - main: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - # This enables task distribution via Nx Cloud - # Run this command as early as possible, before dependencies are installed - # Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun - - run: npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="e2e-ci" - - # Cache node_modules - - uses: actions/setup-node@v3 - with: - node-version: 20 - cache: 'npm' - - - run: npm ci --legacy-peer-deps - - uses: nrwl/nx-set-shas@v4 - - # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud - # - run: npx nx-cloud record -- echo Hello World - # Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected - - run: npx nx affected -t lint test build - - run: npx nx affected --parallel 1 -t e2e-ci -" -`; 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 400d80172345a..50342c6b69ffb 100644 --- a/packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts +++ b/packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts @@ -11,6 +11,20 @@ import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import { ciWorkflowGenerator } from './ci-workflow'; import { vol } from 'memfs'; +jest.mock('child_process', () => { + const cp = jest.requireActual('child_process'); + return { + ...cp, + execSync: (...args) => { + if (args[0] === 'yarn --version') { + return '1.22.10'; + } else { + return cp.execSync(...args); + } + }, + }; +}); + jest.mock('@nx/devkit', () => ({ ...jest.requireActual('@nx/devkit'), workspaceRoot: '/root', @@ -161,55 +175,57 @@ describe('CI Workflow generator', () => { }); }); }); - }); - describe('optional e2e', () => { - beforeEach(() => { - updateJson(tree, 'package.json', (json) => { - json.devDependencies = { - ...json.devDependencies, - '@nx/cypress': 'latest', - }; - return json; + describe('optional e2e', () => { + beforeEach(() => { + updateJson(tree, 'package.json', (json) => { + json.devDependencies = { + ...json.devDependencies, + '@nx/cypress': 'latest', + }; + return json; + }); }); - }); - it('should add e2e to github CI config', async () => { - await ciWorkflowGenerator(tree, { ci: 'github', name: 'CI' }); + it('should add e2e to github CI config', async () => { + await ciWorkflowGenerator(tree, { ci: 'github', name: 'CI' }); - expect(tree.read('.github/workflows/ci.yml', 'utf-8')).toMatchSnapshot(); - }); - - it('should add e2e to circleci CI config', async () => { - await ciWorkflowGenerator(tree, { ci: 'circleci', name: 'CI' }); + expect( + tree.read('.github/workflows/ci.yml', 'utf-8') + ).toMatchSnapshot(); + }); - expect(tree.read('.circleci/config.yml', 'utf-8')).toMatchSnapshot(); - }); + it('should add e2e to circleci CI config', async () => { + await ciWorkflowGenerator(tree, { ci: 'circleci', name: 'CI' }); - it('should add e2e to azure CI config', async () => { - await ciWorkflowGenerator(tree, { ci: 'azure', name: 'CI' }); + expect(tree.read('.circleci/config.yml', 'utf-8')).toMatchSnapshot(); + }); - expect(tree.read('azure-pipelines.yml', 'utf-8')).toMatchSnapshot(); - }); + it('should add e2e to azure CI config', async () => { + await ciWorkflowGenerator(tree, { ci: 'azure', name: 'CI' }); - it('should add e2e to github CI config with custom name', async () => { - await ciWorkflowGenerator(tree, { - ci: 'github', - name: 'My custom-workflow', + expect(tree.read('azure-pipelines.yml', 'utf-8')).toMatchSnapshot(); }); - expect( - tree.read('.github/workflows/my-custom-workflow.yml', 'utf-8') - ).toMatchSnapshot(); - }); + it('should add e2e to github CI config with custom name', async () => { + await ciWorkflowGenerator(tree, { + ci: 'github', + name: 'My custom-workflow', + }); - it('should add e2e to bitbucket pipelines config', async () => { - await ciWorkflowGenerator(tree, { - ci: 'bitbucket-pipelines', - name: 'CI', + expect( + tree.read('.github/workflows/my-custom-workflow.yml', 'utf-8') + ).toMatchSnapshot(); }); - expect(tree.read('bitbucket-pipelines.yml', 'utf-8')).toMatchSnapshot(); + it('should add e2e to bitbucket pipelines config', async () => { + await ciWorkflowGenerator(tree, { + ci: 'bitbucket-pipelines', + name: 'CI', + }); + + expect(tree.read('bitbucket-pipelines.yml', 'utf-8')).toMatchSnapshot(); + }); }); });