Skip to content

Commit 191bc48

Browse files
authored
Update workflows and configs (#376)
1 parent 33a5fbc commit 191bc48

30 files changed

+3613
-3026
lines changed

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

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

.github/workflows/lint-test.yml

Lines changed: 48 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,66 @@
11
name: 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
10+
outputs:
11+
child-workspace-package-names: ${{ steps.workspace-package-names.outputs.child-workspace-package-names }}
1212
steps:
13-
- uses: actions/checkout@v3
14-
- name: Use Node.js
15-
uses: actions/setup-node@v3
13+
- uses: actions/checkout@v4
14+
- name: Setup Node.js
15+
uses: actions/setup-node@v4
1616
with:
1717
node-version-file: '.nvmrc'
18-
cache: 'yarn'
18+
cache: yarn
1919
- name: Install Yarn dependencies
2020
run: yarn --immutable
21+
- name: Fetch workspace package names
22+
id: workspace-package-names
23+
run: |
24+
echo "child-workspace-package-names=$(yarn workspaces list --no-private --json | jq --slurp --raw-output 'map(.name) | @json')" >> "$GITHUB_OUTPUT"
25+
shell: bash
2126

2227
lint:
2328
name: Lint
2429
runs-on: ubuntu-latest
25-
needs:
26-
- prepare
30+
needs: prepare
31+
steps:
32+
- uses: actions/checkout@v4
33+
- name: Setup Node.js
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version-file: '.nvmrc'
37+
cache: yarn
38+
- run: yarn --immutable
39+
- run: yarn lint
40+
- name: Require clean working directory
41+
shell: bash
42+
run: |
43+
if ! git diff --exit-code; then
44+
echo "Working tree dirty at end of job"
45+
exit 1
46+
fi
47+
48+
validate-changelog:
49+
name: Validate changelog
50+
runs-on: ubuntu-latest
51+
needs: prepare
2752
strategy:
2853
matrix:
29-
node-version: [18.x, 20.x]
54+
package-name: ${{ fromJson(needs.prepare.outputs.child-workspace-package-names) }}
3055
steps:
31-
- uses: actions/checkout@v3
32-
- name: Use Node.js ${{ matrix.node-version }}
33-
uses: actions/setup-node@v3
56+
- uses: actions/checkout@v4
57+
- name: Setup Node.js
58+
uses: actions/setup-node@v4
3459
with:
35-
node-version: ${{ matrix.node-version }}
36-
cache: 'yarn'
37-
- run: yarn --immutable --immutable-cache
38-
- run: yarn lint
39-
- name: Validate RC changelog
40-
if: ${{ startsWith(github.head_ref, 'release/') }}
41-
run: yarn lint:changelogs --rc
42-
- name: Validate changelog
43-
if: ${{ !startsWith(github.head_ref, 'release/') }}
44-
run: yarn lint:changelogs
60+
node-version-file: '.nvmrc'
61+
cache: yarn
62+
- run: yarn --immutable
63+
- run: yarn workspace ${{ matrix.package-name }} changelog:validate
4564
- name: Require clean working directory
4665
shell: bash
4766
run: |
@@ -59,63 +78,19 @@ jobs:
5978
matrix:
6079
node-version: [18.x, 20.x]
6180
steps:
62-
- uses: actions/checkout@v3
63-
- name: Use Node.js ${{ matrix.node-version }}
64-
uses: actions/setup-node@v3
81+
- uses: actions/checkout@v4
82+
- name: Setup Node.js ${{ matrix.node-version }}
83+
uses: actions/setup-node@v4
6584
with:
6685
node-version: ${{ matrix.node-version }}
67-
cache: 'yarn'
86+
cache: yarn
6887
- run: yarn --immutable --immutable-cache
69-
- run: yarn test
88+
- name: Test
89+
run: yarn test
7090
- name: Require clean working directory
7191
shell: bash
7292
run: |
7393
if ! git diff --exit-code; then
7494
echo "Working tree dirty at end of job"
7595
exit 1
7696
fi
77-
78-
check-workflows:
79-
name: Check workflows
80-
runs-on: ubuntu-latest
81-
steps:
82-
- uses: actions/checkout@v3
83-
- name: Download actionlint
84-
id: download-actionlint
85-
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/7fdc9630cc360ea1a469eed64ac6d78caeda1234/scripts/download-actionlint.bash) 1.6.22
86-
shell: bash
87-
- name: Check workflow files
88-
run: ${{ steps.download-actionlint.outputs.executable }} -color
89-
shell: bash
90-
91-
all-jobs-pass:
92-
name: All jobs pass
93-
runs-on: ubuntu-latest
94-
needs:
95-
- lint
96-
- test
97-
- check-workflows
98-
steps:
99-
- run: echo "Great success!"
100-
101-
is-release:
102-
# release merge commits come from github-actions
103-
if: startsWith(github.event.commits[0].author.name, 'github-actions')
104-
needs:
105-
- all-jobs-pass
106-
outputs:
107-
IS_RELEASE: ${{ steps.is-release.outputs.IS_RELEASE }}
108-
runs-on: ubuntu-latest
109-
steps:
110-
- uses: MetaMask/action-is-release@v1
111-
id: is-release
112-
113-
publish-release:
114-
needs: is-release
115-
if: needs.is-release.outputs.IS_RELEASE == 'true'
116-
name: Publish release
117-
permissions:
118-
contents: write
119-
uses: ./.github/workflows/publish-release.yml
120-
secrets:
121-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/main.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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.25
17+
shell: bash
18+
- name: Check workflow files
19+
run: ${{ steps.download-actionlint.outputs.executable }} -color
20+
shell: bash
21+
22+
lint-test:
23+
name: Lint, build, and test
24+
needs: check-workflows
25+
uses: ./.github/workflows/lint-test.yml
26+
27+
is-release:
28+
name: Determine whether this is a release merge commit
29+
needs: lint-test
30+
if: github.event_name == 'push'
31+
runs-on: ubuntu-latest
32+
outputs:
33+
IS_RELEASE: ${{ steps.is-release.outputs.IS_RELEASE }}
34+
steps:
35+
- id: is-release
36+
uses: MetaMask/action-is-release@v2
37+
with:
38+
commit-starts-with: 'Release [version],Release v[version],Release/[version],Release/v[version]'
39+
40+
publish-release:
41+
name: Publish release
42+
needs: is-release
43+
if: needs.is-release.outputs.IS_RELEASE == 'true'
44+
permissions:
45+
contents: write
46+
uses: ./.github/workflows/publish-release.yml
47+
secrets:
48+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
49+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
50+
51+
all-jobs-complete:
52+
name: All jobs complete
53+
runs-on: ubuntu-latest
54+
needs: lint-test
55+
outputs:
56+
passed: ${{ steps.set-output.outputs.passed }}
57+
steps:
58+
- name: Set passed output
59+
id: set-output
60+
run: echo "passed=true" >> "$GITHUB_OUTPUT"
61+
62+
all-jobs-pass:
63+
name: All jobs pass
64+
if: ${{ always() }}
65+
runs-on: ubuntu-latest
66+
needs: all-jobs-complete
67+
steps:
68+
- name: Check that all jobs have passed
69+
run: |
70+
passed="${{ needs.all-jobs-complete.outputs.passed }}"
71+
if [[ $passed != "true" ]]; then
72+
exit 1
73+
fi

