From 3d88cc777fd18667012b7ca26db84b88d06cff16 Mon Sep 17 00:00:00 2001 From: Emily Xiong Date: Fri, 21 Jun 2024 19:16:32 -0400 Subject: [PATCH] feat(gradle): uncomment start-ci-run --- .../__snapshots__/generator.spec.ts.snap | 20 ++- .../circleci/.circleci/config.yml.template | 9 +- .../__workflowFileName__.yml.template | 2 +- .../src/generators/ci-workflow/generator.ts | 4 + .../__snapshots__/ci-workflow.spec.ts.snap | 164 +++++++++++++----- .../src/generators/ci-workflow/ci-workflow.ts | 6 +- .../files/azure/azure-pipelines.yml__tmpl__ | 10 +- .../bitbucket-pipelines.yml__tmpl__ | 18 +- .../circleci/.circleci/config.yml__tmpl__ | 9 +- .../__workflowFileName__.yml__tmpl__ | 9 +- .../files/gitlab/.gitlab-ci.yml__tmpl__ | 11 +- 11 files changed, 183 insertions(+), 79 deletions(-) diff --git a/packages/gradle/src/generators/ci-workflow/__snapshots__/generator.spec.ts.snap b/packages/gradle/src/generators/ci-workflow/__snapshots__/generator.spec.ts.snap index 86dad706a30d90..b444ef85651571 100644 --- a/packages/gradle/src/generators/ci-workflow/__snapshots__/generator.spec.ts.snap +++ b/packages/gradle/src/generators/ci-workflow/__snapshots__/generator.spec.ts.snap @@ -16,11 +16,14 @@ jobs: - image: cimg/openjdk:17.0-node steps: - checkout - - # Connect your workspace on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested + + # 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 + <% if (connectedToCloud) { %>- run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build" + <% } else { %># Connect your workspace on nx.app and uncomment this to enable task distribution. # - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build" - + <% } %> - nx/set-shas: main-branch-name: 'main' @@ -56,10 +59,13 @@ jobs: with: fetch-depth: 0 - # Connect your workspace on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested + # 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 + <% if (connectedToCloud) { %>- run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build" + <% } else { %># Connect your workspace on nx.app and uncomment this to enable task distribution. # - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build" - + <% } %> - name: Set up JDK 17 for x64 uses: actions/setup-java@v4 with: diff --git a/packages/gradle/src/generators/ci-workflow/files/circleci/.circleci/config.yml.template b/packages/gradle/src/generators/ci-workflow/files/circleci/.circleci/config.yml.template index 8c4f695c7791d2..58967947edb165 100644 --- a/packages/gradle/src/generators/ci-workflow/files/circleci/.circleci/config.yml.template +++ b/packages/gradle/src/generators/ci-workflow/files/circleci/.circleci/config.yml.template @@ -14,10 +14,13 @@ jobs: steps: - checkout - # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested + # 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 + <% if (connectedToCloud) { %>- run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build" + <% } else { %># Connect your workspace on nx.app and uncomment this to enable task distribution. # - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build" - + <% } %> - nx/set-shas: main-branch-name: '<%= mainBranch %>' diff --git a/packages/gradle/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml.template b/packages/gradle/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml.template index 938ba9624a08d4..ff18c64e51ad2d 100644 --- a/packages/gradle/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml.template +++ b/packages/gradle/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml.template @@ -20,7 +20,7 @@ jobs: # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution. # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested - # - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build" + - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build" - name: Set up JDK 17 for x64 uses: actions/setup-java@v4 diff --git a/packages/gradle/src/generators/ci-workflow/generator.ts b/packages/gradle/src/generators/ci-workflow/generator.ts index f548efb227a4ca..017aa07e565314 100644 --- a/packages/gradle/src/generators/ci-workflow/generator.ts +++ b/packages/gradle/src/generators/ci-workflow/generator.ts @@ -47,6 +47,7 @@ interface Substitutes { packageManagerPrefix: string; commands: string[]; nxCloudHost: string; + connectedTocloud: boolean; } function getTemplateData(tree: Tree, options: Schema): Substitutes { @@ -67,6 +68,8 @@ function getTemplateData(tree: Tree, options: Schema): Substitutes { const commands = options.commands ?? getCiCommands(options.ci, mainBranch); + const connectedTocloud = isNxCloudUsed(readNxJson(tree)); + return { workflowName, workflowFileName, @@ -75,6 +78,7 @@ function getTemplateData(tree: Tree, options: Schema): Substitutes { commands, mainBranch, nxCloudHost, + connectedTocloud, }; } 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 552b31e974b873..3f9fa827eba9c5 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 @@ -44,8 +44,10 @@ jobs: 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 # Connect your workspace on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested # - script: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci" - script: npm ci @@ -73,8 +75,10 @@ pipelines: 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 # Connect your workspace on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested # - npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci" - npm ci @@ -89,8 +93,10 @@ pipelines: 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested # - npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci" - npm ci @@ -114,8 +120,10 @@ jobs: 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested # - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci" - run: npm ci @@ -157,8 +165,10 @@ jobs: 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested # - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci" # Cache node_modules @@ -198,8 +208,10 @@ jobs: 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested # - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci" # Cache node_modules @@ -265,8 +277,10 @@ jobs: - 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - script: bunx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - script: bun install --no-cache @@ -295,8 +309,10 @@ pipelines: - 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - bunx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - bun install --no-cache @@ -310,8 +326,10 @@ pipelines: 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - bunx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - npm install --prefix=$HOME/.local -g bun @@ -341,8 +359,10 @@ jobs: name: Install Bun command: 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - run: bunx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - run: bun install --no-cache @@ -387,8 +407,10 @@ jobs: with: bun-version: latest + # 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - run: bunx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - run: bun install --no-cache @@ -425,8 +447,10 @@ jobs: with: bun-version: latest + # 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - run: bunx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - run: bun install --no-cache @@ -452,8 +476,10 @@ CI: script: - 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - bunx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - bun install --no-cache @@ -510,8 +536,10 @@ jobs: 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 # Connect your workspace on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - script: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - script: npm ci @@ -538,8 +566,10 @@ pipelines: 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 # Connect your workspace on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - npm ci @@ -553,8 +583,10 @@ pipelines: 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - npm ci @@ -578,8 +610,10 @@ jobs: 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - run: npm ci @@ -620,8 +654,10 @@ jobs: 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" # Cache node_modules @@ -660,8 +696,10 @@ jobs: 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" # Cache node_modules @@ -691,8 +729,10 @@ CI: - main - merge_requests script: + # 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - npm ci @@ -752,8 +792,10 @@ jobs: - script: npm install --prefix=$HOME/.local -g pnpm@8 displayName: Install PNPM + # 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - script: pnpm dlx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - script: pnpm install --frozen-lockfile @@ -782,8 +824,10 @@ pipelines: - npm install --prefix=$HOME/.local -g pnpm@8 + # 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - pnpm dlx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - pnpm install --frozen-lockfile @@ -797,8 +841,10 @@ pipelines: 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - pnpm dlx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - npm install --prefix=$HOME/.local -g pnpm@8 @@ -828,8 +874,10 @@ jobs: name: Install PNPM command: npm install --prefix=$HOME/.local -g pnpm@8 + # 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - run: pnpm dlx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - run: pnpm install --frozen-lockfile @@ -874,8 +922,10 @@ jobs: with: version: 8 + # 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - run: pnpm dlx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" # Cache node_modules @@ -918,8 +968,10 @@ jobs: with: version: 8 + # 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - run: pnpm dlx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" # Cache node_modules @@ -951,8 +1003,10 @@ CI: script: - npm install --prefix=$HOME/.local -g pnpm@8 + # 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested # - pnpm dlx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - pnpm install --frozen-lockfile @@ -1009,11 +1063,13 @@ jobs: 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 # Connect your workspace on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested - # - script: yarn nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" + # - script: yarn dlx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - - script: yarn install --frozen-lockfile + - script: yarn install --immutable - script: git branch --track main origin/main condition: eq(variables['Build.Reason'], 'PullRequest') @@ -1037,11 +1093,13 @@ pipelines: 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 # Connect your workspace on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested - # - yarn nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" + # - yarn dlx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - - yarn install --frozen-lockfile + - yarn install --immutable - yarn nx-cloud record -- nx format:check - yarn nx affected --base=origin/main -t lint test build @@ -1052,11 +1110,13 @@ pipelines: 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested - # - yarn nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" + # - yarn dlx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - - yarn install --frozen-lockfile + - yarn install --immutable # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud # - yarn nx-cloud record -- echo Hello World @@ -1077,11 +1137,13 @@ jobs: 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested - # - run: yarn nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" + # - run: yarn dlx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - - run: yarn install --frozen-lockfile + - run: yarn install --immutable - nx/set-shas: main-branch-name: 'main' @@ -1119,9 +1181,11 @@ jobs: 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested - # - run: yarn nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" + # - run: yarn dlx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" # Cache node_modules - uses: actions/setup-node@v3 @@ -1129,7 +1193,7 @@ jobs: node-version: 20 cache: 'yarn' - - run: yarn install --frozen-lockfile + - run: yarn install --immutable - uses: nrwl/nx-set-shas@v4 # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud @@ -1159,9 +1223,11 @@ jobs: 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested - # - run: yarn nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" + # - run: yarn dlx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" # Cache node_modules - uses: actions/setup-node@v3 @@ -1169,7 +1235,7 @@ jobs: node-version: 20 cache: 'yarn' - - run: yarn install --frozen-lockfile + - run: yarn install --immutable - uses: nrwl/nx-set-shas@v4 # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud @@ -1190,11 +1256,13 @@ CI: - main - merge_requests script: + # 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 on nx.app and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested - # - yarn nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" + # - yarn dlx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" - - yarn install --frozen-lockfile + - yarn install --immutable - NX_HEAD=$CI_COMMIT_SHA - NX_BASE=\${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA} diff --git a/packages/workspace/src/generators/ci-workflow/ci-workflow.ts b/packages/workspace/src/generators/ci-workflow/ci-workflow.ts index b8a1fb59abb63b..bc2c8c8d955c1e 100644 --- a/packages/workspace/src/generators/ci-workflow/ci-workflow.ts +++ b/packages/workspace/src/generators/ci-workflow/ci-workflow.ts @@ -11,7 +11,7 @@ import { } from '@nx/devkit'; import { deduceDefaultBase } from '../../utilities/default-base'; import { join } from 'path'; -import { getNxCloudUrl } from 'nx/src/utils/nx-cloud-utils'; +import { getNxCloudUrl, isNxCloudUsed } from 'nx/src/utils/nx-cloud-utils'; export interface Schema { name: string; @@ -42,6 +42,7 @@ interface Substitutes { nxCloudHost: string; hasE2E: boolean; tmpl: ''; + connectedToCloud: boolean; } function normalizeOptions(options: Schema, tree: Tree): Substitutes { @@ -70,6 +71,8 @@ function normalizeOptions(options: Schema, tree: Tree): Substitutes { const hasE2E = allDependencies['@nx/cypress'] || allDependencies['@nx/playwright']; + const connectedToCloud = isNxCloudUsed(readJson(tree, 'nx.json')); + return { workflowName, workflowFileName, @@ -81,6 +84,7 @@ function normalizeOptions(options: Schema, tree: Tree): Substitutes { hasE2E, nxCloudHost, tmpl: '', + connectedToCloud, }; } 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 1e6a205fe8f798..3fd6f4a980b808 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__ @@ -51,10 +51,14 @@ jobs: displayName: Install Bun <% } %> - # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested + + # 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 + <% if (connectedToCloud) { %># - script: <%= packageManagerPreInstallPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" + <% } else { %># Connect your workspace on nx.app and uncomment this to enable task distribution. # - script: <%= packageManagerPreInstallPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" - + <% } %> - script: <%= packageManagerInstall %> - script: git branch --track <%= mainBranch %> origin/<%= mainBranch %> condition: eq(variables['Build.Reason'], 'PullRequest') 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 bc6df793a4e579..d624aa0b280ef2 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__ @@ -19,10 +19,13 @@ pipelines: - npm install --prefix=$HOME/.local -g bun <% } %> - # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested + # 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 + <% if (connectedToCloud) { %> - <%= packageManagerPreInstallPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" + <% } else { %># Connect your workspace on nx.app and uncomment this to enable task distribution. # - <%= packageManagerPreInstallPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" - + <% } %> - <%= packageManagerInstall %> - <%= packageManagerPrefix %> nx-cloud record -- nx format:check @@ -35,10 +38,13 @@ pipelines: name: 'Build and test affected apps on "<%= mainBranch %>" branch changes' script: - export NX_BRANCH=$BITBUCKET_BRANCH - # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested + # 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 + <% if (connectedToCloud) { %> - <%= packageManagerPreInstallPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" + <% } else { %># Connect your workspace on nx.app and uncomment this to enable task distribution. # - <%= packageManagerPreInstallPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" - + <% } %> <% if(packageManager == 'pnpm'){ %> - npm install --prefix=$HOME/.local -g pnpm@8 <% } %> 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 8d99f60dfb1267..bf5585defe01d4 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__ @@ -21,10 +21,13 @@ jobs: <% } %> - # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested + # 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 + <% if (connectedToCloud) { %> - run: <%= packageManagerPreInstallPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" + <% } else { %># Connect your workspace on nx.app and uncomment this to enable task distribution. # - run: <%= packageManagerPreInstallPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" - + <% } %> - run: <%= packageManagerInstall %> - nx/set-shas: main-branch-name: '<%= mainBranch %>' 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 be73dff3c3901c..62577934814b01 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__ @@ -28,10 +28,13 @@ jobs: bun-version: latest <% } %> - # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested + # 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 + <% if (connectedToCloud) { %> - run: <%= packageManagerPreInstallPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" + <% } else { %># Connect your workspace on nx.app and uncomment this to enable task distribution. # - run: <%= packageManagerPreInstallPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" - + <% } %> <% if(packageManager != 'bun'){ %> # Cache node_modules - uses: actions/setup-node@v3 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 ebd364670cd0de..160a2901a8e3b6 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__ @@ -15,10 +15,13 @@ variables: <% if(packageManager == 'bun'){ %> - npm install --prefix=$HOME/.local -g bun <% } %> - # Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution. - # The "--stop-agents-after" is optional, but allows idle agents to shut down once the "<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" targets have been requested - # - <%= packageManagerPreInstallPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" - + # 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 + <% if (connectedToCloud) { %> - <%= packageManagerPreInstallPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" + <% } else { %># Connect your workspace on nx.app and uncomment this to enable task distribution. + # - <%= packageManagerPreInstallPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="<% if(hasE2E){ %>e2e-ci<% } else { %>build<% } %>" + <% } %> - <%= packageManagerInstall %> - NX_HEAD=$CI_COMMIT_SHA - NX_BASE=${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA}