Skip to content

Commit e5ddf14

Browse files
chore: Update workflows to use MetaMask/action-checkout-and-setup (#481)
## Description This updates all workflows to remove the use of `actions/checkout`, `actions/setup-node`, `actions/cache`. The implementation here is based on MetaMask/core#5474 Key improvements: 1. Replaces manual Node.js setup and caching with a standardized action 2. Adds proper high-risk environment handling for sensitive workflows 3. Updates Node.js version matrix to include v22.x 4. Improves security by removing potentially vulnerable caching mechanisms ## Related issues Fixes: #377 - https://github.com/MetaMask/metamask-design-system/security/code-scanning/3 - https://github.com/MetaMask/metamask-design-system/security/code-scanning/2 - https://github.com/MetaMask/metamask-design-system/security/code-scanning/1 ## Manual testing steps 1. Review the changes MetaMask/core#5474 and make sure it matches in this PR in each workflow: - `.github/workflows/lint-build-test.yml` - `.github/workflows/publish-release.yml` - `.github/workflows/publish-preview.yml` - `.github/workflows/ensure-blocking-pr-labels-absent.yml` - `.github/workflows/security-code-scanner.yml` - `.github/workflows/main.yml` 2. Verify that the workflows use the correct configuration: ```yaml - name: Checkout and setup environment uses: MetaMask/action-checkout-and-setup@v1 with: is-high-risk-environment: true # for publish workflows node-version: ${{ matrix.node-version }} # when using matrix ``` 3. Confirm CI passes on this PR with the updated workflows 4. For publish workflows, verify: - High-risk environment flag is set to `true` - Artifact handling is properly configured - Node.js matrix strategy includes all required versions (18.x, 20.x, 22.x) ## Screenshots/Recordings ### After Comparing code changes between this PR and the one in core MetaMask/core#5474 https://github.com/user-attachments/assets/dfda14a7-2c90-4f12-bab5-ac78413552c3 ## Pre-merge author checklist - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) - [x] I've completed the PR template to the best of my ability - [x] I've included tests if applicable - [x] I've documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I've applied the right labels on the PR ## Pre-merge reviewer checklist - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed) - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots
1 parent 5658529 commit e5ddf14

File tree

6 files changed

+99
-159
lines changed

6 files changed

+99
-159
lines changed

.github/workflows/ensure-blocking-pr-labels-absent.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,10 @@ jobs:
1313
permissions:
1414
pull-requests: read
1515
steps:
16-
- uses: actions/checkout@v4
17-
- name: Use Node.js
18-
uses: actions/setup-node@v4
16+
- name: Checkout and setup environment
17+
uses: MetaMask/action-checkout-and-setup@v1
1918
with:
20-
node-version-file: '.nvmrc'
21-
- name: Install Yarn
22-
run: corepack enable
23-
- name: Restore Yarn cache
24-
uses: actions/setup-node@v4
25-
with:
26-
node-version-file: '.nvmrc'
27-
cache: 'yarn'
28-
- run: yarn --immutable
19+
is-high-risk-environment: false
2920
- name: Run command
3021
uses: actions/github-script@v7
3122
with:

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

Lines changed: 21 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,15 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
node-version: [18.x, 20.x]
12+
node-version: [18.x, 20.x, 22.x]
1313
outputs:
1414
child-workspace-package-names: ${{ steps.workspace-package-names.outputs.child-workspace-package-names }}
1515
steps:
16-
- uses: actions/checkout@v4
17-
- name: Install Node.js ${{ matrix.node-version }}
18-
uses: actions/setup-node@v4
16+
- name: Checkout and setup environment
17+
uses: MetaMask/action-checkout-and-setup@v1
1918
with:
20-
node-version: ${{ matrix.node-version }}
21-
- name: Install Yarn
22-
run: corepack enable
23-
- name: Restore Yarn cache
24-
uses: actions/setup-node@v4
25-
with:
26-
node-version: ${{ matrix.node-version }}
27-
cache: yarn
28-
- run: yarn --immutable
19+
is-high-risk-environment: false
20+
cache-node-modules: ${{ matrix.node-version == '22.x' }}
2921
- name: Fetch workspace package names
3022
id: workspace-package-names
3123
run: |
@@ -38,21 +30,12 @@ jobs:
3830
needs: prepare
3931
strategy:
4032
matrix:
41-
node-version: [20.x]
33+
node-version: [22.x]
4234
steps:
43-
- uses: actions/checkout@v4
44-
- name: Install Node.js ${{ matrix.node-version }}
45-
uses: actions/setup-node@v4
46-
with:
47-
node-version: ${{ matrix.node-version }}
48-
- name: Install Yarn
49-
run: corepack enable
50-
- name: Restore Yarn cache
51-
uses: actions/setup-node@v4
35+
- name: Checkout and setup environment
36+
uses: MetaMask/action-checkout-and-setup@v1
5237
with:
53-
node-version: ${{ matrix.node-version }}
54-
cache: yarn
55-
- run: yarn --immutable
38+
is-high-risk-environment: false
5639
- run: yarn lint
5740
- name: Require clean working directory
5841
shell: bash
@@ -68,22 +51,13 @@ jobs:
6851
needs: prepare
6952
strategy:
7053
matrix:
71-
node-version: [20.x]
54+
node-version: [22.x]
7255
package-name: ${{ fromJson(needs.prepare.outputs.child-workspace-package-names) }}
7356
steps:
74-
- uses: actions/checkout@v4
75-
- name: Install Node.js ${{ matrix.node-version }}
76-
uses: actions/setup-node@v4
77-
with:
78-
node-version: ${{ matrix.node-version }}
79-
- name: Install Yarn
80-
run: corepack enable
81-
- name: Restore Yarn cache
82-
uses: actions/setup-node@v4
57+
- name: Checkout and setup environment
58+
uses: MetaMask/action-checkout-and-setup@v1
8359
with:
84-
node-version: ${{ matrix.node-version }}
85-
cache: yarn
86-
- run: yarn --immutable
60+
is-high-risk-environment: false
8761
- run: yarn workspace ${{ matrix.package-name }} changelog:validate
8862
- name: Require clean working directory
8963
shell: bash
@@ -99,21 +73,12 @@ jobs:
9973
needs: prepare
10074
strategy:
10175
matrix:
102-
node-version: [20.x]
76+
node-version: [22.x]
10377
steps:
104-
- uses: actions/checkout@v4
105-
- name: Install Node.js ${{ matrix.node-version }}
106-
uses: actions/setup-node@v4
78+
- name: Checkout and setup environment
79+
uses: MetaMask/action-checkout-and-setup@v1
10780
with:
108-
node-version: ${{ matrix.node-version }}
109-
- name: Install Yarn
110-
run: corepack enable
111-
- name: Restore Yarn cache
112-
uses: actions/setup-node@v4
113-
with:
114-
node-version: ${{ matrix.node-version }}
115-
cache: yarn
116-
- run: yarn --immutable
81+
is-high-risk-environment: false
11782
- run: yarn build
11883
- name: Require clean working directory
11984
shell: bash
@@ -129,22 +94,13 @@ jobs:
12994
needs: prepare
13095
strategy:
13196
matrix:
132-
node-version: [18.x, 20.x]
97+
node-version: [18.x, 20.x, 22.x]
13398
package-name: ${{ fromJson(needs.prepare.outputs.child-workspace-package-names) }}
13499
steps:
135-
- uses: actions/checkout@v4
136-
- name: Install Node.js ${{ matrix.node-version }}
137-
uses: actions/setup-node@v4
138-
with:
139-
node-version: ${{ matrix.node-version }}
140-
- name: Install Yarn
141-
run: corepack enable
142-
- name: Restore Yarn cache
143-
uses: actions/setup-node@v4
100+
- name: Checkout and setup environment
101+
uses: MetaMask/action-checkout-and-setup@v1
144102
with:
145-
node-version: ${{ matrix.node-version }}
146-
cache: yarn
147-
- run: yarn --immutable
103+
is-high-risk-environment: false
148104
- run: yarn test:scripts
149105
- run: yarn workspace ${{ matrix.package-name }} run test
150106
- name: Require clean working directory

.github/workflows/main.yml

Lines changed: 17 additions & 3 deletions
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.25
@@ -19,6 +19,18 @@ jobs:
1919
run: ${{ steps.download-actionlint.outputs.executable }} -color
2020
shell: bash
2121

22+
analyse-code:
23+
name: Code scanner
24+
needs: check-workflows
25+
uses: ./.github/workflows/security-code-scanner.yml
26+
permissions:
27+
actions: read
28+
contents: read
29+
security-events: write
30+
secrets:
31+
SECURITY_SCAN_METRICS_TOKEN: ${{ secrets.SECURITY_SCAN_METRICS_TOKEN }}
32+
APPSEC_BOT_SLACK_WEBHOOK: ${{ secrets.APPSEC_BOT_SLACK_WEBHOOK }}
33+
2234
lint-build-test:
2335
name: Lint, build, and test
2436
needs: check-workflows
@@ -35,7 +47,7 @@ jobs:
3547
- id: is-release
3648
uses: MetaMask/action-is-release@dc4672b05e3b1d464cdaf783579b04a4e43f8b02
3749
with:
38-
commit-starts-with: 'Release [version],Release v[version],Release/[version],Release/v[version]'
50+
commit-starts-with: 'Release [version],Release v[version],Release/[version],Release/v[version],Release `[version]`'
3951

4052
publish-release:
4153
name: Publish release
@@ -51,7 +63,9 @@ jobs:
5163
all-jobs-complete:
5264
name: All jobs complete
5365
runs-on: ubuntu-latest
54-
needs: lint-build-test
66+
needs:
67+
- analyse-code
68+
- lint-build-test
5569
outputs:
5670
passed: ${{ steps.set-output.outputs.passed }}
5771
steps:

.github/workflows/publish-preview.yml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# TODO: Publish a preview build doesn't work and needs to be fixed https://github.com/MetaMask/metamask-design-system/issues/38
2-
31
name: Publish a preview build
42

53
on:
@@ -37,18 +35,10 @@ jobs:
3735
env:
3836
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3937
PR_NUMBER: ${{ github.event.issue.number }}
40-
- name: Install Node
41-
uses: actions/setup-node@v4
42-
with:
43-
node-version-file: '.nvmrc'
44-
- name: Install Yarn
45-
run: corepack enable
46-
- name: Restore Yarn cache
47-
uses: actions/setup-node@v4
38+
- name: Checkout and setup environment
39+
uses: MetaMask/action-checkout-and-setup@v1
4840
with:
49-
node-version-file: '.nvmrc'
50-
cache: yarn
51-
- run: yarn --immutable
41+
is-high-risk-environment: true
5242
- name: Get commit SHA
5343
id: commit-sha
5444
run: echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"

.github/workflows/publish-release.yml

Lines changed: 28 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -14,85 +14,60 @@ jobs:
1414
contents: write
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v4
17+
- name: Checkout and setup environment
18+
uses: MetaMask/action-checkout-and-setup@v1
1819
with:
19-
ref: ${{ github.sha }}
20-
- name: Install Node
21-
uses: actions/setup-node@v4
22-
with:
23-
node-version-file: '.nvmrc'
24-
- name: Install Yarn
25-
run: corepack enable
26-
- name: Restore Yarn cache
27-
uses: actions/setup-node@v4
28-
with:
29-
node-version-file: '.nvmrc'
30-
cache: yarn
31-
- uses: actions/cache@v4
32-
with:
33-
path: |
34-
./packages/**/dist
35-
./node_modules/.yarn-state.yml
36-
key: ${{ github.sha }}
20+
is-high-risk-environment: true
3721
- uses: MetaMask/action-publish-release@v3
3822
env:
3923
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40-
- run: yarn --immutable
4124
- run: yarn build
25+
- name: Upload build artifacts
26+
uses: actions/upload-artifact@v4
27+
with:
28+
name: publish-release-artifacts-${{ github.sha }}
29+
include-hidden-files: true
30+
retention-days: 4
31+
path: |
32+
./packages/**/dist
33+
./node_modules/.yarn-state.yml
4234
4335
publish-npm-dry-run:
36+
name: Dry run publish to NPM
4437
runs-on: ubuntu-latest
4538
needs: publish-release
4639
steps:
47-
- uses: actions/checkout@v4
40+
- name: Checkout and setup environment
41+
uses: MetaMask/action-checkout-and-setup@v1
4842
with:
43+
is-high-risk-environment: true
4944
ref: ${{ github.sha }}
50-
- name: Install Node
51-
uses: actions/setup-node@v4
45+
- name: Restore build artifacts
46+
uses: actions/download-artifact@v4
5247
with:
53-
node-version-file: '.nvmrc'
54-
- name: Install Yarn
55-
run: corepack enable
56-
- uses: actions/cache@v4
57-
with:
58-
path: |
59-
./packages/**/dist
60-
./node_modules/.yarn-state.yml
61-
key: ${{ github.sha }}
62-
fail-on-cache-miss: true
63-
- name: Dry Run Publish
64-
# omit npm-token token to perform dry run publish
48+
name: publish-release-artifacts-${{ github.sha }}
49+
- name: Dry run publish to NPM
6550
uses: MetaMask/action-npm-publish@v5
6651
with:
6752
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
6853
subteam: S042S7RE4AE # @metamask-npm-publishers
69-
env:
70-
SKIP_PREPACK: true
7154

7255
publish-npm:
56+
name: Publish to NPM
7357
environment: npm-publish
7458
runs-on: ubuntu-latest
7559
needs: publish-npm-dry-run
7660
steps:
77-
- uses: actions/checkout@v4
61+
- name: Checkout and setup environment
62+
uses: MetaMask/action-checkout-and-setup@v1
7863
with:
64+
is-high-risk-environment: true
7965
ref: ${{ github.sha }}
80-
- name: Install Node
81-
uses: actions/setup-node@v4
66+
- name: Restore build artifacts
67+
uses: actions/download-artifact@v4
8268
with:
83-
node-version-file: '.nvmrc'
84-
- name: Install Yarn
85-
run: corepack enable
86-
- uses: actions/cache@v4
87-
with:
88-
path: |
89-
./packages/**/dist
90-
./node_modules/.yarn-state.yml
91-
key: ${{ github.sha }}
92-
fail-on-cache-miss: true
93-
- name: Publish
69+
name: publish-release-artifacts-${{ github.sha }}
70+
- name: Publish to NPM
9471
uses: MetaMask/action-npm-publish@v5
9572
with:
9673
npm-token: ${{ secrets.NPM_TOKEN }}
97-
env:
98-
SKIP_PREPACK: true

0 commit comments

Comments
 (0)