UNPKG

3.15 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 and pull requests
6# as well as tags with a semantic version
7on:
8 push:
9 branches:
10 - "*"
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: [12.x, 14.x, 16.x]
27 os: [ubuntu-latest, windows-latest, macos-latest]
28
29 steps:
30 - name: Checkout code
31 uses: actions/checkout@v2
32
33 - name: Use Node.js ${{ matrix.node-version }}
34 uses: actions/setup-node@v1
35 with:
36 node-version: ${{ matrix.node-version }}
37
38 - name: Install dependencies
39 run: npm ci
40
41 - name: Lint code
42 run: npm run lint
43
44 - name: Compile TypeScript code
45 run: npm run build
46
47 # TODO: No actual tests aside from declaration checks
48 - name: Run component tests
49 run: npm test
50
51 # ===================
52
53 # Deploys the final package to NPM
54 deploy:
55 # Trigger this step only when a commit on any branch is tagged with a version number
56 if: |
57 contains(github.event.head_commit.message, '[skip ci]') == false &&
58 github.event_name == 'push' &&
59 startsWith(github.ref, 'refs/tags/v')
60
61 needs: [unit-tests]
62
63 runs-on: ubuntu-latest
64 strategy:
65 matrix:
66 node-version: [14.x]
67
68 steps:
69 - name: Checkout code
70 uses: actions/checkout@v2
71
72 - name: Use Node.js ${{ matrix.node-version }}
73 uses: actions/setup-node@v1
74 with:
75 node-version: ${{ matrix.node-version }}
76
77 - name: Extract the version and commit body from the tag
78 id: extract_release
79 # The body may be multiline, therefore we need to escape some characters
80 run: |
81 VERSION="${{ github.ref }}"
82 VERSION=${VERSION##*/v}
83 echo "::set-output name=VERSION::$VERSION"
84 BODY=$(git show -s --format=%b)
85 BODY="${BODY//'%'/'%25'}"
86 BODY="${BODY//$'\n'/'%0A'}"
87 BODY="${BODY//$'\r'/'%0D'}"
88 echo "::set-output name=BODY::$BODY"
89
90 - name: Install dependencies
91 run: npm ci
92
93 - name: Create a clean build
94 run: npm run build
95
96 - name: Publish package to npm
97 run: |
98 npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
99 npm whoami
100 npm publish
101
102 - name: Create Github Release
103 uses: actions/create-release@v1
104 env:
105 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106 with:
107 tag_name: ${{ github.ref }}
108 release_name: Release v${{ steps.extract_release.outputs.VERSION }}
109 draft: false
110 # Prerelease versions create prereleases on Github
111 prerelease: ${{ contains(steps.extract_release.outputs.VERSION, '-') }}
112 body: ${{ steps.extract_release.outputs.BODY }}