Skip to content

Commit 570f6c2

Browse files
authored
Fix other workflows to install Corepack as prereq (#246)
A recent commit upgraded the version of Yarn to v4 and removed the Yarn binary from the repo, thereby requiring that Corepack be installed in order to install dependencies. The `build-lint-test` was updated to install Corepack, but not the documentation-related workflows, so they are failing. This commit fixes those workflows to install Corepack. It also cleans up some work that was done in previous commits: - In the `build-lint-test` workflow we ensure that `prepare` is run once per Node version we are testing and that `build` and `lint` use the latest Node version we are testing. - In steps where we are installing Node just to gain access to the `corepack` executable, we use `.nvmrc` (the version of Node we use for development) to know which version of Node to install rather than using the latest LTS (`lts/*`). For jobs that do not need to concern themselves with being run in multiple Node versions, this ensures that consistent Node versions are used in this step vs. the step that is used to simply restore the Yarn cache. - The checkout step always goes first, this way `.nvmrc` can be read.
1 parent 076554c commit 570f6c2

File tree

4 files changed

+97
-58
lines changed

4 files changed

+97
-58
lines changed

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

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,47 @@ jobs:
77
prepare:
88
name: Prepare
99
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
node-version: [18.x, 20.x]
1013
steps:
11-
- name: Use Node.js
14+
- uses: actions/checkout@v4
15+
- name: Install Corepack via Node
1216
uses: actions/setup-node@v4
1317
with:
14-
node-version: 'lts/*'
18+
node-version-file: '.nvmrc'
1519
- name: Install Yarn
1620
run: corepack enable
17-
- uses: actions/checkout@v4
18-
- name: Use Node.js and install dependencies
21+
- name: Install Node.js ${{ matrix.node-version }} and restore Yarn cache
1922
uses: actions/setup-node@v4
2023
with:
21-
node-version: 'lts/*'
24+
node-version: ${{ matrix.node-version }}
2225
cache: 'yarn'
23-
- name: Install Yarn dependencies
26+
- name: Install dependencies via Yarn
2427
run: yarn --immutable
2528

2629
build:
2730
name: Build
31+
needs: prepare
2832
runs-on: ubuntu-latest
29-
needs:
30-
- prepare
33+
strategy:
34+
matrix:
35+
node-version: [20.x]
3136
steps:
32-
- name: Use Node.js
37+
- uses: actions/checkout@v4
38+
- name: Install Corepack via Node
3339
uses: actions/setup-node@v4
3440
with:
35-
node-version: 'lts/*'
41+
node-version-file: '.nvmrc'
3642
- name: Install Yarn
3743
run: corepack enable
38-
- uses: actions/checkout@v4
39-
- name: Use Node.js
44+
- name: Install Node.js ${{ matrix.node-version }} and restore Yarn cache
4045
uses: actions/setup-node@v4
4146
with:
42-
node-version: 'lts/*'
47+
node-version: ${{ matrix.node-version }}
4348
cache: 'yarn'
44-
- run: yarn --immutable --immutable-cache
49+
- name: Install dependencies via Yarn
50+
run: yarn --immutable --immutable-cache
4551
- run: yarn build
4652
- name: Require clean working directory
4753
shell: bash
@@ -53,23 +59,26 @@ jobs:
5359
5460
lint:
5561
name: Lint
62+
needs: prepare
5663
runs-on: ubuntu-latest
57-
needs:
58-
- prepare
64+
strategy:
65+
matrix:
66+
node-version: [20.x]
5967
steps:
60-
- name: Use Node.js
68+
- uses: actions/checkout@v4
69+
- name: Install Corepack via Node
6170
uses: actions/setup-node@v4
6271
with:
63-
node-version: 'lts/*'
72+
node-version-file: '.nvmrc'
6473
- name: Install Yarn
6574
run: corepack enable
66-
- uses: actions/checkout@v4
67-
- name: Use Node.js
75+
- name: Install Node.js ${{ matrix.node-version }} and restore Yarn cache
6876
uses: actions/setup-node@v4
6977
with:
70-
node-version: 'lts/*'
78+
node-version: ${{ matrix.node-version }}
7179
cache: 'yarn'
72-
- run: yarn --immutable --immutable-cache
80+
- name: Install dependencies via Yarn
81+
run: yarn --immutable --immutable-cache
7382
- run: yarn lint
7483
- name: Validate RC changelog
7584
if: ${{ startsWith(github.head_ref, 'release/') }}
@@ -87,26 +96,26 @@ jobs:
8796
8897
test:
8998
name: Test
99+
needs: prepare
90100
runs-on: ubuntu-latest
91-
needs:
92-
- prepare
93101
strategy:
94102
matrix:
95103
node-version: [18.x, 20.x]
96104
steps:
97-
- name: Use Node.js
105+
- uses: actions/checkout@v4
106+
- name: Install Corepack via Node
98107
uses: actions/setup-node@v4
99108
with:
100-
node-version: ${{ matrix.node-version }}
109+
node-version-file: '.nvmrc'
101110
- name: Install Yarn
102111
run: corepack enable
103-
- uses: actions/checkout@v4
104-
- name: Use Node.js ${{ matrix.node-version }}
112+
- name: Install Node.js ${{ matrix.node-version }} and restore Yarn cache
105113
uses: actions/setup-node@v4
106114
with:
107115
node-version: ${{ matrix.node-version }}
108116
cache: 'yarn'
109-
- run: yarn --immutable --immutable-cache
117+
- name: Install dependencies via Yarn
118+
run: yarn --immutable --immutable-cache
110119
- run: yarn test
111120
- name: Require clean working directory
112121
shell: bash
@@ -118,31 +127,32 @@ jobs:
118127
119128
compatibility-test:
120129
name: Compatibility test
130+
needs: prepare
121131
runs-on: ubuntu-latest
122-
needs:
123-
- prepare
124132
strategy:
125133
matrix:
126134
node-version: [18.x, 20.x]
127135
steps:
128-
- name: Use Node.js
136+
- uses: actions/checkout@v4
137+
- name: Install Corepack via Node
129138
uses: actions/setup-node@v4
130139
with:
131-
node-version: ${{ matrix.node-version }}
140+
node-version-file: '.nvmrc'
132141
- name: Install Yarn
133142
run: corepack enable
134-
- uses: actions/checkout@v4
135-
- name: Use Node.js ${{ matrix.node-version }}
143+
- name: Install Node.js ${{ matrix.node-version }} and restore Yarn cache
136144
uses: actions/setup-node@v4
137145
with:
138146
node-version: ${{ matrix.node-version }}
139147
cache: 'yarn'
140-
- 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
141150
- run: yarn test
151+
- name: Restore lockfile
152+
run: git restore yarn.lock
142153
- name: Require clean working directory
143154
shell: bash
144155
run: |
145-
git restore yarn.lock
146156
if ! git diff --exit-code; then
147157
echo "Working tree dirty at end of job"
148158
exit 1

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ jobs:
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
32+
- name: Install Node.js
3333
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/publish-docs.yml

Lines changed: 9 additions & 4 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@v4
26-
- name: Use Node.js
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
2732
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: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,48 @@ jobs:
1919
- uses: actions/checkout@v4
2020
with:
2121
ref: ${{ github.sha }}
22-
- name: Setup Node.js
22+
- name: Install Corepack via Node
2323
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:
4549
- 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:
6983
- 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,8 +110,8 @@ 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:
@@ -99,8 +123,8 @@ jobs:
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)