Skip to content

Commit 156c5c9

Browse files
authored
chore: Migrate to Yarn 4, use JS constraints (#156)
Migrates from Yarn 3 to 4 and replaces `constraints.pro` with JavaScript constraints via `yarn.config.cjs`. Migrating to Yarn 4 required a change to the Node / Yarn install flow in CI, which we solve by simply copypasting the workflows from the module template as of https://github.com/MetaMask/metamask-module-template/tree/570f6c2b80cb14fd61d5325131337401ae65c159.
1 parent 39b34e2 commit 156c5c9

11 files changed

Lines changed: 2657 additions & 3194 deletions

File tree

.github/workflows/build-lint-test.yml

Lines changed: 69 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,47 @@ jobs:
77
prepare:
88
name: Prepare
99
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
node-version: [18.x, 20.x, 22.x]
1013
steps:
11-
- uses: actions/checkout@v3
12-
- name: Use Node.js
13-
uses: actions/setup-node@v3
14+
- uses: actions/checkout@v4
15+
- name: Install Corepack via Node
16+
uses: actions/setup-node@v4
1417
with:
1518
node-version-file: '.nvmrc'
19+
- name: Install Yarn
20+
run: corepack enable
21+
- name: Install Node.js ${{ matrix.node-version }} and restore Yarn cache
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ matrix.node-version }}
1625
cache: 'yarn'
17-
- name: Install Yarn dependencies
26+
- name: Install dependencies via Yarn
1827
run: yarn --immutable
1928

2029
build:
2130
name: Build
31+
needs: prepare
2232
runs-on: ubuntu-latest
23-
needs:
24-
- prepare
33+
strategy:
34+
matrix:
35+
node-version: [22.x]
2536
steps:
26-
- uses: actions/checkout@v3
27-
- name: Use Node.js
28-
uses: actions/setup-node@v3
37+
- uses: actions/checkout@v4
38+
- name: Install Corepack via Node
39+
uses: actions/setup-node@v4
2940
with:
3041
node-version-file: '.nvmrc'
42+
- name: Install Yarn
43+
run: corepack enable
44+
- name: Install Node.js ${{ matrix.node-version }} and restore Yarn cache
45+
uses: actions/setup-node@v4
46+
with:
47+
node-version: ${{ matrix.node-version }}
3148
cache: 'yarn'
32-
- run: yarn --immutable --immutable-cache
49+
- name: Install dependencies via Yarn
50+
run: yarn --immutable --immutable-cache
3351
- run: yarn build
3452
- name: Require clean working directory
3553
shell: bash
@@ -41,17 +59,26 @@ jobs:
4159
4260
lint:
4361
name: Lint
62+
needs: prepare
4463
runs-on: ubuntu-latest
45-
needs:
46-
- prepare
64+
strategy:
65+
matrix:
66+
node-version: [22.x]
4767
steps:
48-
- uses: actions/checkout@v3
49-
- name: Use Node.js
50-
uses: actions/setup-node@v3
68+
- uses: actions/checkout@v4
69+
- name: Install Corepack via Node
70+
uses: actions/setup-node@v4
5171
with:
5272
node-version-file: '.nvmrc'
73+
- name: Install Yarn
74+
run: corepack enable
75+
- name: Install Node.js ${{ matrix.node-version }} and restore Yarn cache
76+
uses: actions/setup-node@v4
77+
with:
78+
node-version: ${{ matrix.node-version }}
5379
cache: 'yarn'
54-
- run: yarn --immutable --immutable-cache
80+
- name: Install dependencies via Yarn
81+
run: yarn --immutable --immutable-cache
5582
- run: yarn lint
5683
- name: Validate RC changelog
5784
if: ${{ startsWith(github.head_ref, 'release/') }}
@@ -69,20 +96,26 @@ jobs:
6996
7097
test:
7198
name: Test
99+
needs: prepare
72100
runs-on: ubuntu-latest
73-
needs:
74-
- prepare
75101
strategy:
76102
matrix:
77103
node-version: [18.x, 20.x, 22.x]
78104
steps:
79-
- uses: actions/checkout@v3
80-
- name: Use Node.js ${{ matrix.node-version }}
81-
uses: actions/setup-node@v3
105+
- uses: actions/checkout@v4
106+
- name: Install Corepack via Node
107+
uses: actions/setup-node@v4
108+
with:
109+
node-version-file: '.nvmrc'
110+
- name: Install Yarn
111+
run: corepack enable
112+
- name: Install Node.js ${{ matrix.node-version }} and restore Yarn cache
113+
uses: actions/setup-node@v4
82114
with:
83115
node-version: ${{ matrix.node-version }}
84116
cache: 'yarn'
85-
- run: yarn --immutable --immutable-cache
117+
- name: Install dependencies via Yarn
118+
run: yarn --immutable --immutable-cache
86119
- run: yarn test
87120
- name: Require clean working directory
88121
shell: bash
@@ -94,25 +127,32 @@ jobs:
94127
95128
compatibility-test:
96129
name: Compatibility test
130+
needs: prepare
97131
runs-on: ubuntu-latest
98-
needs:
99-
- prepare
100132
strategy:
101133
matrix:
102134
node-version: [18.x, 20.x, 22.x]
103135
steps:
104-
- uses: actions/checkout@v3
105-
- name: Use Node.js ${{ matrix.node-version }}
106-
uses: actions/setup-node@v3
136+
- uses: actions/checkout@v4
137+
- name: Install Corepack via Node
138+
uses: actions/setup-node@v4
139+
with:
140+
node-version-file: '.nvmrc'
141+
- name: Install Yarn
142+
run: corepack enable
143+
- name: Install Node.js ${{ matrix.node-version }} and restore Yarn cache
144+
uses: actions/setup-node@v4
107145
with:
108146
node-version: ${{ matrix.node-version }}
109147
cache: 'yarn'
110-
- run: rm yarn.lock && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn
148+
- name: Install dependencies via Yarn
149+
run: rm yarn.lock && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn
111150
- run: yarn test
151+
- name: Restore lockfile
152+
run: git restore yarn.lock
112153
- name: Require clean working directory
113154
shell: bash
114155
run: |
115-
git restore yarn.lock
116156
if ! git diff --exit-code; then
117157
echo "Working tree dirty at end of job"
118158
exit 1

