Skip to content

Commit

Permalink
feat(gradle): uncomment start-ci-run
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Jul 9, 2024
1 parent 8fd38cb commit db934e0
Show file tree
Hide file tree
Showing 14 changed files with 212 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ jobs:
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
# - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="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
- run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build"
- nx/set-shas:
main-branch-name: 'main'
Expand Down Expand Up @@ -56,9 +57,10 @@ 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
# - run: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="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
- 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 by running "nx connect" and uncomment this
# - run: <%= packageManagerPrefix %> nx-cloud start-ci-run --distribute-on="5 linux-medium-jvm" --stop-agents-after="build"

<% } %>
- nx/set-shas:
main-branch-name: '<%= mainBranch %>'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ jobs:
with:
fetch-depth: 0

# 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 by running "nx connect" and uncomment this
# - 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
Expand Down
5 changes: 4 additions & 1 deletion packages/gradle/src/generators/ci-workflow/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree } from '@nx/devkit';
import { readNxJson, Tree, updateNxJson } from '@nx/devkit';

import { ciWorkflowGenerator } from './generator';

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

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
const nxJson = readNxJson(tree);
nxJson.nxCloudAccessToken = 'test';
updateNxJson(tree, nxJson);
});

describe.each([
Expand Down
8 changes: 5 additions & 3 deletions packages/gradle/src/generators/ci-workflow/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import {
names,
generateFiles,
getPackageManagerCommand,
NxJsonConfiguration,
formatFiles,
detectPackageManager,
readNxJson,
readJson,
} from '@nx/devkit';
import { join } from 'path';
import { getNxCloudUrl, isNxCloudUsed } from 'nx/src/utils/nx-cloud-utils';
Expand Down Expand Up @@ -47,6 +45,7 @@ interface Substitutes {
packageManagerPrefix: string;
commands: string[];
nxCloudHost: string;
connectedToCloud: boolean;
}

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

let nxCloudHost: string = 'nx.app';
try {
const nxCloudUrl = getNxCloudUrl(readJson(tree, 'nx.json'));
const nxCloudUrl = getNxCloudUrl(readNxJson(tree));
nxCloudHost = new URL(nxCloudUrl).host;
} catch {}

const mainBranch = deduceDefaultBase();

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

const connectedToCloud = isNxCloudUsed(readNxJson(tree));

return {
workflowName,
workflowFileName,
Expand All @@ -75,6 +76,7 @@ function getTemplateData(tree: Tree, options: Schema): Substitutes {
commands,
mainBranch,
nxCloudHost,
connectedToCloud,
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/utils/nx-cloud-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NxJsonConfiguration, readNxJson } from '../config/nx-json';
import { NxJsonConfiguration } from '../config/nx-json';

export function isNxCloudUsed(nxJson: NxJsonConfiguration): boolean {
return (
Expand Down
Loading

0 comments on commit db934e0

Please sign in to comment.