Skip to content

Commit ba6a56f

Browse files
authored
Update GitHub actions to match module template (#125)
The GitHub actions have been updated to match the latest used in the module template, with some exceptions. The require-additional-reviewer action was omitted because it's broken for forks, and the documentation-related steps have been omitted because this repository does not yet have API documentation. The build has also been included in the lint step, because the changelog linting relies upon the built `auto-changelog` tool. See: https://github.com/MetaMask/metamask-module-template/tree/a3b2e531a7961ccc32577ac3c49aa651a14623cd/.github/workflows
1 parent f9a33a7 commit ba6a56f

File tree

5 files changed

+196
-41
lines changed

5 files changed

+196
-41
lines changed

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

Lines changed: 108 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ on:
66
pull_request:
77

88
jobs:
9-
build-lint-test:
10-
name: Build, Lint, and Test
11-
runs-on: ubuntu-20.04
9+
prepare:
10+
name: Prepare
11+
runs-on: ubuntu-latest
12+
outputs:
13+
YARN_CACHE_DIR: ${{ steps.yarn-cache-dir.outputs.YARN_CACHE_DIR }}
14+
YARN_VERSION: ${{ steps.yarn-version.outputs.YARN_VERSION }}
1215
strategy:
1316
matrix:
14-
node-version: [14.x, 16.x, 18.x]
17+
node-version: [14.x, 16.x, 18.x, 19.x]
1518
steps:
1619
- uses: actions/checkout@v3
1720
- name: Use Node.js ${{ matrix.node-version }}
@@ -24,39 +27,123 @@ jobs:
2427
- name: Get Yarn version
2528
run: echo "YARN_VERSION=$(yarn --version)" >> "$GITHUB_OUTPUT"
2629
id: yarn-version
27-
- name: Cache yarn dependencies
30+
- name: Cache Yarn dependencies
2831
uses: actions/cache@v3
2932
with:
3033
path: ${{ steps.yarn-cache-dir.outputs.YARN_CACHE_DIR }}
31-
key: yarn-cache-${{ runner.os }}-${{ steps.yarn-version.outputs.YARN_VERSION }}-${{ hashFiles('yarn.lock') }}
34+
key: yarn-cache-${{ runner.os }}-${{ steps.yarn-version.outputs.YARN_VERSION }}-${{ hashFiles('yarn.lock') }}-${{ matrix.node-version }}
35+
- name: Install Yarn dependencies
36+
run: yarn --immutable
37+
build:
38+
name: Build
39+
runs-on: ubuntu-latest
40+
needs:
41+
- prepare
42+
strategy:
43+
matrix:
44+
node-version: [14.x, 16.x, 18.x, 19.x]
45+
steps:
46+
- uses: actions/checkout@v3
47+
- name: Use Node.js ${{ matrix.node-version }}
48+
uses: actions/setup-node@v3
49+
with:
50+
node-version: ${{ matrix.node-version }}
51+
- name: Restore Yarn dependencies
52+
uses: actions/cache@v3
53+
with:
54+
path: ${{ needs.prepare.outputs.YARN_CACHE_DIR }}
55+
key: yarn-cache-${{ runner.os }}-${{ needs.prepare.outputs.YARN_VERSION }}-${{ hashFiles('yarn.lock') }}-${{ matrix.node-version }}
3256
- run: yarn --immutable
3357
- run: yarn build
34-
- run: yarn lint
35-
- run: yarn test
36-
validate-changelog:
37-
name: Validate changelog
38-
runs-on: ubuntu-20.04
58+
- name: Require clean working directory
59+
shell: bash
60+
run: |
61+
if ! git diff --exit-code; then
62+
echo "Working tree dirty at end of job"
63+
exit 1
64+
fi
65+
lint:
66+
name: Lint
67+
runs-on: ubuntu-latest
68+
needs:
69+
- prepare
70+
strategy:
71+
matrix:
72+
node-version: [14.x, 16.x, 18.x, 19.x]
3973
steps:
4074
- uses: actions/checkout@v3
41-
- name: Get Node.js version
42-
id: nvm
43-
run: echo "NODE_VERSION=$(cat .nvmrc)" >> "$GITHUB_OUTPUT"
44-
- uses: actions/setup-node@v3
75+
- name: Use Node.js ${{ matrix.node-version }}
76+
uses: actions/setup-node@v3
4577
with:
46-
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
78+
node-version: ${{ matrix.node-version }}
79+
- name: Restore Yarn dependencies
80+
uses: actions/cache@v3
81+
with:
82+
path: ${{ needs.prepare.outputs.YARN_CACHE_DIR }}
83+
key: yarn-cache-${{ runner.os }}-${{ needs.prepare.outputs.YARN_VERSION }}-${{ hashFiles('yarn.lock') }}-${{ matrix.node-version }}
4784
- run: yarn --immutable
85+
- run: yarn lint
4886
- run: yarn build
4987
- name: Validate RC changelog
5088
if: ${{ startsWith(github.head_ref, 'release/') }}
51-
run: yarn changelog validate --rc
89+
run: yarn auto-changelog validate --rc
5290
- name: Validate changelog
5391
if: ${{ !startsWith(github.head_ref, 'release/') }}
54-
run: yarn changelog validate
92+
run: yarn auto-changelog validate
93+
- name: Require clean working directory
94+
shell: bash
95+
run: |
96+
if ! git diff --exit-code; then
97+
echo "Working tree dirty at end of job"
98+
exit 1
99+
fi
100+
test:
101+
name: Test
102+
runs-on: ubuntu-latest
103+
needs:
104+
- prepare
105+
strategy:
106+
matrix:
107+
node-version: [14.x, 16.x, 18.x, 19.x]
108+
steps:
109+
- uses: actions/checkout@v3
110+
- name: Use Node.js ${{ matrix.node-version }}
111+
uses: actions/setup-node@v3
112+
with:
113+
node-version: ${{ matrix.node-version }}
114+
- name: Restore Yarn dependencies
115+
uses: actions/cache@v3
116+
with:
117+
path: ${{ needs.prepare.outputs.YARN_CACHE_DIR }}
118+
key: yarn-cache-${{ runner.os }}-${{ needs.prepare.outputs.YARN_VERSION }}-${{ hashFiles('yarn.lock') }}-${{ matrix.node-version }}
119+
- run: yarn --immutable
120+
- run: yarn test
121+
- name: Require clean working directory
122+
shell: bash
123+
run: |
124+
if ! git diff --exit-code; then
125+
echo "Working tree dirty at end of job"
126+
exit 1
127+
fi
128+
check-workflows:
129+
name: Check workflows
130+
runs-on: ubuntu-latest
131+
steps:
132+
- uses: actions/checkout@v3
133+
- name: Download actionlint
134+
id: download-actionlint
135+
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/d5f726fb9c9aaff30c8c3787a9b9640f7612838a/scripts/download-actionlint.bash) 1.6.21
136+
shell: bash
137+
- name: Check workflow files
138+
run: ${{ steps.download-actionlint.outputs.executable }} -color
139+
shell: bash
55140
all-jobs-pass:
56141
name: All jobs pass
57-
runs-on: ubuntu-20.04
142+
runs-on: ubuntu-latest
58143
needs:
59-
- build-lint-test
60-
- validate-changelog
144+
- build
145+
- lint
146+
- test
147+
- check-workflows
61148
steps:
62149
- run: echo "Great success!"

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ 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: Get Node.js version
33-
id: nvm
34-
run: echo "NODE_VERSION=$(cat .nvmrc)" >> "$GITHUB_OUTPUT"
35-
- uses: actions/setup-node@v3
32+
- name: Setup Node.js
33+
uses: actions/setup-node@v3
3634
with:
37-
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
35+
node-version-file: '.nvmrc'
3836
- uses: MetaMask/action-create-release-pr@v1
3937
env:
4038
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,87 @@
11
name: Publish Release
22

