Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): fix optional branch tracking on ci pipeline #22652

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/nx-cloud/tutorial/github-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ jobs:
- uses: nrwl/nx-set-shas@v3
# This line is needed for nx affected to work when CI is running on a PR
- run: git branch --track main origin/main
if: ${{ github.event_name == 'pull_request' }}

- run: pnpm nx affected -t lint test build --parallel=3
- run: pnpm nx affected -t e2e --parallel=1
```
Expand Down Expand Up @@ -463,6 +465,7 @@ jobs:
- uses: nrwl/nx-set-shas@v3
# This line is needed for nx affected to work when CI is running on a PR
- run: git branch --track main origin/main
if: ${{ github.event_name == 'pull_request' }}
- run: pnpm nx affected -t lint test build --parallel=3
- run: pnpm nx affected -t e2e-ci --parallel=1
- run: pnpm nx affected -t deploy --no-agents
Expand Down
6 changes: 4 additions & 2 deletions docs/shared/monorepo-ci-azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ jobs:
echo "##vso[task.setvariable variable=BASE_SHA]$LAST_SHA"
fi
# Required for nx affected if we're on a branch
- script: git branch --track main origin/main
# This line enables distribution
# The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested
# - script: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci"
- script: npm ci

# Required for nx affected if we're on a branch
- script: git branch --track main origin/main
condition: eq(variables['Build.Reason'], 'PullRequest')

- script: npx nx-cloud record -- nx format:check --base=$(BASE_SHA)
- script: npx nx affected --base=$(BASE_SHA) -t lint test build e2e-ci
```
Expand Down
2 changes: 2 additions & 0 deletions docs/shared/monorepo-ci-github-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ jobs:
- run: npm ci

- uses: nrwl/nx-set-shas@v3

# This line is needed for nx affected to work when CI is running on a PR
- run: git branch --track main origin/main
if: ${{ github.event_name == 'pull_request' }}

- run: npx nx-cloud record -- nx format:check
- run: npx nx affected -t lint test build e2e-ci
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
# - script: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="e2e-ci"

- script: npm ci
- script: git branch --track main origin/main
condition: eq(variables['Build.Reason'], 'PullRequest')

- script: npx nx-cloud record -- nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
- script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t lint test build e2e-ci
Expand Down Expand Up @@ -115,6 +117,10 @@ jobs:
- nx/set-shas:
main-branch-name: 'main'

# Required for nx affected if we're on a branch
- run: git branch --track main origin/main
condition: eq(variables['Build.Reason'], 'PullRequest')

- run: npx nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD
- run: npx nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build e2e-ci

Expand Down Expand Up @@ -160,6 +166,9 @@ jobs:
- run: npm ci
- uses: nrwl/nx-set-shas@v4

- run: git branch --track main origin/main
if: \${{ github.event_name == 'pull_request' }}

- run: npx nx-cloud record -- nx format:check
- run: npx nx affected -t lint test build e2e-ci
"
Expand Down Expand Up @@ -198,6 +207,9 @@ jobs:
- run: npm ci
- uses: nrwl/nx-set-shas@v4

- run: git branch --track main origin/main
if: \${{ github.event_name == 'pull_request' }}

- run: npx nx-cloud record -- nx format:check
- run: npx nx affected -t lint test build e2e-ci
"
Expand Down Expand Up @@ -252,6 +264,8 @@ jobs:
# - script: npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build"

- script: npm ci
- script: git branch --track main origin/main
condition: eq(variables['Build.Reason'], 'PullRequest')

- script: npx nx-cloud record -- nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
- script: npx nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t lint test build
Expand Down Expand Up @@ -318,6 +332,10 @@ jobs:
- nx/set-shas:
main-branch-name: 'main'

# Required for nx affected if we're on a branch
- run: git branch --track main origin/main
condition: eq(variables['Build.Reason'], 'PullRequest')

- run: npx nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD
- run: npx nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build

Expand Down Expand Up @@ -363,6 +381,9 @@ jobs:
- run: npm ci
- uses: nrwl/nx-set-shas@v4

- run: git branch --track main origin/main
if: \${{ github.event_name == 'pull_request' }}

- run: npx nx-cloud record -- nx format:check
- run: npx nx affected -t lint test build
"
Expand Down Expand Up @@ -401,6 +422,9 @@ jobs:
- run: npm ci
- uses: nrwl/nx-set-shas@v4

- run: git branch --track main origin/main
if: \${{ github.event_name == 'pull_request' }}

