Skip to content

Commit b881c7c

Browse files
authored
Merge pull request #160 from dwightjack/ci-publish
ci: release workflow
2 parents e9b42e4 + 89bf293 commit b881c7c

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

.github/workflows/release.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: NPM publish CD workflow
2+
3+
on:
4+
release:
5+
# This specifies that the build will be triggered when we publish a release
6+
types: [published]
7+
8+
jobs:
9+
publish:
10+
if: github.event.release.target_commitish == 'main' || github.event.release.target_commitish == 'next'
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
with:
15+
# "ref" specifies the branch to check out.
16+
# "github.event.release.target_commitish" is a global variable and specifies the branch the release targeted
17+
ref: ${{ github.event.release.target_commitish }}
18+
- uses: actions/setup-node@v2
19+
with:
20+
node-version: '14'
21+
# Specifies the registry, this field is required!
22+
registry-url: https://registry.npmjs.org/
23+
- name: Cache node modules
24+
uses: actions/cache@v2
25+
env:
26+
cache-name: cache-node-modules
27+
with:
28+
path: ~/.npm
29+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
30+
restore-keys: |
31+
${{ runner.os }}-build-${{ env.cache-name }}-
32+
${{ runner.os }}-build-
33+
${{ runner.os }}-
34+
- run: npm ci
35+
- run: npm test
36+
- run: npm run build
37+
- run: git config --global user.name "GitHub Release Bot"
38+
- run: git config --global user.email "[email protected]"
39+
40+
# upgrade npm version in package.json to the tag used in the release.
41+
- run: npm version ${{ github.event.release.tag_name }} -m "Bump version %s"
42+
- name: Publish next release
43+
if: github.event.release.target_commitish == 'next'
44+
run: npm publish --ignore-scripts --tag=next
45+
env:
46+
# Use a token to publish to NPM. See below for how to set it up
47+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
48+
- name: Publish stable release
49+
if: github.event.release.target_commitish == 'main'
50+
run: npm publish --ignore-scripts
51+
env:
52+
# Use a token to publish to NPM. See below for how to set it up
53+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
54+
- run: git push
55+
env:
56+
github-token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)