Skip to content

Commit 2771767

Browse files
authored
Update GitHub actions to match module template (#44)
The GitHub actions have been updated to match the module template, with some exceptions. The docs publishing was omitted because this repository does not yet have API documentation, and I left some additional steps in the prepack script because they were present already.
1 parent 72d5610 commit 2771767

File tree

5 files changed

+200
-39
lines changed

5 files changed

+200
-39
lines changed

.github/workflows/build-test.yml

Lines changed: 107 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,83 @@ 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]
17+
node-version: [14.x, 16.x, 18.x, 19.x]
1518
steps:
16-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v3
1720
- name: Use Node.js ${{ matrix.node-version }}
18-
uses: actions/setup-node@v2
21+
uses: actions/setup-node@v3
1922
with:
2023
node-version: ${{ matrix.node-version }}
2124
- name: Get Yarn cache directory
22-
run: echo "::set-output name=YARN_CACHE_DIR::$(yarn config get cacheFolder)"
25+
run: echo "YARN_CACHE_DIR=$(yarn config get cacheFolder)" >> "$GITHUB_OUTPUT"
2326
id: yarn-cache-dir
2427
- name: Get Yarn version
25-
run: echo "::set-output name=YARN_VERSION::$(yarn --version)"
28+
run: echo "YARN_VERSION=$(yarn --version)" >> "$GITHUB_OUTPUT"
2629
id: yarn-version
27-
- name: Cache yarn dependencies
28-
uses: actions/cache@v2
30+
- name: Cache Yarn dependencies
31+
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
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]
73+
steps:
74+
- uses: actions/checkout@v3
75+
- name: Use Node.js ${{ matrix.node-version }}
76+
uses: actions/setup-node@v3
77+
with:
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 }}
84+
- run: yarn --immutable
3485
- run: yarn lint
35-
- run: yarn test
3686
- name: Validate RC changelog
3787
if: ${{ startsWith(github.head_ref, 'release/') }}
3888
run: yarn auto-changelog validate --rc
@@ -46,10 +96,53 @@ jobs:
4696
echo "Working tree dirty at end of job"
4797
exit 1
4898
fi
99+
test:
100+
name: Test
101+
runs-on: ubuntu-latest
102+
needs:
103+
- prepare
104+
strategy:
105+
matrix:
106+
node-version: [14.x, 16.x, 18.x, 19.x]
107+
steps:
108+
- uses: actions/checkout@v3
109+
- name: Use Node.js ${{ matrix.node-version }}
110+
uses: actions/setup-node@v3
111+
with:
112+
node-version: ${{ matrix.node-version }}
113+
- name: Restore Yarn dependencies
114+
uses: actions/cache@v3
115+
with:
116+
path: ${{ needs.prepare.outputs.YARN_CACHE_DIR }}
117+
key: yarn-cache-${{ runner.os }}-${{ needs.prepare.outputs.YARN_VERSION }}-${{ hashFiles('yarn.lock') }}-${{ matrix.node-version }}
118+
- run: yarn --immutable
119+
- run: yarn test
120+
- name: Require clean working directory
121+
shell: bash
122+
run: |
123+
if ! git diff --exit-code; then
124+
echo "Working tree dirty at end of job"
125+
exit 1
126+
fi
127+
check-workflows:
128+
name: Check workflows
129+
runs-on: ubuntu-latest
130+
steps:
131+
- uses: actions/checkout@v3
132+
- name: Download actionlint
133+
id: download-actionlint
134+
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/d5f726fb9c9aaff30c8c3787a9b9640f7612838a/scripts/download-actionlint.bash) 1.6.21
135+
shell: bash
136+
- name: Check workflow files
137+
run: ${{ steps.download-actionlint.outputs.executable }} -color
138+
shell: bash
49139
all-jobs-pass:
50140
name: All jobs pass
51-
runs-on: ubuntu-20.04
141+
runs-on: ubuntu-latest
52142
needs:
53-
- build-lint-test
143+
- build
144+
- lint
145+
- test
146+
- check-workflows
54147
steps:
55148
- run: echo "Great success!"

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,18 @@ jobs:
2121
contents: write
2222
pull-requests: write
2323
steps:
24-
- uses: actions/checkout@v2
24+
- uses: actions/checkout@v3
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: Get Node.js version
33-
id: nvm
34-
run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
35-
- uses: actions/setup-node@v2
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 }}
@@ -43,7 +41,7 @@ jobs:
4341
release-version: ${{ github.event.inputs.release-version }}
4442
artifacts-path: gh-action__release-authors
4543
# Upload the release author artifact for use in subsequent workflows
46-
- uses: actions/upload-artifact@v2
44+
- uses: actions/upload-artifact@v3
4745
with:
4846
name: release-authors
4947
path: gh-action__release-authors
Lines changed: 75 additions & 17 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:
16-
- uses: actions/checkout@v2
17-
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 ::set-output name=NODE_VERSION::$(cat .nvmrc)
24-
- uses: actions/setup-node@v2
25-
with:
26-
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
27-
- uses: MetaMask/action-publish-release@v1
25+
- uses: actions/checkout@v3
26+
with:
27+
ref: ${{ github.sha }}
28+
- name: Setup Node.js
29+
uses: actions/setup-node@v3
30+
with:
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
@@ -18,7 +18,7 @@
1818
"lint:eslint": "eslint . --cache --ext js,ts",
1919
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
2020
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
21-
"prepack": "yarn lint && yarn build:clean && yarn test",
21+
"prepack": "./scripts/prepack.sh",
2222
"test": "jest && jest-it-up",
2323
"test:watch": "jest --watch"
2424
},

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 lint && yarn test && yarn build:clean

0 commit comments

Comments
 (0)