.github/workflows/create-release-pr.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ jobs:
2121
contents: write
2222
pull-requests: write
2323
steps:
24-
- uses: actions/checkout@v3
24+
- uses: actions/checkout@v4
2525
with:
2626
# This is to guarantee that the most recent tag is fetched.
2727
# This can be configured to a more reasonable value by consumers.
2828
fetch-depth: 0
2929
# We check out the specified branch, which will be used as the base
3030
# branch for all git operations and the release PR.
3131
ref: ${{ github.event.inputs.base-branch }}
32-
- name: Setup Node.js
33-
uses: actions/setup-node@v3
32+
- name: Install Node.js
33+
uses: actions/setup-node@v4
3434
with:
3535
node-version-file: '.nvmrc'
3636
- uses: MetaMask/action-create-release-pr@v3
37-
env:
38-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3937
with:
4038
release-type: ${{ github.event.inputs.release-type }}
4139
release-version: ${{ github.event.inputs.release-version }}
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
name: Check workflows
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414
- name: Download actionlint
1515
id: download-actionlint
1616
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/7fdc9630cc360ea1a469eed64ac6d78caeda1234/scripts/download-actionlint.bash) 1.6.23

.github/workflows/publish-docs.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ jobs:
2121
- name: Ensure `destination_dir` is not empty
2222
if: ${{ inputs.destination_dir == '' }}
2323
run: exit 1
24-
- name: Checkout the repository
25-
uses: actions/checkout@v3
26-
- name: Use Node.js
27-
uses: actions/setup-node@v3
24+
- uses: actions/checkout@v4
25+
- name: Install Corepack via Node
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version-file: '.nvmrc'
29+
- name: Install Yarn
30+
run: corepack enable
31+
- name: Restore Yarn cache
32+
uses: actions/setup-node@v4
2833
with:
2934
node-version-file: '.nvmrc'
3035
cache: 'yarn'
31-
- name: Install npm dependencies
36+
- name: Install dependencies via Yarn
3237
run: yarn --immutable
3338
- name: Run build script
3439
run: yarn build:docs