33
on:
4-
pull_request:
5-
types: [closed]
4+
push:
5+
branches: [main]
66

77
jobs:
8+
is-release:
9+
# release merge commits come from github-actions
10+
if: startsWith(github.event.commits[0].author.name, 'github-actions')
11+
outputs:
12+
IS_RELEASE: ${{ steps.is-release.outputs.IS_RELEASE }}
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: MetaMask/action-is-release@v1
16+
id: is-release
17+
818
publish-release:
919
permissions:
1020
contents: write
11-
if: |
12-
github.event.pull_request.merged == true &&
13-
startsWith(github.event.pull_request.head.ref, 'release/')
21+
if: needs.is-release.outputs.IS_RELEASE == 'true'
1422
runs-on: ubuntu-latest
23+
needs: is-release
1524
steps:
1625
- uses: actions/checkout@v3
1726
with:
18-
# We check out the release pull request's base branch, which will be
19-
# used as the base branch for all git operations.
20-
ref: ${{ github.event.pull_request.base.ref }}
21-
- name: Get Node.js version
22-
id: nvm
23-
run: echo "NODE_VERSION=$(cat .nvmrc)" >> "$GITHUB_OUTPUT"
24-
- uses: actions/setup-node@v3
27+
ref: ${{ github.sha }}
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v3
2530
with:
26-
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
27-
- uses: MetaMask/action-publish-release@v1
31+
node-version-file: '.nvmrc'
32+
- uses: MetaMask/action-publish-release@v2
2833
env:
2934
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
- name: Install
36+
run: |
37+
yarn install
38+
yarn build
39+
- uses: actions/cache@v3
40+
id: restore-build
41+
with:
42+
path: ./dist
43+
key: ${{ github.sha }}
44+
45+
publish-npm-dry-run:
46+
runs-on: ubuntu-latest
47+
needs: publish-release
48+
steps:
49+
- uses: actions/checkout@v3
50+
with:
51+
ref: ${{ github.sha }}
52+
- uses: actions/cache@v3
53+
id: restore-build
54+
with:
55+
path: ./dist
56+
key: ${{ github.sha }}
57+
# Set `ignore-scripts` to skip `prepublishOnly` because the release was built already in the previous job
58+
- run: npm config set ignore-scripts true
59+
- name: Dry Run Publish
60+
# omit npm-token token to perform dry run publish
61+
uses: MetaMask/action-npm-publish@v1
62+
env:
63+
SKIP_PREPACK: true
64+
65+
publish-npm:
66+
environment: npm-publish
67+
runs-on: ubuntu-latest
68+
needs: publish-npm-dry-run
69+
steps:
70+
- uses: actions/checkout@v3
71+
with:
72+
ref: ${{ github.sha }}
73+
- uses: actions/cache@v3
74+
id: restore-build
75+
with:
76+
path: ./dist
77+
key: ${{ github.sha }}
78+
# Set `ignore-scripts` to skip `prepublishOnly` because the release was built already in the previous job
79+
- run: npm config set ignore-scripts true
80+
- name: Publish
81+
uses: MetaMask/action-npm-publish@v1
82+
with:
83+
# This `NPM_TOKEN` needs to be manually set per-repository.
84+
# Look in the repository settings under "Environments", and set this token in the `npm-publish` environment.
85+
npm-token: ${{ secrets.NPM_TOKEN }}
86+
env:
87+
SKIP_PREPACK: true

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"scripts": {
2222
"test": "jest",
2323
"test:watch": "jest --watch",
24-
"prepack": "yarn build",
24+
"prepack": "./scripts/prepack.sh",
2525
"lint:eslint": "eslint . --cache --ext js,ts",
2626
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore",
2727
"lint": "yarn lint:eslint && yarn lint:misc --check",

scripts/prepack.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
set -x
4+
set -e
5+
set -o pipefail
6+
7+
if [[ -n $SKIP_PREPACK ]]; then
8+
echo "Notice: skipping prepack."
9+
exit 0
10+
fi
11+
12+
yarn build

0 commit comments

Comments
 (0)