generated from JS-DevTools/template-node-typescript
-
Notifications
You must be signed in to change notification settings - Fork 74
223 lines (185 loc) · 5.5 KB
/
ci-cd.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
name: CI-CD
on:
pull_request:
branches:
- main
push:
branches:
- main
# run CI every Monday at 12:25 UTC
schedule:
- cron: "25 12 * * 1"
jobs:
test:
name: Unit tests / Node.js ${{ matrix.node-version }} / ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
node-version:
- 16
- 18
- 20
steps:
- name: Checkout source
uses: actions/checkout@v3
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: npm
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm run coverage
- name: Send code coverage results to Coveralls
uses: coverallsapp/github-action@95b1a2355bd0e526ad2fd62da9fd386ad4c98474
with:
parallel: true
flag-name: Node.js ${{ matrix.node-version }} / ${{ matrix.os }}
coverage:
name: Code Coverage
runs-on: ubuntu-latest
timeout-minutes: 10
needs: test
steps:
- name: Let Coveralls know that all tests have finished
uses: coverallsapp/github-action@95b1a2355bd0e526ad2fd62da9fd386ad4c98474
with:
parallel-finished: true
build:
name: Build and lint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout source
uses: actions/checkout@v3
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
cache: npm
- name: Install development dependencies
run: npm ci
- name: Build
run: npm run build
- name: Verify no un-staged changes
run: |
git status --porcelain
git diff-files --quiet
- name: Run lints
run: npm run lint
- name: Upload publish artifact
uses: actions/upload-artifact@v3
with:
name: publish-artifact
path: lib
e2e:
name: E2E tests / Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
timeout-minutes: 10
needs: build
strategy:
fail-fast: false
matrix:
node-version:
- 16
- 18
- 20
services:
verdaccio:
image: verdaccio/verdaccio:5
ports:
- 4873:4873
steps:
- name: Checkout source
uses: actions/checkout@v3
- name: Install Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install production dependencies
run: npm install --production
- name: Download publish artifact
uses: actions/download-artifact@v3
with:
name: publish-artifact
path: lib
- id: setup
name: Login to local registry and set up fixture package
shell: bash
run: |
echo "token=$(./e2e/00-login.sh)" >> "$GITHUB_OUTPUT"
echo "package=$(./e2e/01-setup-package.sh ./e2e/fixture/cool\ package 0.0.1)" >> "$GITHUB_OUTPUT"
- name: Run CLI end-to-end test
shell: bash
env:
TOKEN: ${{ steps.setup.outputs.token }}
PACKAGE: ${{ steps.setup.outputs.package }}
run: |
./e2e/02-publish.sh "${PACKAGE}" ${TOKEN}
./e2e/03-verify.sh "${PACKAGE}"
./e2e/02-publish.sh "${PACKAGE}" ${TOKEN}
./e2e/01-setup-package.sh "${PACKAGE}" 0.0.2
./e2e/02-publish.sh "${PACKAGE}" ${TOKEN}
./e2e/03-verify.sh "${PACKAGE}"
- id: action-no-publish
name: Publish with already published version
uses: ./
with:
registry: http://localhost:4873
package: ${{ steps.setup.outputs.package }}/package.json
token: ${{ steps.setup.outputs.token }}
- name: Check action output
if: ${{ steps.action-no-publish.outputs.type }}
run: |
echo "::error::Expected release type to be '', got '${{ steps.action-no-publish.outputs.type }}'"
exit 1
- name: Create new version for Action end-to-end test
shell: bash
run: ./e2e/01-setup-package.sh "${{ steps.setup.outputs.package }}" 0.0.3
- id: action-publish
name: Publish a new version
uses: ./
with:
registry: http://localhost:4873
package: ${{ steps.setup.outputs.package }}/package.json
token: ${{ steps.setup.outputs.token }}
- name: Check release output
if: ${{ steps.action-publish.outputs.type != 'patch' }}
run: |
echo "::error::Expected release type to be 'patch', got '${{ steps.action-publish.outputs.type }}'"
exit 1
deploy:
if: ${{ github.ref == 'refs/heads/main' }}
name: Publish
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
id-token: write
needs:
- test
- build
- e2e
steps:
- name: Checkout source
uses: actions/checkout@v3
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Download publish artifact
uses: actions/download-artifact@v3
with:
name: publish-artifact
path: lib
- name: Publish to NPM
uses: ./
with:
token: ${{ secrets.NPM_TOKEN }}