-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (90 loc) · 2.74 KB
/
publish.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Publish on NPM registry
on:
push:
branches: [main]
tags: ['**']
pull_request:
types: [opened, synchronize]
jobs:
format:
name: Check format with Prettier
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-16-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-16
- name: Install NPM dependencies
run: npm install
- name: Run Prettier
run: npm run format:check
test:
name: Test with Jest
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
node: [10, 11, 12, 13, 14, 15, 16]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-${{ matrix.node }}
- name: Install NPM dependencies
run: npm install
- name: Run Jest with coverage
run: npm run test:cov
- name: Upload coverage reports to Codecov
if: matrix.node == '16' # Only upload coverage reports when using latest Node version
uses: codecov/codecov-action@v1
with:
files: ./coverage/lcov.info
verbose: true
publish:
name: Publish to GitHub registry
needs: [format, test]
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Ensure tag validity
if: startsWith(github.ref, 'refs/tags/')
run: |
if [ $(jq -r .version package.json) != ${GITHUB_REF/refs\/tags\//} ]; then
echo "Error: $GITHUB_REF does not match package.json version"
exit 1
fi
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-16-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-node-16
- name: Install NPM dependencies
run: npm install
- name: Publish new release
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_PUBLISH_TOKEN }}
dry-run: ${{ !startsWith(github.ref , 'refs/tags/') }}
access: public