Skip to content

Commit c5b9b80

Browse files
committed
chore: setup migrate pipeline
1 parent ab31e2f commit c5b9b80

File tree

5 files changed

+167
-4
lines changed

5 files changed

+167
-4
lines changed

.github/renovate.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"extends": [
3+
"config:recommended",
4+
":semanticCommits",
5+
":semanticCommitScopeDisabled"
6+
],
7+
// Wait 3 days.
8+
// https://docs.npmjs.com/policies/unpublish/#packages-published-less-than-72-hours-ago
9+
"minimumReleaseAge": "3 days",
10+
"packageRules": [
11+
// Allow nx to manage dependencies
12+
{
13+
"matchPackageNames": ["*"],
14+
"enabled": false
15+
},
16+
{
17+
"matchPackageNames": ["@nx/workspace"],
18+
"enabled": true,
19+
"semanticCommitType": "chore"
20+
}
21+
],
22+
"rebaseWhen": "conflicted"
23+
}

.github/workflows/nx-migrate.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# This workflow is used to augment the capabilities of the renovate GitHub app by running a full
2+
# `nx migrate` when renovate opens a PR to change the version of @nx/workspace in package.json.
3+
#
4+
# You will therefore also notice that in the renovate configuration, we ignore any packages which
5+
# Nx will manage for us as part of `nx migrate` such as the remaining @nx/* packages.
6+
7+
name: Nx Migrate
8+
9+
on:
10+
# NOTE: Never use pull_request_target here because that would populate secrets for forks
11+
# Renovate creates branches directly on the main repo and acts like a trusted contributor
12+
pull_request:
13+
branches: [main]
14+
paths:
15+
- 'package.json'
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
19+
cancel-in-progress: true
20+
21+
# Minimal permissions by default
22+
permissions:
23+
contents: read
24+
25+
jobs:
26+
maybe_nx_migrate:
27+
# Only run if it was the renovate bot that triggered the workflow (otherwise we'll create a loop)
28+
if: contains('["renovate[bot]"]', github.actor) == true
29+
name: Run nx migrate if required
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v5
33+
with:
34+
# To allow us to perform the git diff we need the git history
35+
fetch-depth: 0
36+
# To ensure we can push from a different user (and therefore cause actions to rerun)
37+
persist-credentials: false
38+
39+
- name: Check if @nx/workspace was changed as part of the latest commit on the PR
40+
id: nx-workspace-package-check
41+
run: |
42+
git diff HEAD~1 -G"@nx/workspace" --exit-code package.json && echo "@nx/workspace unchanged" || echo "::set-output name=was-changed::true"
43+
44+
- uses: pnpm/action-setup@v4
45+
if: ${{ steps.nx-workspace-package-check.outputs.was-changed == 'true' }}
46+
name: Install pnpm
47+
with:
48+
run_install: false
49+
50+
- name: Install Node.js per package.json
51+
if: ${{ steps.nx-workspace-package-check.outputs.was-changed == 'true' }}
52+
uses: actions/setup-node@v5
53+
with:
54+
# Use the volta.node property as the source of truth
55+
node-version-file: 'package.json'
56+
cache: 'pnpm'
57+
58+
- name: Run nx migrate if @nx/workspace changed and commit the results
59+
if: ${{ steps.nx-workspace-package-check.outputs.was-changed == 'true' }}
60+
env:
61+
# We cannot use secrets.GITHUB_TOKEN for this because it is not permitted to kick off subsequent actions worfklow runs, so we use a fine grained PAT instead
62+
GITHUB_TOKEN: ${{ secrets.GH_FINE_GRAINED_PAT }}
63+
# We don't want to run any of our postinstall logic when Nx is invoking install behind the scenes
64+
SKIP_POSTINSTALL: 'true'
65+
run: |
66+
# Checkout the PR branch using the github CLI
67+
gh pr checkout ${{ github.event.pull_request.number }}
68+
69+
# Get the version of Nx we are migrating to
70+
NX_VERSION=$(node -e "console.log(require('./package.json').devDependencies['@nx/workspace'])")
71+
72+
# Revert renovate's changes to package.json and pnpm-lock.yaml so that it is a clean migrate from the status quo
73+
git checkout HEAD~1 -- package.json pnpm-lock.yaml
74+
75+
# We need to expect lock file changes to be applicable
76+
pnpm install --ignore-scripts --frozen-lockfile=false
77+
78+
pnpm nx migrate $NX_VERSION
79+
80+
# Sometimes Nx can require config formatting changes after a migrate command
81+
# We need to expect lock file changes to be applicable
82+
pnpm install --ignore-scripts --frozen-lockfile=false
83+
pnpm nx format
84+
85+
# migrations.json may or may not exist after running nx migrate
86+
if [ -f migrations.json ]; then
87+
pnpm nx migrate --run-migrations=migrations.json
88+
89+
# After we have run its migrations, we no longer need the migrations.json file
90+
rm migrations.json
91+
fi
92+
93+
# Ensure all the changed files are formatted appropriately
94+
pnpm format
95+
96+
# Commit all the changes to the PR (see note on not being able to use secrets.GITHUB_TOKEN for this)
97+
git config --global user.email "[email protected]"
98+
git config --global user.name "Coly010"
99+
git remote set-url origin https://x-access-token:[email protected]/$GITHUB_REPOSITORY.git
100+
101+
git add --all
102+
git commit -m "chore: run nx migrate for nx v$NX_VERSION"
103+
git push

.github/workflows/pr.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Verify PR
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
main:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
filter: tree:0
19+
fetch-depth: 0
20+
21+
- uses: pnpm/action-setup@v4
22+
name: Install pnpm
23+
with:
24+
run_install: false
25+
26+
- name: Install Node.js per package.json
27+
uses: actions/setup-node@v5
28+
with:
29+
cache: 'pnpm'
30+
31+
- run: pnpm install
32+
- run: npx playwright install --with-deps
33+
34+
# Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
35+
# - run: npx nx-cloud record -- echo Hello World
36+
# When you enable task distribution, run the e2e-ci task instead of e2e
37+
- run: pnpm nx run-many -t lint test build typecheck e2e

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"license": "MIT",
55
"scripts": {},
66
"private": true,
7+
"packageManager": "[email protected]",
78
"dependencies": {
89
"express": "^4.21.2",
910
"react": "19.0.0",

pnpm-lock.yaml

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)