-
Notifications
You must be signed in to change notification settings - Fork 12
202 lines (192 loc) · 6.25 KB
/
test-and-deploy-docker.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
name: Run tests
on: [push]
env:
DOCKER_IMAGE: codekie/openapi-examples-validator
DOCKER_IMAGE_TEST: codekie/openapi-examples-validator:test
PATH_DOCKERFILE: dist/Dockerfile
PATH_IMAGE_ARTIFACT: /tmp/myimage.tar
jobs:
install:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v2
- name: Prepare NodeJS environment
uses: ./.github/actions/setup-js
with:
node-version: ${{ matrix.node-version }}
build:
needs: install
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v2
- name: Prepare NodeJS environment
uses: ./.github/actions/setup-js
with:
node-version: ${{ matrix.node-version }}
- name: Build
run: npm run build
- name: Create build-artifact
uses: actions/upload-artifact@v2
with:
name: build-${{ matrix.node-version }}
path: ./dist/
retention-days: 1
test:
needs: install
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
steps:
- uses: actions/checkout@v2
- name: Prepare NodeJS environment
uses: ./.github/actions/setup-js
with:
node-version: ${{ matrix.node-version }}
- name: Build and run tests with coverage
run: npm run coverage
- name: Coveralls Parallel
uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{ secrets.github_token }}
flag-name: run-${{ matrix.node-version }}
parallel: true
finish-send-coveralls:
needs: test
runs-on: ubuntu-latest
steps:
- name: Push coverage to coveralls
uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
test-mutations:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
steps:
- uses: actions/checkout@v2
- name: Prepare NodeJS environment
uses: ./.github/actions/setup-js
with:
node-version: ${{ matrix.node-version }}
- name: Download build-artifacts
uses: actions/download-artifact@v2
with:
name: build-${{ matrix.node-version }}
path: ./dist/
- name: Run mutation tests
run: npm run test-mutations
# Build image and create artifact
docker-build:
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
needs:
- test
runs-on: ubuntu-latest
steps:
# An explicit checkout is required, due to the `file`- and `context`-option, in the "Build and export to Docker"
# See: https://github.com/docker/build-push-action/issues/51#issuecomment-724662235
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and export to Docker
uses: docker/build-push-action@v2
with:
context: .
load: true
file: ${{ env.PATH_DOCKERFILE }}
tags: ${{ env.DOCKER_IMAGE_TEST }}
outputs: type=docker,dest=${{ env.PATH_IMAGE_ARTIFACT }}
# Upload docker-image as artifact, so it can be used in succeeding jobs
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: myimage
path: ${{ env.PATH_IMAGE_ARTIFACT }}
# Test built image
docker-test:
needs:
- docker-build
runs-on: ubuntu-latest
steps:
# Get the docker-image from the artifacts and load it
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: myimage
path: /tmp
- name: Load image
run: |
docker load --input ${{ env.PATH_IMAGE_ARTIFACT }}
docker image ls -a
# Run the container
- name: Test
run: docker run --rm ${{ env.DOCKER_IMAGE_TEST }}
# Push image `latest` for every push on the default-branch and for every tag
docker-push-image:
needs:
- docker-test
runs-on: ubuntu-latest
steps:
# An explicit checkout is required, due to the `file`- and `context`-option, in the "Build and export to Docker"
# See: https://github.com/docker/build-push-action/issues/51#issuecomment-724662235
- uses: actions/checkout@v2
# Get the docker-image from the artifacts and load it (as cache for the builds)
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: myimage
path: /tmp
- name: Load image
run: |
docker load --input ${{ env.PATH_IMAGE_ARTIFACT }}
docker image ls -a
# Prepare tags, based on the metadata of the git reference
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.DOCKER_IMAGE }}
# generate Docker tags based on the following events/attributes
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}
# Log in to DockerHub
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Prepare Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
# Push, based on tags
- name: Build and push for tags
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v2
with:
context: .
file: ${{ env.PATH_DOCKERFILE }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Push `latest`, based on pushes on the default-branch
- name: Build and push for "latest"
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v2
with:
context: .
file: ${{ env.PATH_DOCKERFILE }}
push: true
tags: ${{ env.DOCKER_IMAGE }}:latest
labels: ${{ steps.meta.outputs.labels }}