.github/workflows/publish-release.yml

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,67 @@ on:
55
secrets:
66
NPM_TOKEN:
77
required: true
8+
SLACK_WEBHOOK_URL:
9+
required: true
810

911
jobs:
1012
publish-release:
1113
permissions:
1214
contents: write
1315
runs-on: ubuntu-latest
1416
steps:
15-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
1618
with:
1719
ref: ${{ github.sha }}
18-
- name: Setup Node.js
19-
uses: actions/setup-node@v3
20+
- name: Install Node
21+
uses: actions/setup-node@v4
2022
with:
2123
node-version-file: '.nvmrc'
22-
- uses: MetaMask/action-publish-release@v2
23-
env:
24-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25-
- name: Install
26-
run: yarn install
27-
- uses: actions/cache@v3
28-
id: restore-build
24+
- name: Install Yarn
25+
run: corepack enable
26+
- name: Restore Yarn cache
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version-file: '.nvmrc'
30+
cache: yarn
31+
- uses: actions/cache@v4
2932
with:
3033
path: |
34+
./packages/**/src
3135
./node_modules/.yarn-state.yml
3236
key: ${{ github.sha }}
37+
- uses: MetaMask/action-publish-release@v3
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
- run: yarn --immutable
41+
- run: yarn build
3342

3443
publish-npm-dry-run:
3544
runs-on: ubuntu-latest
3645
needs: publish-release
3746
steps:
38-
- uses: actions/checkout@v3
47+
- uses: actions/checkout@v4
3948
with:
4049
ref: ${{ github.sha }}
41-
- uses: actions/cache@v3
42-
id: restore-build
50+
- name: Install Node
51+
uses: actions/setup-node@v4
52+
with:
53+
node-version-file: '.nvmrc'
54+
- name: Install Yarn
55+
run: corepack enable
56+
- uses: actions/cache@v4
4357
with:
4458
path: |
59+
./packages/**/src
4560
./node_modules/.yarn-state.yml
4661
key: ${{ github.sha }}
62+
fail-on-cache-miss: true
4763
- name: Dry Run Publish
4864
# omit npm-token token to perform dry run publish
49-
uses: MetaMask/action-npm-publish@v2
65+
uses: MetaMask/action-npm-publish@v5
66+
with:
67+
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
68+
subteam: S042S7RE4AE # @metamask-npm-publishers
5069
env:
5170
SKIP_PREPACK: true
5271

@@ -55,20 +74,25 @@ jobs:
5574
runs-on: ubuntu-latest
5675
needs: publish-npm-dry-run
5776
steps:
58-
- uses: actions/checkout@v3
77+
- uses: actions/checkout@v4
5978
with:
6079
ref: ${{ github.sha }}
61-
- uses: actions/cache@v3
62-
id: restore-build
80+
- name: Install Node
81+
uses: actions/setup-node@v4
82+
with:
83+
node-version-file: '.nvmrc'
84+
- name: Install Yarn
85+
run: corepack enable
86+
- uses: actions/cache@v4
6387
with:
6488
path: |
89+
./packages/**/src
6590
./node_modules/.yarn-state.yml
6691
key: ${{ github.sha }}
92+
fail-on-cache-miss: true
6793
- name: Publish
68-
uses: MetaMask/action-npm-publish@v2
94+
uses: MetaMask/action-npm-publish@v5
6995
with:
70-
# This `NPM_TOKEN` needs to be manually set per-repository.
71-
# Look in the repository settings under "Environments", and set this token in the `npm-publish` environment.
7296
npm-token: ${{ secrets.NPM_TOKEN }}
7397
env:
7498
SKIP_PREPACK: true

0 commit comments

Comments
 (0)