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 81fe132 commit 3d88cc7
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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:
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 @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/gradle/src/generators/ci-workflow/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface Substitutes {
packageManagerPrefix: string;
commands: string[];
nxCloudHost: string;
connectedTocloud: boolean;
}

function getTemplateData(tree: Tree, options: Schema): Substitutes {
Expand All @@ -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,
Expand All @@ -75,6 +78,7 @@ function getTemplateData(tree: Tree, options: Schema): Substitutes {
commands,
mainBranch,
nxCloudHost,
connectedTocloud,
};
}

Expand Down

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion packages/workspace/src/generators/ci-workflow/ci-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,6 +42,7 @@ interface Substitutes {
nxCloudHost: string;
hasE2E: boolean;
tmpl: '';
connectedToCloud: boolean;
}

function normalizeOptions(options: Schema, tree: Tree): Substitutes {
Expand Down Expand Up @@ -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,
Expand All @@ -81,6 +84,7 @@ function normalizeOptions(options: Schema, tree: Tree): Substitutes {
hasE2E,
nxCloudHost,
tmpl: '',
connectedToCloud,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
<% } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 3d88cc7

Please sign in to comment.