Skip to content

Commit e584d08

Browse files
authored
Update GitHub Actions to match module template (#95)
The GitHub Actions have been updated to match the latest version of the module template. Notable changes include: * We now use `setup-node` for caching rather than manually caching dependencies. * The "all-jobs-pass" required status check has been split into two steps ("all-jobs-completed" and "all-jobs-pass") to ensure it runs even when a required job is skipped, ensuring that the status check itself is never skipped. * The obsolete `require-additional-reviewer` check has been removed. * Yarn v3 is now used for publishing rather than npm
1 parent f424d21 commit e584d08

File tree

7 files changed

+193
-221
lines changed

7 files changed

+193
-221
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Build, Lint, and Test
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
prepare:
8+
name: Prepare
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Use Node.js
13+
uses: actions/setup-node@v3
14+
with:
15+
node-version-file: '.nvmrc'
16+
cache: 'yarn'
17+
- name: Install Yarn dependencies
18+
run: yarn --immutable
19+
20+
build:
21+
name: Build
22+
runs-on: ubuntu-latest
23+
needs:
24+
- prepare
25+
strategy:
26+
matrix:
27+
node-version: [14.x, 16.x, 18.x, 19.x]
28+
steps:
29+
- uses: actions/checkout@v3
30+
- name: Use Node.js ${{ matrix.node-version }}
31+
uses: actions/setup-node@v3
32+
with:
33+
node-version: ${{ matrix.node-version }}
34+
cache: 'yarn'
35+
- run: yarn --immutable --immutable-cache
36+
- run: yarn build
37+
# This step is dependent on the build output, so it's run here, rather than in the test job.
38+
- run: yarn test:types
39+
- name: Require clean working directory
40+
shell: bash
41+
run: |
42+
if ! git diff --exit-code; then
43+
echo "Working tree dirty at end of job"
44+
exit 1
45+
fi
46+
47+
lint:
48+
name: Lint
49+
runs-on: ubuntu-latest
50+
needs:
51+
- prepare
52+
strategy:
53+
matrix:
54+
node-version: [14.x, 16.x, 18.x, 19.x]
55+
steps:
56+
- uses: actions/checkout@v3
57+
- name: Use Node.js ${{ matrix.node-version }}
58+
uses: actions/setup-node@v3
59+
with:
60+
node-version: ${{ matrix.node-version }}
61+
cache: 'yarn'
62+
- run: yarn --immutable --immutable-cache
63+
- run: yarn lint
64+
- name: Validate RC changelog
65+
if: ${{ startsWith(github.head_ref, 'release/') }}
66+
run: yarn auto-changelog validate --rc
67+
- name: Validate changelog
68+
if: ${{ !startsWith(github.head_ref, 'release/') }}
69+
run: yarn auto-changelog validate
70+
- name: Require clean working directory
71+
shell: bash
72+
run: |
73+
if ! git diff --exit-code; then
74+
echo "Working tree dirty at end of job"
75+
exit 1
76+
fi
77+
78+
test:
79+
name: Test
80+
runs-on: ubuntu-latest
81+
needs:
82+
- prepare
83+
strategy:
84+
matrix:
85+
node-version: [14.x, 16.x, 18.x, 19.x]
86+
steps:
87+
- uses: actions/checkout@v3
88+
- name: Use Node.js ${{ matrix.node-version }}
89+
uses: actions/setup-node@v3
90+
with:
91+
node-version: ${{ matrix.node-version }}
92+
cache: 'yarn'
93+
- run: yarn --immutable --immutable-cache
94+
- run: yarn test:source
95+
- name: Require clean working directory
96+
shell: bash
97+
run: |
98+
if ! git diff --exit-code; then
99+
echo "Working tree dirty at end of job"
100+
exit 1
101+
fi

.github/workflows/build-test.yml

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

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,3 @@ jobs:
3939
with:
4040
release-type: ${{ github.event.inputs.release-type }}
4141
release-version: ${{ github.event.inputs.release-version }}
42-
artifacts-path: gh-action__release-authors
43-
# Upload the release author artifact for use in subsequent workflows
44-
- uses: actions/upload-artifact@v3
45-
with:
46-
name: release-authors
47-
path: gh-action__release-authors
48-
if-no-files-found: error

.github/workflows/main.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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@v3
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-test:
23+
name: Build, lint, and test
24+
uses: ./.github/workflows/build-lint-test.yml
25+
26+
all-jobs-completed:
27+
name: All jobs completed
28+
runs-on: ubuntu-latest
29+
needs:
30+
- check-workflows
31+
- build-lint-test
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 }}

.github/workflows/publish-docs.yml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,11 @@ jobs:
1919
run: exit 1
2020
- name: Checkout the repository
2121
uses: actions/checkout@v3
22-
- name: Setup Node.js
22+
- name: Use Node.js
2323
uses: actions/setup-node@v3
2424
with:
2525
node-version-file: '.nvmrc'
26-
- name: Get Yarn cache directory
27-
run: echo "YARN_CACHE_DIR=$(yarn config get cacheFolder)" >> "$GITHUB_OUTPUT"
28-
id: yarn-cache-dir
29-
- name: Get Yarn version
30-
run: echo "YARN_VERSION=$(yarn --version)" >> "$GITHUB_OUTPUT"
31-
id: yarn-version
32-
- name: Cache yarn dependencies
33-
uses: actions/cache@v3
34-
with:
35-
path: ${{ steps.yarn-cache-dir.outputs.YARN_CACHE_DIR }}
36-
key: yarn-cache-${{ runner.os }}-${{ steps.yarn-version.outputs.YARN_VERSION }}-${{ hashFiles('yarn.lock') }}
26+
cache: 'yarn'
3727
- name: Install npm dependencies
3828
run: yarn --immutable
3929
- name: Run build script

0 commit comments

Comments
 (0)