.github/workflows/publish-release.yml

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,51 @@ jobs:
1616
contents: write
1717
runs-on: ubuntu-latest
1818
steps:
19-
- uses: actions/checkout@v3
19+
- uses: actions/checkout@v4
2020
with:
2121
ref: ${{ github.sha }}
22-
- name: Setup Node.js
23-
uses: actions/setup-node@v3
22+
- name: Install Corepack via Node
23+
uses: actions/setup-node@v4
2424
with:
2525
node-version-file: '.nvmrc'
26+
- name: Install Yarn
27+
run: corepack enable
28+
- name: Restore Yarn cache
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version-file: '.nvmrc'
32+
cache: 'yarn'
2633
- uses: MetaMask/action-publish-release@v3
2734
env:
2835
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29-
- name: Install
30-
run: |
31-
yarn install
32-
yarn build
3336
- uses: actions/cache@v3
34-
id: restore-build
3537
with:
3638
path: |
3739
./dist
3840
./node_modules/.yarn-state.yml
3941
key: ${{ github.sha }}
42+
- run: yarn --immutable
43+
- run: yarn build
4044

4145
publish-npm-dry-run:
42-
runs-on: ubuntu-latest
4346
needs: publish-release
47+
runs-on: ubuntu-latest
4448
steps:
45-
- uses: actions/checkout@v3
49+
- uses: actions/checkout@v4
4650
with:
4751
ref: ${{ github.sha }}
52+
- name: Install Corepack via Node
53+
uses: actions/setup-node@v4
54+
with:
55+
node-version-file: '.nvmrc'
56+
- name: Install Yarn
57+
run: corepack enable
58+
- name: Restore Yarn cache
59+
uses: actions/setup-node@v4
60+
with:
61+
node-version-file: '.nvmrc'
62+
cache: 'yarn'
4863
- uses: actions/cache@v3
49-
id: restore-build
5064
with:
5165
path: |
5266
./dist
@@ -62,15 +76,25 @@ jobs:
6276
SKIP_PREPACK: true
6377

6478
publish-npm:
65-
environment: npm-publish
66-
runs-on: ubuntu-latest
6779
needs: publish-npm-dry-run
80+
runs-on: ubuntu-latest
81+
environment: npm-publish
6882
steps:
69-
- uses: actions/checkout@v3
83+
- uses: actions/checkout@v4
7084
with:
7185
ref: ${{ github.sha }}
86+
- name: Install Corepack via Node
87+
uses: actions/setup-node@v4
88+
with:
89+
node-version-file: '.nvmrc'
90+
- name: Install Yarn
91+
run: corepack enable
92+
- name: Restore Yarn cache
93+
uses: actions/setup-node@v4
94+
with:
95+
node-version-file: '.nvmrc'
96+
cache: 'yarn'
7297
- uses: actions/cache@v3
73-
id: restore-build
7498
with:
7599
path: |
76100
./dist
@@ -86,21 +110,21 @@ jobs:
86110
SKIP_PREPACK: true
87111

88112
get-release-version:
89-
runs-on: ubuntu-latest
90113
needs: publish-npm
114+
runs-on: ubuntu-latest
91115
outputs:
92116
RELEASE_VERSION: ${{ steps.get-release-version.outputs.RELEASE_VERSION }}
93117
steps:
94-
- uses: actions/checkout@v3
118+
- uses: actions/checkout@v4
95119
with:
96120
ref: ${{ github.sha }}
97121
- id: get-release-version
98122
shell: bash
99123
run: ./scripts/get.sh ".version" "RELEASE_VERSION"
100124

101125
publish-release-to-gh-pages:
102-
needs: get-release-version
103126
name: Publish docs to `${{ needs.get-release-version.outputs.RELEASE_VERSION }}` directory of `gh-pages` branch
127+
needs: get-release-version
104128
permissions:
105129
contents: write
106130
uses: ./.github/workflows/publish-docs.yml
@@ -110,8 +134,8 @@ jobs:
110134
PUBLISH_DOCS_TOKEN: ${{ secrets.PUBLISH_DOCS_TOKEN }}
111135

112136
publish-release-to-latest-gh-pages:
113-
needs: publish-npm
114137
name: Publish docs to `latest` directory of `gh-pages` branch
138+
needs: publish-npm
115139
permissions:
116140
contents: write
117141
uses: ./.github/workflows/publish-docs.yml

0 commit comments

Comments
 (0)