Skip to content

Commit 2b7b523

Browse files
authored
feat(core): uncomment start-ci-run (#26645)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
1 parent 8fd38cb commit 2b7b523

File tree

14 files changed

+212
-137
lines changed

14 files changed

+212
-137
lines changed

packages/gradle/src/generators/ci-workflow/__snapshots__/generator.spec.ts.snap

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ jobs:
1717
steps:
1818
- checkout
1919
20-
# Connect your workspace on nx.app and uncomment this to enable task distribution.
21-
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested
22-
# - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build"
20+
# This enables task distribution via Nx Cloud
21+
# Run this command as early as possible, before dependencies are installed
22+
# Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun
23+
- run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build"
2324
2425
- nx/set-shas:
2526
main-branch-name: 'main'
@@ -56,9 +57,10 @@ jobs:
5657
with:
5758
fetch-depth: 0
5859
59-
# Connect your workspace on nx.app and uncomment this to enable task distribution.
60-
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested
61-
# - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build"
60+
# This enables task distribution via Nx Cloud
61+
# Run this command as early as possible, before dependencies are installed
62+
# Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun
63+
- run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build"
6264
6365
- name: Set up JDK 17 for x64
6466
uses: actions/setup-java@v4

packages/gradle/src/generators/ci-workflow/files/circleci/.circleci/config.yml.template

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ jobs:
1414
steps:
1515
- checkout
1616

17-
# Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution.
18-
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested
17+
# This enables task distribution via Nx Cloud
18+
# Run this command as early as possible, before dependencies are installed
19+
# Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun
20+
<% if (connectedToCloud) { %>- run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build"
21+
<% } else { %># Connect your workspace by running "nx connect" and uncomment this
1922
# - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build"
20-
23+
<% } %>
2124
- nx/set-shas:
2225
main-branch-name: '<%= mainBranch %>'
2326

packages/gradle/src/generators/ci-workflow/files/github/.github/workflows/__workflowFileName__.yml.template

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ jobs:
1818
with:
1919
fetch-depth: 0
2020

21-
# Connect your workspace on <%= nxCloudHost %> and uncomment this to enable task distribution.
22-
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "build" targets have been requested
21+
# This enables task distribution via Nx Cloud
22+
# Run this command as early as possible, before dependencies are installed
23+
# Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun
24+
<% if (connectedToCloud) { %>- run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build"
25+
<% } else { %># Connect your workspace by running "nx connect" and uncomment this
2326
# - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build"
27+
<% } %>
2428

2529
- name: Set up JDK 17 for x64
2630
uses: actions/setup-java@v4

packages/gradle/src/generators/ci-workflow/generator.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
2-
import { Tree } from '@nx/devkit';
2+
import { readNxJson, Tree, updateNxJson } from '@nx/devkit';
33

44
import { ciWorkflowGenerator } from './generator';
55

@@ -8,6 +8,9 @@ describe('ci-workflow generator', () => {
88

99
beforeEach(() => {
1010
tree = createTreeWithEmptyWorkspace();
11+
const nxJson = readNxJson(tree);
12+
nxJson.nxCloudAccessToken = 'test';
13+
updateNxJson(tree, nxJson);
1114
});
1215

1316
describe.each([

packages/gradle/src/generators/ci-workflow/generator.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ import {
33
names,
44
generateFiles,
55
getPackageManagerCommand,
6-
NxJsonConfiguration,
76
formatFiles,
87
detectPackageManager,
98
readNxJson,
10-
readJson,
119
} from '@nx/devkit';
1210
import { join } from 'path';
1311
import { getNxCloudUrl, isNxCloudUsed } from 'nx/src/utils/nx-cloud-utils';
@@ -47,6 +45,7 @@ interface Substitutes {
4745
packageManagerPrefix: string;
4846
commands: string[];
4947
nxCloudHost: string;
48+
connectedToCloud: boolean;
5049
}
5150

5251
function getTemplateData(tree: Tree, options: Schema): Substitutes {
@@ -59,14 +58,16 @@ function getTemplateData(tree: Tree, options: Schema): Substitutes {
5958

6059
let nxCloudHost: string = 'nx.app';
6160
try {
62-
const nxCloudUrl = getNxCloudUrl(readJson(tree, 'nx.json'));
61+
const nxCloudUrl = getNxCloudUrl(readNxJson(tree));
6362
nxCloudHost = new URL(nxCloudUrl).host;
6463
} catch {}
6564

6665
const mainBranch = deduceDefaultBase();
6766

6867
const commands = options.commands ?? getCiCommands(options.ci, mainBranch);
6968

69+
const connectedToCloud = isNxCloudUsed(readNxJson(tree));
70+
7071
return {
7172
workflowName,
7273
workflowFileName,
@@ -75,6 +76,7 @@ function getTemplateData(tree: Tree, options: Schema): Substitutes {
7576
commands,
7677
mainBranch,
7778
nxCloudHost,
79+
connectedToCloud,
7880
};
7981
}
8082

packages/nx/src/utils/nx-cloud-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NxJsonConfiguration, readNxJson } from '../config/nx-json';
1+
import { NxJsonConfiguration } from '../config/nx-json';
22

33
export function isNxCloudUsed(nxJson: NxJsonConfiguration): boolean {
44
return (

0 commit comments

Comments
 (0)