UNPKG

3.21 kBYAMLView Raw
1# This is a composition of lint and test scripts
2
3name: Test and Release
4
5# Run this job on all pushes to master and pull requests
6# as well as tags with a semantic version
7on:
8 push:
9 branches:
10 - master
11 tags:
12 # normal versions
13 - "v[0-9]+.[0-9]+.[0-9]+"
14 # pre-releases
15 - "v[0-9]+.[0-9]+.[0-9]+-**"
16 pull_request: {}
17
18jobs:
19 # Runs unit tests on all supported node versions and OSes
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 # TODO: No actual tests aside from declaration checks
49 - name: Run component tests
50 run: npm test
51
52 # ===================
53
54 # Deploys the final package to NPM
55 deploy:
56 # Trigger this step only when a commit on any branch is tagged with a version number
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 # The body may be multiline, therefore we need to escape some characters
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 # Prerelease versions create prereleases on Github
113 prerelease: ${{ contains(steps.extract_release.outputs.VERSION, '-') }}
114 body: ${{ steps.extract_release.outputs.BODY }}