Skip to content

Commit

Permalink
fix(core): improve generated workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Apr 21, 2022
1 parent 3dc818f commit ab4d4a0
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 102 deletions.
2 changes: 1 addition & 1 deletion docs/generated/packages/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@
"type": "string",
"description": "Workflow name.",
"$default": { "$source": "argv", "index": 0 },
"default": "build",
"default": "CI",
"x-prompt": "How should we name your workflow?",
"pattern": "^[a-zA-Z].*$"
}
Expand Down
58 changes: 23 additions & 35 deletions docs/shared/monorepo-ci-azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,15 @@ pr:
- main

variables:
- name: NX_BRANCH
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
value: $(System.PullRequest.PullRequestNumber)
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
value: $(Build.SourceBranchName)
- name: TARGET_BRANCH
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
value: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')]
- name: BASE_SHA
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
value: $(git merge-base $(TARGET_BRANCH) HEAD)
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
value: $(git rev-parse HEAD~1)
- name: HEAD_SHA
value: $(git rev-parse HEAD)
CI: 'true'
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
NX_BRANCH: $(System.PullRequest.PullRequestNumber)
TARGET_BRANCH: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')]
BASE_SHA: $(git merge-base $(TARGET_BRANCH) HEAD)
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
NX_BRANCH: $(Build.SourceBranchName)
BASE_SHA: $(git rev-parse HEAD~1)
HEAD_SHA: $(git rev-parse HEAD)

