Skip to content

Commit 6d70495

Browse files
Gudahttmcmire
andauthored
chore: Update workflows and automate releases (#125)
* chore: Update workflows and automate releases The GitHub Action workflows have been updated based on the module template. The changes made from the template are: * There are no tests, so the test step from "build-lint-test" was removed. * The "build" step is now run on three Node.js versions rathern than just one. In the template we rely more on tests for compatibility, but that won't work with no tests of course. * The "build" step builds the demo, not the package. There is no build step for the package, it's not in TypeScript (yet). * The API doc publishing was removed (this repo uses the `gh-pages` branch for the demo). * The changelog doesn't use Prettier formatting yet (this requires more lint tooling/config updates). The changes made from the previous workflows in this repository are: * Automated npm publishing * Removed "require additional reviewer" workflow (we've stopped using this) * Additional workflow linting * Updated vertions of various actions * Update base image to `ubuntu-latest` * Add Node.js v22.x to the test matrix * Add checks for a dirty working tree Additionally, the "publish-gh-pages" workflow was updated to use the same "checkout, install Node.js, and install dependencies" steps as elsewhere. This workflow has no analog in the module template. * Remove non-existent build step and build artifacts from publishing workflow * Update to latest version of npm publish action Co-authored-by: Elliot Winkler <[email protected]> --------- Co-authored-by: Elliot Winkler <[email protected]>
1 parent b87ad9a commit 6d70495

File tree

7 files changed

+221
-90
lines changed

7 files changed

+221
-90
lines changed

.github/workflows/build-lint.yml

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
name: Build and Lint
22

33
on:
4-
push:
5-
branches: [main]
6-
pull_request:
4+
workflow_call:
75

