Skip to content

Commit 8eff000

Browse files
authored
Sync GitHub workflows with module template (#225)
- Add pull request template - Add compatibility test - Use `action-checkout-and-setup` for checkout + setup Node tests - Consolidate main workflows into `main.yml` - Use artifacts for caching in release workflows - Add Slack notification for releases Note that this commit does not add docs publishing workflows or lint the changelog because `yarn build:docs` and `yarn lint:changelog` don't exist yet.
1 parent e76de22 commit 8eff000

File tree

7 files changed

+210
-141
lines changed

7 files changed

+210
-141
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Please see the documentation for all configuration options:
2-
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
2+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
33

44
version: 2
55
updates:

.github/pull_request_template.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!--
2+
Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes:
3+
4+
* What is the current state of things and why does it need to change?
5+
* What is the solution your changes offer and how does it work?
6+
7+
Are there any issues or other links reviewers should consult to understand this pull request better? For instance:
8+
9+
* Fixes #12345
10+
* See: #67890
11+
-->
Lines changed: 43 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,36 @@
11
name: Build, Lint, and Test
22

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

86
jobs:
97
prepare:
108
name: Prepare
119
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 }}
1510
strategy:
1611
matrix:
1712
node-version: [18.x, 20.x, 22.x]
1813
steps:
19-
- uses: actions/checkout@v3
20-
- name: Use Node.js ${{ matrix.node-version }}
21-
uses: actions/setup-node@v3
14+
- name: Checkout and setup environment
15+
uses: MetaMask/action-checkout-and-setup@v1
2216
with:
17+
is-high-risk-environment: false
2318
node-version: ${{ matrix.node-version }}
24-
- name: Get Yarn cache directory
25-
run: echo "YARN_CACHE_DIR=$(yarn config get cacheFolder)" >> "$GITHUB_OUTPUT"
26-
id: yarn-cache-dir
27-
- name: Get Yarn version
28-
run: echo "YARN_VERSION=$(yarn --version)" >> "$GITHUB_OUTPUT"
29-
id: yarn-version
30-
- name: Cache Yarn dependencies
31-
uses: actions/cache@v3
32-
with:
33-
path: ${{ steps.yarn-cache-dir.outputs.YARN_CACHE_DIR }}
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
19+
cache-node-modules: ${{ matrix.node-version == '22.x' }}
20+
3721
build:
3822
name: Build
23+
needs: prepare
3924
runs-on: ubuntu-latest
40-
needs:
41-
- prepare
4225
strategy:
4326
matrix:
4427
node-version: [18.x, 20.x, 22.x]
4528
steps:
46-
- uses: actions/checkout@v3
47-
- name: Use Node.js ${{ matrix.node-version }}
48-
uses: actions/setup-node@v3
29+
- name: Checkout and setup environment
30+
uses: MetaMask/action-checkout-and-setup@v1
4931
with:
32+
is-high-risk-environment: false
5033
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 }}
56-
- run: yarn --immutable
5734
- run: yarn build
5835
- name: Require clean working directory
5936
shell: bash
@@ -62,61 +39,42 @@ jobs:
6239
echo "Working tree dirty at end of job"
6340
exit 1
6441
fi
42+
6543
lint:
6644
name: Lint
45+
needs: prepare
6746
runs-on: ubuntu-latest
68-
needs:
69-
- prepare
7047
strategy:
7148
matrix:
7249
node-version: [18.x, 20.x, 22.x]
7350
steps:
74-
- uses: actions/checkout@v3
75-
- name: Use Node.js ${{ matrix.node-version }}
76-
uses: actions/setup-node@v3
51+
- name: Checkout and setup environment
52+
uses: MetaMask/action-checkout-and-setup@v1
7753
with:
54+
is-high-risk-environment: false
7855
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
8556
- run: yarn lint
86-
- run: yarn build
87-
- name: Validate RC changelog
88-
if: ${{ startsWith(github.head_ref, 'release/') }}
89-
run: yarn auto-changelog validate --rc
90-
- name: Validate changelog
91-
if: ${{ !startsWith(github.head_ref, 'release/') }}
92-
run: yarn auto-changelog validate
9357
- name: Require clean working directory
9458
shell: bash
9559
run: |
9660
if ! git diff --exit-code; then
9761
echo "Working tree dirty at end of job"
9862
exit 1
9963
fi
64+
10065
test:
10166
name: Test
67+
needs: prepare
10268
runs-on: ubuntu-latest
103-
needs:
104-
- prepare
10569
strategy:
10670
matrix:
10771
node-version: [18.x, 20.x, 22.x]
10872
steps:
109-
- uses: actions/checkout@v3
110-
- name: Use Node.js ${{ matrix.node-version }}
111-
uses: actions/setup-node@v3
73+
- name: Checkout and setup environment
74+
uses: MetaMask/action-checkout-and-setup@v1
11275
with:
76+
is-high-risk-environment: false
11377
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
12078
- run: yarn test
12179
- name: Require clean working directory
12280
shell: bash
@@ -125,25 +83,29 @@ jobs:
12583
echo "Working tree dirty at end of job"
12684
exit 1
12785
fi
128-
check-workflows:
129-
name: Check workflows
86+
87+
compatibility-test:
88+
name: Compatibility test
89+
needs: prepare
13090
runs-on: ubuntu-latest
91+
strategy:
92+
matrix:
93+
node-version: [18.x, 20.x, 22.x]
13194
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
95+
- name: Checkout and setup environment
96+
uses: MetaMask/action-checkout-and-setup@v1
97+
with:
98+
is-high-risk-environment: false
99+
node-version: ${{ matrix.node-version }}
100+
- name: Install dependencies via Yarn
101+
run: rm yarn.lock && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn
102+
- run: yarn test
103+
- name: Restore lockfile
104+
run: git restore yarn.lock
105+
- name: Require clean working directory
139106
shell: bash
140-
all-jobs-pass:
141-
name: All jobs pass
142-
runs-on: ubuntu-latest
143-
needs:
144-
- build
145-
- lint
146-
- test
147-
- check-workflows
148-
steps:
149-
- run: echo "Great success!"
107+
run: |
108+
if ! git diff --exit-code; then
109+
echo "Working tree dirty at end of job"
110+
exit 1
111+
fi

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

Lines changed: 12 additions & 11 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,21 +21,22 @@ jobs:
2121
contents: write
2222
pull-requests: write
2323
steps:
24-
- uses: actions/checkout@v3
24+
- name: Checkout and setup environment
25+
uses: MetaMask/action-checkout-and-setup@v1
2526
with:
26-
# This is to guarantee that the most recent tag is fetched.
27-
# This can be configured to a more reasonable value by consumers.
27+
is-high-risk-environment: true
28+
29+
# This is to guarantee that the most recent tag is fetched. This can
30+
# be configured to a more reasonable value by consumers.
2831
fetch-depth: 0
32+
2933
# We check out the specified branch, which will be used as the base
3034
# branch for all git operations and the release PR.
3135
ref: ${{ github.event.inputs.base-branch }}
32-
- name: Setup Node.js
33-
uses: actions/setup-node@v3
34-
with:
35-
node-version-file: '.nvmrc'
36-
- uses: MetaMask/action-create-release-pr@v1
37-
env:
38-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- uses: MetaMask/action-create-release-pr@v4
3938
with:
4039
release-type: ${{ github.event.inputs.release-type }}
4140
release-version: ${{ github.event.inputs.release-version }}
41+
env:
42+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/main.yml

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

0 commit comments

Comments
 (0)