-
Notifications
You must be signed in to change notification settings - Fork 17
335 lines (312 loc) · 10.9 KB
/
node-ci.prod.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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#######################################################################################################################
#
# Node CI - Production
#
# The workflow ensures quality for the build, builds the project and publishes it to the configured destinations.
# There are the following destinations:
#
# [Github Release]
# The destination is only triggered if the secret 'RELEASE_TO_GITHUB' is set to a non-empty value.
#
# [NPM]
# The destination is only triggered if the secret 'NPM_TOKEN' is provided.
#
# [Docker Hub]
# The destination is only triggered if the secrets 'DOCKER_USERNAME' and 'DOCKER_PASSWORD' are
# provided.
#
#######################################################################################################################
name: Prod Node CI
env:
node-version: 18
node-package-manager: yarn
on:
push:
branches:
- "master"
- "main"
jobs:
cache-dependencies:
runs-on: ubuntu-latest
steps:
- name: Access repository
uses: actions/checkout@v4
- uses: ./.github/actions/cache
- name: Install dependencies
run: yarn install --frozen-lockfile
prebuild:
runs-on: ubuntu-latest
needs: cache-dependencies
steps:
- name: Access repository
uses: actions/checkout@v4
- uses: ./.github/actions/cache
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
test:
runs-on: ubuntu-latest
needs: cache-dependencies
steps:
- name: Access repository
uses: actions/checkout@v4
- uses: ./.github/actions/test
validate-dependencies:
runs-on: ubuntu-latest
steps:
- name: Access repository
uses: actions/checkout@v4
- uses: ./.github/actions/validate-dependencies
bump-version:
runs-on: ubuntu-latest
needs:
- prebuild
- test
- validate-dependencies
outputs:
tag_version: ${{ steps.tag_version.outputs.new_tag || steps.tag_version.outputs.previous_tag }}
version: ${{ steps.tag_version.outputs.new_version || steps.tag_version.outputs.previous_version }}
changelog: ${{ steps.tag_version.outputs.changelog }}
bumped: ${{ steps.tag_version.outputs.new_tag != '' }}
commit_sha: ${{ steps.commit_sha.outputs.commit_sha }}
steps:
- name: Access repository
uses: actions/checkout@v4
- name: Configure committer
run: |
git config user.name "${{ github.event.pusher.name }}"
git config user.email "${{ github.event.pusher.email }}"
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: false
- name: Update package.json
if: steps.tag_version.outputs.new_tag != ''
uses: jossef/[email protected]
with:
file: package.json
field: version
value: ${{ steps.tag_version.outputs.new_version }}
- name: Update CHANGELOG.md
env:
changes: ${{ steps.tag_version.outputs.changelog }}
run: |
echo "$changes" > /tmp/tmp-changelog.md
[ -f CHANGELOG.md ] && cat CHANGELOG.md >> /tmp/tmp-changelog.md
mv /tmp/tmp-changelog.md CHANGELOG.md
- name: Commit and push changes to package.json and CHANGELOG.md
id: commit_sha
if: steps.tag_version.outputs.new_tag != ''
uses: EndBug/add-and-commit@v9
with:
add: "['package.json', 'CHANGELOG.md']"
create-pull-request-develop:
runs-on: ubuntu-latest
if: needs.bump-version.outputs.bumped == 'true'
needs:
- bump-version
steps:
- name: Access repository
uses: actions/checkout@v4
- name: Pull request to develop
id: develop
continue-on-error: true
uses: repo-sync/pull-request@v2
with:
destination_branch: "develop"
github_token: ${{ secrets.GITHUB_TOKEN }}
pr_label: "release, automated-pr"
pr_title: "Release ${{ needs.bump-version.outputs.version }} -> develop"
- name: Report status
env:
report: ${{ toJSON(steps.develop.outcome) }} - ${{ toJSON(steps.develop.conclusion) }}
run: echo $report
build:
runs-on: ubuntu-latest
needs:
- bump-version
steps:
- name: Access repository
uses: actions/checkout@v4
with:
ref: ${{ needs.bump-version.outputs.commit_sha }}
- name: Ensure commits from bump-version
run: git pull
- uses: ./.github/actions/cache
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Upload client build artifact
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}-client
path: client/dist
- name: Upload server build artifact
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}-server
path: server/dist
build-desktop:
runs-on: windows-latest
needs:
- bump-version
- build
steps:
- name: Access repository
uses: actions/checkout@v4
with:
ref: ${{ needs.bump-version.outputs.commit_sha }}
- name: Ensure commits from bump-version
run: git pull
- uses: ./.github/actions/cache
- uses: actions/download-artifact@v3
with:
name: ${{ github.event.repository.name }}-client
path: client/dist
- uses: actions/download-artifact@v3
with:
name: ${{ github.event.repository.name }}-server
path: server/dist
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build desktop
run: yarn build:desktop
- name: Upload desktop build artifact
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}-desktop
path: desktop/dist
check-github-release:
runs-on: ubuntu-latest
needs: build-desktop
outputs:
defined: ${{ steps.release.outputs.defined == 'true' }}
steps:
- name: Access repository
uses: actions/checkout@v4
- name: Check if is set to release
id: release
uses: ./.github/actions/check-secret
with:
secret: ${{ secrets.RELEASE_TO_GITHUB }}
publish-github-release:
runs-on: ubuntu-latest
if: needs.bump-version.outputs.bumped == 'true' && needs.check-github-release.outputs.defined == 'true'
needs:
- bump-version
- check-github-release
steps:
- name: Access repository
uses: actions/checkout@v4
with:
ref: ${{ needs.bump-version.outputs.commit_sha }}
- name: Ensure commits from bump-version
run: git pull
- uses: actions/download-artifact@v3
with:
name: ${{ github.event.repository.name }}-desktop
path: desktop/dist
- name: Compress artifact to zip
uses: papeloto/action-zip@v1
with:
files: dist
dest: "${{ github.event.repository.name }}-${{ needs.bump-version.outputs.version }}.zip"
- name: Create Github release with desktop exe
uses: softprops/action-gh-release@v1
with:
name: Release ${{ needs.bump-version.outputs.tag_version }}
tag_name: ${{ needs.bump-version.outputs.tag_version }}
body: ${{ needs.bump-version.outputs.changelog }}
files: |
desktop/dist/*.exe
desktop/dist/*.dmg
check-npm-token:
runs-on: ubuntu-latest
needs: build
outputs:
defined: ${{ steps.token.outputs.defined == 'true' }}
steps:
- name: Access repository
uses: actions/checkout@v4
- name: Check if has username
id: token
uses: ./.github/actions/check-secret
with:
secret: ${{ secrets.NPM_TOKEN }}
publish-npm-package:
runs-on: ubuntu-latest
if: needs.check-npm-token.outputs.defined == 'true'
needs:
- bump-version
- check-npm-token
steps:
- name: Access repository
uses: actions/checkout@v4
- name: Configure publisher
run: |
git config user.name "${{ github.event.pusher.name }}"
git config user.email "${{ github.event.pusher.email }}"
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: ${{ github.event.repository.name }}
path: dist
- uses: actions/setup-node@v3
with:
node-version: "18.x"
registry-url: "https://registry.npmjs.org"
- name: Publish package
run: yarn publish --access=public --tag latest --new-version "${{ needs.bump-version.outputs.version }}"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
check-docker-credentials:
runs-on: ubuntu-latest
needs: build
outputs:
defined: ${{ steps.username.outputs.defined == 'true' && steps.password.outputs.defined == 'true' }}
steps:
- name: Access repository
uses: actions/checkout@v4
- name: Check if has username
id: username
uses: ./.github/actions/check-secret
with:
secret: ${{ secrets.DOCKER_USERNAME }}
- name: Check if has password
id: password
uses: ./.github/actions/check-secret
with:
secret: ${{ secrets.DOCKER_PASSWORD }}
publish-docker-image:
runs-on: ubuntu-latest
if: needs.check-docker-credentials.outputs.defined == 'true'
needs:
- bump-version
- check-docker-credentials
steps:
- name: Access repository
uses: actions/checkout@v4
- name: Extract version for tags
id: version
uses: ./.github/actions/extract-version
with:
version: ${{ needs.bump-version.outputs.version }}
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
"tv2media/${{ github.event.repository.name }}:latest"
"tv2media/${{ github.event.repository.name }}:${{ steps.version.outputs.version }}"
"tv2media/${{ github.event.repository.name }}:${{ steps.version.outputs.major }}"
"tv2media/${{ github.event.repository.name }}:${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }}"