-
-
Notifications
You must be signed in to change notification settings - Fork 0
141 lines (118 loc) · 4.23 KB
/
main.yml
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: main
on:
push:
branches:
- main
# Release Please needs permisisons to write commits and open PRs.
permissions:
contents: write
pull-requests: write
# We will build and test across a number of Node.js versions. Some steps only
# occur for a single Node version (such as uploading coverage) - this variable
# defines which Node version to use for these steps (which should be the current
# Node Long-Term Support version).
env:
NODE_LTS_VERSION: 20.x
jobs:
validate-main:
runs-on: ubuntu-20.04
strategy:
matrix:
node-version:
- 16.x
- 18.x
- 20.x
steps:
- name: Checkout
uses: actions/checkout@v3
# Setup the right version of Node.js.
- name: Setup Node ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: 'https://registry.npmjs.org'
# Fixup Git URLs, see:
# https://stackoverflow.com/questions/70663523/the-unauthenticated-git-protocol-on-port-9418-is-no-longer-supported
- name: Fix up git URLs
run: echo -e '[url "https://github.com/"]\n insteadOf = "git://github.com/"' >> ~/.gitconfig
if: ${{ steps.release.outputs.release_created }}
# Lint and test.
- name: install
run: npm install
- name: lint
run: npm run lint
- name: test
run: npm run test:cov
# Upload the artifacts folder.
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: build-artifacts
path: |
./artifacts/
# Only upload artifacts for the build on the LTS version (we don't
# need artifacts per node version).
if: ${{ matrix.node-version == env.NODE_LTS_VERSION }}
upload-coverage:
# The 'upload coverage' job will only run if successfully complete the
# 'validate-main' job.
needs: validate-main
runs-on: ubuntu-20.04
steps:
# The source files must be present for codecov to be upload the file list
# properly, otherwise no coverage is reported and the "unusable report"
# error is shown. Took ages to work this out.
- name: Checkout
uses: actions/checkout@v3
# Download the build artifacts.
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: build-artifacts
path: ./artifacts
# Upload coverage.
- name: Upload Coverage
uses: codecov/codecov-action@v3
with:
directory: ./artifacts/coverage
release-please:
# The 'release please' job will only run if successfully complete the
# 'validate-main' job. The deployment steps only occur if this is a release
# merge.
needs: validate-main
runs-on: ubuntu-20.04
steps:
- name: Release Please
uses: google-github-actions/release-please-action@v3
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
package-name: crosswords-js
- name: Checkout
uses: actions/checkout@v3
# Setup the right version of Node.js.
- name: Setup Node ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_LTS_VERSION }}
registry-url: 'https://registry.npmjs.org'
# Fixup Git URLs, see:
# https://stackoverflow.com/questions/70663523/the-unauthenticated-git-protocol-on-port-9418-is-no-longer-supported
- name: Fix up git URLs
run: echo -e '[url "https://github.com/"]\n insteadOf = "git://github.com/"' >> ~/.gitconfig
# Publish the module to NPM.
- name: Publish to NPM
run: |
# The 'npm publish' command will only run if an NPM_TOKEN secret is
# set. If it is not set, warn the user.
if [ "$NODE_AUTH_TOKEN" == "" ]; then
echo "The 'NPM_TOKEN' secret must be set to deploy to NPM"
exit 1
else
echo "The 'NPM_TOKEN' secret has been set - deploying to NPM..."
npm publish --access=public
fi
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
if: ${{ steps.release.outputs.release_created }}