86
jobs:
9-
build-lint:
10-
name: Build and Lint
11-
env:
12-
INFURA_PROJECT_ID: ${{ secrets.INFURA_PROJECT_ID }}
13-
runs-on: ubuntu-20.04
7+
prepare:
8+
name: Prepare
9+
runs-on: ubuntu-latest
1410
strategy:
1511
matrix:
16-
node-version: [18.x, 20.x]
12+
node-version: [18.x, 20.x, 22.x]
1713
steps:
18-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v4
1915
- name: Install Corepack via Node
2016
uses: actions/setup-node@v4
2117
with:
@@ -27,20 +23,74 @@ jobs:
2723
with:
2824
node-version: ${{ matrix.node-version }}
2925
cache: 'yarn'
30-
- run: yarn --immutable
31-
- run: yarn lint
26+
- name: Install dependencies via Yarn
27+
run: yarn --immutable
28+
29+
build:
30+
name: Build
31+
needs: prepare
32+
runs-on: ubuntu-latest
33+
strategy:
34+
matrix:
35+
node-version: [18.x, 20.x, 22.x]
36+
steps:
37+
- uses: actions/checkout@v4
38+
- name: Install Corepack via Node
39+
uses: actions/setup-node@v4
40+
with:
41+
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 }}
48+
cache: 'yarn'
49+
- name: Install dependencies via Yarn
50+
run: yarn --immutable --immutable-cache
3251
- name: Ensure demo build script works
3352
run: yarn demo --all
53+
- name: Require clean working directory
54+
shell: bash
55+
run: |
56+
if ! git diff --exit-code; then
57+
echo "Working tree dirty at end of job"
58+
exit 1
59+
fi
60+
61+
lint:
62+
name: Lint
63+
needs: prepare
64+
runs-on: ubuntu-latest
65+
strategy:
66+
matrix:
67+
node-version: [22.x]
68+
steps:
69+
- uses: actions/checkout@v4
70+
- name: Install Corepack via Node
71+
uses: actions/setup-node@v4
72+
with:
73+
node-version-file: '.nvmrc'
74+
- name: Install Yarn
75+
run: corepack enable
76+
- name: Install Node.js ${{ matrix.node-version }} and restore Yarn cache
77+
uses: actions/setup-node@v4
78+
with:
79+
node-version: ${{ matrix.node-version }}
80+
cache: 'yarn'
81+
- name: Install dependencies via Yarn
82+
run: yarn --immutable --immutable-cache
83+
- run: yarn lint
3484
- name: Validate RC changelog
3585
if: ${{ startsWith(github.head_ref, 'release/') }}
36-
run: yarn auto-changelog validate --rc
86+
run: yarn lint:changelog --rc
3787
- name: Validate changelog
3888
if: ${{ !startsWith(github.head_ref, 'release/') }}
39-
run: yarn auto-changelog validate
40-
all-jobs-pass:
41-
name: All jobs pass
42-
runs-on: ubuntu-20.04
43-
needs:
44-
- build-lint
45-
steps:
46-
- run: echo "Great success!"
89+
run: yarn lint:changelog
90+
- name: Require clean working directory
91+
shell: bash
92+
run: |
93+
if ! git diff --exit-code; then
94+
echo "Working tree dirty at end of job"
95+
exit 1
96+
fi

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
default: 'main'
99
required: true
1010
release-type:
11-
description: 'A SemVer version diff, i.e. major, minor, patch, prerelease etc. Mutually exclusive with "release-version".'
11+
description: 'A SemVer version diff, i.e. major, minor, or patch. Mutually exclusive with "release-version".'
1212
required: false
1313
release-version:
1414
description: 'A specific version to bump to. Mutually exclusive with "release-type".'
@@ -21,30 +21,21 @@ jobs:
2121
contents: write
2222
pull-requests: write
2323
steps:
24-
- uses: actions/checkout@v2
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: 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: Install Node.js
33+
uses: actions/setup-node@v4
3634
with:
37-
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
38-
- uses: MetaMask/action-create-release-pr@v1
39-
env:
40-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35+
node-version-file: '.nvmrc'
36+
- uses: MetaMask/action-create-release-pr@v4
4137
with:
4238
release-type: ${{ github.event.inputs.release-type }}
4339
release-version: ${{ github.event.inputs.release-version }}
44-
artifacts-path: gh-action__release-authors
45-
# Upload the release author artifact for use in subsequent workflows
46-
- uses: actions/upload-artifact@v2
47-
with:
48-
name: release-authors
49-
path: gh-action__release-authors
50-
if-no-files-found: error
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/main.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Main
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
check-workflows:
10+
name: Check workflows
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Download actionlint
15+
id: download-actionlint
16+
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/7fdc9630cc360ea1a469eed64ac6d78caeda1234/scripts/download-actionlint.bash) 1.6.23
17+
shell: bash
18+
- name: Check workflow files
19+
run: ${{ steps.download-actionlint.outputs.executable }} -color
20+
shell: bash
21+
22+
build-lint:
23+
name: Build and lint
24+
uses: ./.github/workflows/build-lint.yml
25+
26+
all-jobs-completed:
27+
name: All jobs completed
28+
runs-on: ubuntu-latest
29+
needs:
30+
- check-workflows
31+
- build-lint
32+
outputs:
33+
PASSED: ${{ steps.set-output.outputs.PASSED }}
34+
steps:
35+
- name: Set PASSED output
36+
id: set-output
37+
run: echo "PASSED=true" >> "$GITHUB_OUTPUT"
38+
39+
all-jobs-pass:
40+
name: All jobs pass
41+
if: ${{ always() }}
42+
runs-on: ubuntu-latest
43+
needs: all-jobs-completed
44+
steps:
45+
- name: Check that all jobs have passed
46+
run: |
47+
passed="${{ needs.all-jobs-completed.outputs.PASSED }}"
48+
if [[ $passed != "true" ]]; then
49+
exit 1
50+
fi
51+
52+
is-release:
53+
# Filtering by `push` events ensures that we only release from the `main` branch, which is a
54+
# requirement for our npm publishing environment.
55+
# The commit author should always be 'github-actions' for releases created by the
56+
# 'create-release-pr' workflow, so we filter by that as well to prevent accidentally
57+
# triggering a release.
58+
if: github.event_name == 'push' && startsWith(github.event.head_commit.author.name, 'github-actions')
59+
needs: all-jobs-pass
60+
outputs:
61+
IS_RELEASE: ${{ steps.is-release.outputs.IS_RELEASE }}
62+
runs-on: ubuntu-latest
63+
steps:
64+
- uses: MetaMask/action-is-release@v1
65+
id: is-release
66+
67+
publish-release:
68+
needs: is-release
69+
if: needs.is-release.outputs.IS_RELEASE == 'true'
70+
name: Publish release
71+
permissions:
72+
contents: write
73+
uses: ./.github/workflows/publish-release.yml
74+
secrets:
75+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
76+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

