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 acbb62e
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,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-jvm" --stop-agents-after="build"
- nx/set-shas:
Expand Down Expand Up @@ -56,8 +58,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-jvm" --stop-agents-after="build"
- name: Set up JDK 17 for x64
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 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 %>'

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 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"
<% } %>

- name: Set up JDK 17 for x64
uses: actions/setup-java@v4
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 acbb62e

Please sign in to comment.