- run: npx nx-cloud record -- nx format:check
- run: npx nx affected -t lint test build
"
Expand Down Expand Up @@ -484,6 +508,8 @@ jobs:
- script: npm install --prefix=$HOME/.local -g pnpm@8
displayName: Install PNPM
- script: pnpm install --frozen-lockfile
- script: git branch --track main origin/main
condition: eq(variables['Build.Reason'], 'PullRequest')

- script: pnpm exec nx-cloud record -- nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
- script: pnpm exec nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t lint test build
Expand Down Expand Up @@ -557,6 +583,10 @@ jobs:
- nx/set-shas:
main-branch-name: 'main'

# Required for nx affected if we're on a branch
- run: git branch --track main origin/main
condition: eq(variables['Build.Reason'], 'PullRequest')

- run: pnpm exec nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD
- run: pnpm exec nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build

Expand Down Expand Up @@ -605,6 +635,9 @@ jobs:
- run: pnpm install --frozen-lockfile
- uses: nrwl/nx-set-shas@v4

- run: git branch --track main origin/main
if: \${{ github.event_name == 'pull_request' }}

- run: pnpm exec nx-cloud record -- nx format:check
- run: pnpm exec nx affected -t lint test build
"
Expand Down Expand Up @@ -646,6 +679,9 @@ jobs:
- run: pnpm install --frozen-lockfile
- uses: nrwl/nx-set-shas@v4

- run: git branch --track main origin/main
if: \${{ github.event_name == 'pull_request' }}

- run: pnpm exec nx-cloud record -- nx format:check
- run: pnpm exec nx affected -t lint test build
"
Expand Down Expand Up @@ -729,6 +765,8 @@ jobs:
# - script: yarn nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build"

- script: yarn install --frozen-lockfile
- script: git branch --track main origin/main
condition: eq(variables['Build.Reason'], 'PullRequest')

- script: yarn nx-cloud record -- nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
- script: yarn nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t lint test build
Expand Down Expand Up @@ -795,6 +833,10 @@ jobs:
- nx/set-shas:
main-branch-name: 'main'

# Required for nx affected if we're on a branch
- run: git branch --track main origin/main
condition: eq(variables['Build.Reason'], 'PullRequest')

- run: yarn nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD
- run: yarn nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build

Expand Down Expand Up @@ -840,6 +882,9 @@ jobs:
- run: yarn install --frozen-lockfile
- uses: nrwl/nx-set-shas@v4

- run: git branch --track main origin/main
if: \${{ github.event_name == 'pull_request' }}

- run: yarn nx-cloud record -- nx format:check
- run: yarn nx affected -t lint test build
"
Expand Down Expand Up @@ -878,6 +923,9 @@ jobs:
- run: yarn install --frozen-lockfile
- uses: nrwl/nx-set-shas@v4

- run: git branch --track main origin/main
if: \${{ github.event_name == 'pull_request' }}

- run: yarn nx-cloud record -- nx format:check
- run: yarn nx affected -t lint test build
"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
- script: npm install --prefix=$HOME/.local -g pnpm@8
displayName: Install PNPM
<% } %>- script: <%= packageManagerInstall %>
- script: git branch --track main origin/main
condition: eq(variables['Build.Reason'], 'PullRequest')

- script: <%= packageManagerPrefix %> nx-cloud record -- nx format:check --base=$(BASE_SHA) --head=$(HEAD_SHA)
- script: <%= packageManagerPrefix %> nx affected --base=$(BASE_SHA) --head=$(HEAD_SHA) -t lint test build<% if(hasE2E){ %> e2e-ci<% } %>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jobs:
- nx/set-shas:
main-branch-name: '<%= mainBranch %>'

# Required for nx affected if we're on a branch
- run: git branch --track main origin/main
condition: eq(variables['Build.Reason'], 'PullRequest')

- run: <%= packageManagerPrefix %> nx-cloud record -- nx format:check --base=$NX_BASE --head=$NX_HEAD
- run: <%= packageManagerPrefix %> nx affected --base=$NX_BASE --head=$NX_HEAD -t lint test build<% if(hasE2E){ %> e2e-ci<% } %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ jobs:
- run: <%= packageManagerInstall %>
- uses: nrwl/nx-set-shas@v4

- run: git branch --track main origin/main
if: ${{ github.event_name == 'pull_request' }}

- run: <%= packageManagerPrefix %> nx-cloud record -- nx format:check
- run: <%= packageManagerPrefix %> nx affected -t lint test build<% if(hasE2E){ %> e2e-ci<% } %>