Skip to content

Commit 324c6e9

Browse files
committed
ci: Add Github Actions workflows
1 parent 4a5d274 commit 324c6e9

File tree

3 files changed

+202
-0
lines changed

3 files changed

+202
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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: 'npm'
17+
# - name: Install node dependencies
18+
# run: npm i
19+
#
20+
build:
21+
name: Build
22+
runs-on: ubuntu-latest
23+
#needs:
24+
# - prepare
25+
strategy:
26+
matrix:
27+
node-version: [8.x, 10.x, 12.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: 'npm'
35+
- run: npm i
36+
- run: npm run build
37+
- name: Require clean working directory
38+
shell: bash
39+
run: |
40+
if ! git diff --exit-code -- . ':!dist/*.map'; then
41+
echo "Working tree dirty at end of job"
42+
exit 1
43+
fi
44+
45+
lint:
46+
name: Lint
47+
runs-on: ubuntu-latest
48+
#needs:
49+
# - prepare
50+
strategy:
51+
matrix:
52+
node-version: [8.x, 10.x, 12.x]
53+
steps:
54+
- uses: actions/checkout@v3
55+
- name: Use Node.js ${{ matrix.node-version }}
56+
uses: actions/setup-node@v3
57+
with:
58+
node-version: ${{ matrix.node-version }}
59+
cache: 'npm'
60+
- run: npm i
61+
- run: npm run lint
62+
63+
test:
64+
name: Test
65+
runs-on: ubuntu-latest
66+
#needs:
67+
# - prepare
68+
strategy:
69+
matrix:
70+
node-version: [8.x, 10.x, 12.x]
71+
steps:
72+
- uses: actions/checkout@v3
73+
- name: Use Node.js ${{ matrix.node-version }}
74+
uses: actions/setup-node@v3
75+
with:
76+
node-version: ${{ matrix.node-version }}
77+
cache: 'npm'
78+
- run: npm i
79+
- run: npm run test
80+
- name: Require clean working directory
81+
shell: bash
82+
run: |
83+
if ! git diff --exit-code -- . ':!dist/*.map'; then
84+
echo "Working tree dirty at end of job"
85+
exit 1
86+
fi

.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.22
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 }}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Publish Release
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
NPM_TOKEN:
7+
required: true
8+
9+
jobs:
10+
publish-release:
11+
permissions:
12+
contents: write
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
ref: ${{ github.sha }}
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version-file: '.nvmrc'
22+
- uses: MetaMask/action-publish-release@v2
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
- name: Install and build
26+
run: |
27+
npm i
28+
npm run build
29+
- name: Dry Run Publish
30+
# omit npm-token token to perform dry run publish
31+
uses: MetaMask/action-npm-publish@v2
32+
env:
33+
SKIP_PREPACK: true
34+
- name: Publish
35+
uses: MetaMask/action-npm-publish@v2
36+
with:
37+
# This `NPM_TOKEN` needs to be manually set per-repository.
38+
# Look in the repository settings under "Environments", and set this token in the `npm-publish` environment.
39+
npm-token: ${{ secrets.NPM_TOKEN }}
40+
env:
41+
SKIP_PREPACK: true

0 commit comments

Comments
 (0)