-
Notifications
You must be signed in to change notification settings - Fork 21
307 lines (294 loc) · 8.95 KB
/
cicd.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
name: CICD
on:
pull_request:
branches:
- master
push:
branches: []
tags: 'v*'
paths:
- 'src/**/*'
- 'test/**/*'
- '.github/action/**/*'
- '.github/workflows/**/*'
- 'package*.json'
- 'tsconfig*.json'
- 'yarn.lock'
- 'Dockerfile'
- '.dockerignore'
- 'docker-entrypoint.sh'
- 'goss*.yaml'
jobs:
lint:
runs-on: ubuntu-22.04
steps:
- run: git config --global core.autocrlf false
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
check-latest: true
node-version: '18.x'
- uses: bahmutov/npm-install@v1
- run: echo yarn lint # disable for now
build:
runs-on: ubuntu-22.04
steps:
- run: git config --global core.autocrlf false
- uses: actions/checkout@v4
- uses: actions/cache@v4
id: cache
with:
path: dist/
key:
${{ runner.os }}-src-${{ hashFiles('src/**', '**/package*.json',
'**/*.lock', 'tsconfig.json') }}
- if: ${{ steps.cache.outputs.cache-hit != 'true'}}
uses: actions/setup-node@v4
with:
check-latest: true
node-version: '18.x'
- if: ${{ steps.cache.outputs.cache-hit != 'true'}}
uses: bahmutov/npm-install@v1
- if: ${{ steps.cache.outputs.cache-hit != 'true'}}
run: yarn build
- run: |
tar -cvf dist.tar dist/
tar -cvf dist.prod.tar dist/index.js dist/*.production.*.js
- uses: actions/upload-artifact@v3
with:
name: dist.prod
path: dist.prod.tar
retention-days: 7
- uses: actions/upload-artifact@v3
with:
name: dist
path: dist.tar
retention-days: 7
test:
runs-on: ubuntu-22.04
steps:
- run: git config --global core.autocrlf false
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
check-latest: true
node-version: '18.x'
- uses: bahmutov/npm-install@v1
- run: yarn test --ci --coverage --maxWorkers=2
- uses: codecov/codecov-action@v4
if: ${{ success() }}
continue-on-error: true
docker:
runs-on: ubuntu-22.04
permissions:
pull-requests: write
outputs:
config: ${{ steps.generate.outputs.config }}
builds: ${{ steps.generate.outputs.builds }}
manifests: ${{ steps.generate.outputs.manifests }}
steps:
- run: git config --global core.autocrlf false
- uses: actions/checkout@v4
- id: generate
uses: ./.github/actions/docker/buildConfig
with:
repositories: |
ghcr.io/hertzg/tesseract-server
hertzg/tesseract-server
platforms: |
linux/amd64
linux/arm64/v8
linux/arm/v7
linux/arm/v6
- uses: jwalton/gh-find-current-pr@v1
if: ${{ github.event_name != 'pull_request' }}
id: find-pr
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: marocchino/sticky-pull-request-comment@v2
if: ${{ github.event_name != 'pull_request' }}
with:
number: ${{ steps.find-pr.outputs.pr }}
message: |
# Docker build request
```json
${{ toJSON(fromJSON(steps.generate.outputs.config)) }}
```
Images are being built, please wait a few minutes before they get published. They will appear in this comment as soon as they are ready. You can follow the process by inspecting the running checks.
docker-build:
needs:
- docker
- build
runs-on: ubuntu-22.04
permissions:
packages: read
strategy:
matrix: ${{ fromJSON(needs.docker.outputs.builds) }}
fail-fast: false
steps:
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
if:
${{ github.event_name != 'pull_request' ||
github.event.pull_request.head.repo.full_name ==
'hertzg/rtl_433_docker' }}
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: docker/login-action@v3
if:
${{ github.event_name != 'pull_request' ||
github.event.pull_request.head.repo.full_name ==
'hertzg/rtl_433_docker' }}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key:
${{ runner.os }}-buildx-v2-${{ matrix.platform }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-v2-${{ matrix.platform }}
${{ runner.os }}-buildx-v2-
# Build the container
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
id: download
with:
name: dist.prod
path: ./
- run: |
tar xf dist.prod.tar
rm dist.prod.tar
- name: Build
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
build-args: |
DIST_SRC=./dist
target: prod_copy_dist
platforms: ${{ matrix.platform }}
load: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: ${{ matrix.tag }}
- uses: ishworkh/docker-image-artifact-upload@v1
with:
image: ${{ matrix.tag }}
docker-test:
needs:
- docker
- docker-build
runs-on: ubuntu-22.04
strategy:
matrix: ${{ fromJSON(needs.docker.outputs.builds) }}
fail-fast: false
steps:
- uses: docker/setup-qemu-action@v3
- uses: ishworkh/docker-image-artifact-download@v1
with:
image: ${{ matrix.tag }}
# Test that container is working
- uses: e1himself/goss-installation-action@v1.2.1
with:
version: v0.3.16
- uses: actions/checkout@v4
- run: dgoss run ${{ matrix.tag }}
docker-dive:
needs:
- docker
- docker-build
runs-on: ubuntu-22.04
strategy:
matrix: ${{ fromJSON(needs.docker.outputs.builds) }}
fail-fast: false
steps:
- uses: ishworkh/docker-image-artifact-download@v1
with:
image: ${{ matrix.tag }}
- uses: yuichielectric/dive-action@0.0.4
with:
image: ${{ matrix.tag }}
github-token: ${{ secrets.GITHUB_TOKEN }}
docker-push:
if:
${{ github.event_name != 'pull_request' ||
github.event.pull_request.head.repo.full_name == 'hertzg/rtl_433_docker'
}}
needs:
- test
- docker
- docker-test
runs-on: ubuntu-22.04
permissions:
packages: write
strategy:
matrix: ${{ fromJSON(needs.docker.outputs.builds) }}
fail-fast: false
steps:
- uses: docker/setup-buildx-action@v3
- uses: ishworkh/docker-image-artifact-download@v1
with:
image: ${{ matrix.tag }}
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- env:
LOCAL_NAME: ${{ matrix.tag }}
PUSH_NAMES: ${{ join(matrix.push, ' ') }}
run: |
for PUSH_NAME in $PUSH_NAMES; do
docker tag $LOCAL_NAME $PUSH_NAME
docker push $PUSH_NAME
done;
docker-multiarch:
needs:
- docker
- docker-push
runs-on: ubuntu-22.04
permissions:
pull-requests: write
packages: write
strategy:
matrix: ${{ fromJSON(needs.docker.outputs.manifests) }}
fail-fast: false
steps:
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- env:
DOCKER_CLI_EXPERIMENTAL: enabled
run: |
docker manifest create ${{ matrix.name }} ${{ join(matrix.images, ' ') }}
docker manifest push ${{ matrix.name }}
- uses: jwalton/gh-find-current-pr@v1
if: ${{ github.event_name != 'pull_request' }}
id: find-pr
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: marocchino/sticky-pull-request-comment@v2
if: ${{ github.event_name != 'pull_request' }}
with:
number: ${{ steps.find-pr.outputs.pr }}
append: true
message: |
## Published `${{ matrix.name }}`
```json
${{ toJSON(matrix) }}
```