1 |
|
2 |
|
3 | name: Test and Release
|
4 |
|
5 |
|
6 |
|
7 | on:
|
8 | push:
|
9 | branches:
|
10 | - master
|
11 | tags:
|
12 |
|
13 | - "v[0-9]+.[0-9]+.[0-9]+"
|
14 |
|
15 | - "v[0-9]+.[0-9]+.[0-9]+-**"
|
16 | pull_request: {}
|
17 |
|
18 | jobs:
|
19 |
|
20 | unit-tests:
|
21 | if: contains(github.event.head_commit.message, '[skip ci]') == false
|
22 |
|
23 | runs-on: ${{ matrix.os }}
|
24 | strategy:
|
25 | matrix:
|
26 | node-version: [14.x, 16.x, 18.x]
|
27 | os: [ubuntu-latest, windows-latest, macos-latest]
|
28 |
|
29 | steps:
|
30 | - name: Checkout code
|
31 | uses: actions/checkout@v3
|
32 |
|
33 | - name: Use Node.js ${{ matrix.node-version }}
|
34 | uses: actions/setup-node@v3
|
35 | with:
|
36 | node-version: ${{ matrix.node-version }}
|
37 | cache: 'npm'
|
38 |
|
39 | - name: Install dependencies
|
40 | run: npm ci
|
41 |
|
42 | - name: Lint code
|
43 | run: npm run lint
|
44 |
|
45 | - name: Compile TypeScript code
|
46 | run: npm run build
|
47 |
|
48 |
|
49 | - name: Run component tests
|
50 | run: npm test
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | deploy:
|
56 |
|
57 | if: |
|
58 | contains(github.event.head_commit.message, '[skip ci]') == false &&
|
59 | github.event_name == 'push' &&
|
60 | startsWith(github.ref, 'refs/tags/v')
|
61 |
|
62 | needs: [unit-tests]
|
63 |
|
64 | runs-on: ubuntu-latest
|
65 | strategy:
|
66 | matrix:
|
67 | node-version: [16.x]
|
68 |
|
69 | steps:
|
70 | - name: Checkout code
|
71 | uses: actions/checkout@v3
|
72 |
|
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 |
|
79 | - name: Extract the version and commit body from the tag
|
80 | id: extract_release
|
81 |
|
82 | run: |
|
83 | VERSION="${{ github.ref }}"
|
84 | VERSION=${VERSION##*/v}
|
85 | echo "::set-output name=VERSION::$VERSION"
|
86 | BODY=$(git show -s --format=%b)
|
87 | BODY="${BODY//'%'/'%25'}"
|
88 | BODY="${BODY//$'\n'/'%0A'}"
|
89 | BODY="${BODY//$'\r'/'%0D'}"
|
90 | echo "::set-output name=BODY::$BODY"
|
91 |
|
92 | - name: Install dependencies
|
93 | run: npm ci
|
94 |
|
95 | - name: Create a clean build
|
96 | run: npm run build
|
97 |
|
98 | - name: Publish package to npm
|
99 | run: |
|
100 | npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
|
101 | npm whoami
|
102 | npm publish
|
103 |
|
104 | - name: Create Github Release
|
105 | uses: actions/create-release@v1
|
106 | env:
|
107 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
108 | with:
|
109 | tag_name: ${{ github.ref }}
|
110 | release_name: Release v${{ steps.extract_release.outputs.VERSION }}
|
111 | draft: false
|
112 |
|
113 | prerelease: ${{ contains(steps.extract_release.outputs.VERSION, '-') }}
|
114 | body: ${{ steps.extract_release.outputs.BODY }}
|