jobs:
- job: main
Expand Down Expand Up @@ -75,44 +69,38 @@ pr:
- main
variables:
- name: NX_CLOUD_DISTRIBUTED_EXECUTION
value: 'true'
- name: NX_BRANCH
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
value: $(System.PullRequest.PullRequestNumber)
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
value: $(Build.SourceBranchName)
- name: TARGET_BRANCH
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
value: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')]
- name: BASE_SHA
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
value: $(git merge-base $(TARGET_BRANCH) HEAD)
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
value: $(git rev-parse HEAD~1)
- name: HEAD_SHA
value: $(git rev-parse HEAD)
CI: 'true'
NX_CLOUD_DISTRIBUTED_EXECUTION: 'true'
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
NX_BRANCH: $(System.PullRequest.PullRequestNumber)
TARGET_BRANCH: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')]
BASE_SHA: $(git merge-base $(TARGET_BRANCH) HEAD)
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
NX_BRANCH: $(Build.SourceBranchName)
BASE_SHA: $(git rev-parse HEAD~1)
HEAD_SHA: $(git rev-parse HEAD)
jobs:
- job: agents
strategy:
parallel: 3
displayName: 'Agent $(imageName)'
displayName: Nx Cloud Agent
pool:
vmImage: 'ubuntu-latest'
steps:
- script: npm ci
- script: npx nx-cloud start-agent
- job: main
displayName: Nx Cloud Main
pool:
vmImage: 'ubuntu-latest'
steps:
- script: npm ci
- script: npx nx-cloud start-ci-run
- script: npx nx workspace-lint
- script: npx nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
- script: npx nx-cloud record -- npx nx workspace-lint
- script: npx nx-cloud record -- npx nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
- script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=lint --parallel=3
- script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=test --parallel=3 --ci --code-coverage
- script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=build --parallel=3
Expand Down
4 changes: 2 additions & 2 deletions docs/shared/monorepo-ci-circle-ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ jobs:
- nx/set-shas
- run: npx nx-cloud start-ci-run
- run: npx nx workspace-lint
- run: npx nx format:check
- run: npx nx-cloud record -- npx nx workspace-lint
- run: npx nx-cloud record -- npx nx format:check
- run: npx nx affected --base=$NX_BASE --head=$NX_HEAD --target=lint --parallel=3
- run: npx nx affected --base=$NX_BASE --head=$NX_HEAD --target=test --parallel=3 --ci --code-coverage
- run: npx nx affected --base=$NX_BASE --head=$NX_HEAD --target=build --parallel=3
Expand Down
4 changes: 2 additions & 2 deletions docs/shared/monorepo-ci-github-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ jobs:
uses: nrwl/ci/.github/workflows/[email protected]
with:
parallel-commands: |
npx nx workspace-lint
npx nx format:check
npx nx-cloud record -- npx nx workspace-lint
npx nx-cloud record -- npx nx format:check
parallel-commands-on-agents: |
npx nx affected --target=lint --parallel=3
npx nx affected --target=test --parallel=3 --ci --code-coverage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,50 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`lib should generate azure CI config 1`] = `
"name: build
"name: CI
trigger:
- main
pr:
- main
variables:
- name: NX_CLOUD_DISTRIBUTED_EXECUTION
value: 'true'
- name: NX_BRANCH
\${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
value: $(System.PullRequest.PullRequestNumber)
\${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
value: $(Build.SourceBranchName)
- name: TARGET_BRANCH
\${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
value: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')]
- name: BASE_SHA
\${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
value: $(git merge-base $(TARGET_BRANCH) HEAD)
\${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
value: $(git rev-parse HEAD~1)
- name: HEAD_SHA
value: $(git rev-parse HEAD)
CI: 'true'
NX_CLOUD_DISTRIBUTED_EXECUTION: 'true'
\${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
NX_BRANCH: $(System.PullRequest.PullRequestNumber)
TARGET_BRANCH: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')]
BASE_SHA: $(git merge-base $(TARGET_BRANCH) HEAD)
\${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
NX_BRANCH: $(Build.SourceBranchName)
BASE_SHA: $(git rev-parse HEAD~1)
HEAD_SHA: $(git rev-parse HEAD)
jobs:
- job: agents
strategy:
parallel: 3
displayName: 'Nx Cloud Agent'
displayName: Nx Cloud Agent
pool:
vmImage: 'ubuntu-latest'
steps:
- script: yarn --frozen-lockfile
displayName: NPM Install Dependencies
- script: npx nx-cloud start-agent
displayName: 'Start Nx-Cloud agent
displayName: Start Nx-Cloud agent
- job: main
displayName: 'Nx Cloud Main'
displayName: Nx Cloud Main
pool:
vmImage: 'ubuntu-latest'
steps:
- script: yarn --frozen-lockfile
displayName: NPM Install Dependencies
- script: yarn nx-cloud start-ci-run
displayName: Start CI run
- script: yarn nx workspace-lint
- script: yarn nx-cloud record -- yarn nx workspace-lint
displayName: Run workspace lint
- script: yarn nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
- script: yarn nx-cloud record -- yarn nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
displayName: Check format
- script: yarn nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=lint --parallel=3
displayName: Run lint
Expand Down Expand Up @@ -104,10 +97,10 @@ jobs:
command: yarn nx-cloud start-ci-run
- run:
name: Run workspace lint
command: yarn nx workspace-lint
command: yarn nx-cloud record -- yarn nx workspace-lint
- run:
name: Check format
command: yarn nx format:check --base=$NX_BASE --head=$NX_HEAD
command: yarn nx-cloud record -- yarn nx format:check --base=$NX_BASE --head=$NX_HEAD
- run:
name: Run lint
command: yarn nx affected --base=$NX_BASE --head=$NX_HEAD --target=lint --parallel=3
Expand All @@ -125,20 +118,20 @@ jobs:
workflows:
version: 2
build:
ci:
jobs:
- agent:
name: Nx Cloud Agent << matrix.ordinal >>
matrix:
parameters:
ordinal: [1, 2, 3]
- main
- main:
name: Nx Cloud Main
"
`;
exports[`lib should generate github CI config 1`] = `
"name: build
"name: CI
on:
push:
Expand All @@ -152,8 +145,8 @@ jobs:
uses: nrwl/ci/.github/workflows/[email protected]
with:
parallel-commands: |
yarn nx workspace-lint
yarn nx format:check
yarn nx-cloud record -- yarn nx workspace-lint
yarn nx-cloud record -- yarn nx format:check
parallel-commands-on-agents: |
yarn nx affected --target=lint --parallel=3
yarn nx affected --target=test --parallel=3 --ci --code-coverage
Expand Down Expand Up @@ -182,8 +175,8 @@ jobs:
uses: nrwl/ci/.github/workflows/[email protected]
with:
parallel-commands: |
yarn nx workspace-lint
yarn nx format:check
yarn nx-cloud record -- yarn nx workspace-lint
yarn nx-cloud record -- yarn nx format:check
parallel-commands-on-agents: |
yarn nx affected --target=lint --parallel=3
yarn nx affected --target=test --parallel=3 --ci --code-coverage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('lib', () => {
setNxCloud(tree);
await ciWorkflowGenerator(tree, { ci: 'github' });

expect(tree.read('.github/workflows/build.yml', 'utf-8')).toMatchSnapshot();
expect(tree.read('.github/workflows/ci.yml', 'utf-8')).toMatchSnapshot();
});

it('should generate circleci CI config', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface Substitutes {

function normalizeOptions(options: Schema): Substitutes {
const { name: workflowName, fileName: workflowFileName } = names(
options.name || 'build'
options.name || 'CI'
);
const { exec: packageManagerPrefix, ciInstall: packageManagerInstall } =
getPackageManagerCommand();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,22 @@ pr:
- <%= mainBranch %>

variables:
- name: NX_CLOUD_DISTRIBUTED_EXECUTION
value: 'true'
- name: NX_BRANCH
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
value: $(System.PullRequest.PullRequestNumber)
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
value: $(Build.SourceBranchName)
- name: TARGET_BRANCH
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
value: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')]
- name: BASE_SHA
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
value: $(git merge-base $(TARGET_BRANCH) HEAD)
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
value: $(git rev-parse HEAD~1)
- name: HEAD_SHA
value: $(git rev-parse HEAD)
CI: 'true'
NX_CLOUD_DISTRIBUTED_EXECUTION: 'true'
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
NX_BRANCH: $(System.PullRequest.PullRequestNumber)
TARGET_BRANCH: $[replace(variables['System.PullRequest.TargetBranch'],'refs/heads/','origin/')]
BASE_SHA: $(git merge-base $(TARGET_BRANCH) HEAD)
${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
NX_BRANCH: $(Build.SourceBranchName)
BASE_SHA: $(git rev-parse HEAD~1)
HEAD_SHA: $(git rev-parse HEAD)

jobs:
- job: agents
strategy:
parallel: 3
displayName: 'Nx Cloud Agent'
displayName: Nx Cloud Agent
pool:
vmImage: 'ubuntu-latest'
steps:
Expand All @@ -38,10 +31,10 @@ jobs:
<% } %>- script: <%= packageManagerInstall %>
displayName: NPM Install Dependencies
- script: npx nx-cloud start-agent
displayName: 'Start Nx-Cloud agent
displayName: Start Nx-Cloud agent

- job: main
displayName: 'Nx Cloud Main'
displayName: Nx Cloud Main
pool:
vmImage: 'ubuntu-latest'
steps:
Expand All @@ -52,9 +45,9 @@ jobs:
displayName: NPM Install Dependencies
- script: <%= packageManagerPrefix %> nx-cloud start-ci-run
displayName: Start CI run
- script: <%= packageManagerPrefix %> nx workspace-lint
- script: <%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx workspace-lint
displayName: Run workspace lint
- script: <%= packageManagerPrefix %> nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
- script: <%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
displayName: Check format
- script: <%= packageManagerPrefix %> nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) --target=lint --parallel=3
displayName: Run lint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ jobs:
command: <%= packageManagerPrefix %> nx-cloud start-ci-run
- run:
name: Run workspace lint
command: <%= packageManagerPrefix %> nx workspace-lint
command: <%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx workspace-lint
- run:
name: Check format
command: <%= packageManagerPrefix %> nx format:check --base=$NX_BASE --head=$NX_HEAD
command: <%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx format:check --base=$NX_BASE --head=$NX_HEAD
- run:
name: Run lint
command: <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD --target=lint --parallel=3
Expand All @@ -72,5 +72,5 @@ workflows:
matrix:
parameters:
ordinal: [1, 2, 3]
- main
- main:
name: Nx Cloud Main
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
uses: nrwl/ci/.github/workflows/[email protected]
with:
parallel-commands: |
<%= packageManagerPrefix %> nx workspace-lint
<%= packageManagerPrefix %> nx format:check
<%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx workspace-lint
<%= packageManagerPrefix %> nx-cloud record -- <%= packageManagerPrefix %> nx format:check
parallel-commands-on-agents: |
<%= packageManagerPrefix %> nx affected --target=lint --parallel=3
<%= packageManagerPrefix %> nx affected --target=test --parallel=3 --ci --code-coverage
Expand Down
2 changes: 1 addition & 1 deletion packages/workspace/src/generators/ci-workflow/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"$source": "argv",
"index": 0
},
"default": "build",
"default": "CI",
"x-prompt": "How should we name your workflow?",
"pattern": "^[a-zA-Z].*$"
}
Expand Down

0 comments on commit ab4d4a0

Please sign in to comment.