.github/workflows/publish-gh-pages.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ jobs:
1010
contents: write
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
14-
- name: Get Node.js version
15-
id: nvm
16-
run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
17-
- uses: actions/setup-node@v2
13+
- uses: actions/checkout@v4
14+
- name: Install Corepack via Node
15+
uses: actions/setup-node@v4
1816
with:
19-
node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
17+
node-version-file: '.nvmrc'
2018
- name: Install Yarn
2119
run: corepack enable
2220
- run: yarn --immutable
Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,73 @@
11
name: Publish Release
22

33
on:
4-
pull_request:
5-
types: [closed]
4+
workflow_call:
5+
secrets:
6+
NPM_TOKEN:
7+
required: true
8+
SLACK_WEBHOOK_URL:
9+
required: true
610

711
jobs:
812
publish-release:
913
permissions:
1014
contents: write
11-
if: |
12-
github.event.pull_request.merged == true &&
13-
startsWith(github.event.pull_request.head.ref, 'release/')
1415
runs-on: ubuntu-latest
1516
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
17+
- uses: actions/checkout@v4
18+
with:
19+
ref: ${{ github.sha }}
20+
- name: Install Corepack via Node
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version-file: '.nvmrc'
24+
- name: Install Yarn
25+
run: corepack enable
26+
- uses: MetaMask/action-publish-release@v3
2827
env:
2928
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
30+
publish-npm-dry-run:
31+
needs: publish-release
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
with:
36+
ref: ${{ github.sha }}
37+
- name: Install Corepack via Node
38+
uses: actions/setup-node@v4
39+
with:
40+
node-version-file: '.nvmrc'
41+
- name: Install Yarn
42+
run: corepack enable
43+
- name: Dry Run Publish
44+
# omit npm-token token to perform dry run publish
45+
uses: MetaMask/action-npm-publish@v5
46+
with:
47+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
48+
subteam: S042S7RE4AE # @metamask-npm-publishers
49+
env:
50+
SKIP_PREPACK: true
51+
52+
publish-npm:
53+
needs: publish-npm-dry-run
54+
runs-on: ubuntu-latest
55+
environment: npm-publish
56+
steps:
57+
- uses: actions/checkout@v4
58+
with:
59+
ref: ${{ github.sha }}
60+
- name: Install Corepack via Node
61+
uses: actions/setup-node@v4
62+
with:
63+
node-version-file: '.nvmrc'
64+
- name: Install Yarn
65+
run: corepack enable
66+
- name: Publish
67+
uses: MetaMask/action-npm-publish@v5
68+
with:
69+
# This `NPM_TOKEN` needs to be manually set per-repository.
70+
# Look in the repository settings under "Environments", and set this token in the `npm-publish` environment.
71+
npm-token: ${{ secrets.NPM_TOKEN }}
72+
env:
73+
SKIP_PREPACK: true

.github/workflows/require-additional-reviewer.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"demo": "node demo/build.js",
2424
"demo:all": "yarn demo --all",
2525
"lint": "yarn lint:eslint && yarn lint:misc --check",
26+
"lint:changelog": "auto-changelog validate",
2627
"lint:eslint": "eslint . --cache --ext js,ts",
2728
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
2829
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' --ignore-path .gitignore"

0 commit comments

Comments
 (0)