-
Notifications
You must be signed in to change notification settings - Fork 3
303 lines (276 loc) · 11.2 KB
/
test.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
name: Test
on: [push, pull_request, pull_request_target]
jobs:
variables:
runs-on: ubuntu-latest
outputs:
ref: ${{ steps.variables.outputs.ref }}
sha: ${{ steps.variables.outputs.sha }}
sha8: ${{ steps.variables.outputs.sha8 }}
date: ${{ steps.variables.outputs.date }}
version: ${{ steps.variables.outputs.version }}
build_branch: ${{ steps.variables.outputs.build_branch }}
deploy_branch: ${{ steps.variables.outputs.deploy_branch }}
ghpr_docker_image_fqn: ${{ steps.variables.outputs.ghpr_docker_image_fqn }}
ghpr_docker_image_tag: ${{ steps.variables.outputs.docker_image_tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: gittools/actions/gitversion/setup@v0.10.2
with:
versionSpec: "5.x.x"
- id: gitversion
uses: gittools/actions/gitversion/execute@v0.10.2
- id: variables
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: ./.github/scripts/variables.sh ${{ steps.gitversion.outputs.fullSemVer }}
hadolint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: haya14busa/action-cond@v1
id: reporter
with:
cond: ${{ github.event_name == 'pull_request' }}
if_true: github-pr-review
if_false: github-check
- uses: reviewdog/action-hadolint@v1
with:
fail_on_error: true
level: warning
reporter: ${{ steps.reporter.outputs.value }}
verify-bash:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: ShellCheck
uses: bewuethr/shellcheck-action@v2
- name: Control Character Check
run: ./.github/scripts/control_character_finder.sh
docker-build:
runs-on: ubuntu-latest
needs: variables
# If the PR is coming from a fork (pull_request_target), ensure it's opened by "dependabot[bot]".
# Otherwise, clone it normally.
if: |
(github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]') ||
(github.event_name != 'pull_request_target' && github.actor != 'dependabot[bot]')
steps:
- uses: actions/checkout@v4
if: ${{ github.event_name != 'pull_request_target' }}
- uses: actions/checkout@v4
if: ${{ github.event_name == 'pull_request_target' }}
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Build Docker Image
uses: whoan/docker-build-with-cache-action@v8.0.0
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: docker.pkg.github.com
image_name: jekyll-plantuml
image_tag: ${{ needs.variables.outputs.sha8 }}
dockerfile: .docker/Dockerfile
push_image_and_stages: true
pull_image_and_stages: true
build_extra_args: --build-arg SHA=${{ needs.variables.outputs.sha }} --build-arg TAG=${{ needs.variables.outputs.sha8 }} --build-arg DATE=${{ needs.variables.outputs.date }} --build-arg VERSION=${{ needs.variables.outputs.version }}
test-serve:
runs-on: ubuntu-latest
needs: [variables, docker-build]
steps:
- uses: actions/checkout@v4
- name: Run Docker Image (serve)
run: |
timeout --preserve-status 10m \
./.github/scripts/docker_run_test.sh \
serve \
--image ${{ needs.variables.outputs.ghpr_docker_image_fqn }} \
--image-tag ${{ needs.variables.outputs.ghpr_docker_image_tag }} \
--repository ${{ github.repository }} \
--dir ${{ github.workspace }}/tests/full \
--token ${{ secrets.GITHUB_TOKEN }} \
--verbose
test-serve-no-gemfile:
runs-on: ubuntu-latest
needs: [variables, docker-build]
steps:
- uses: actions/checkout@v4
- name: Run Docker Image (serve, no Gemfile)
run: |
timeout --preserve-status 10m \
./.github/scripts/docker_run_test.sh \
serve \
--image ${{ needs.variables.outputs.ghpr_docker_image_fqn }} \
--image-tag ${{ needs.variables.outputs.ghpr_docker_image_tag }} \
--repository ${{ github.repository }} \
--dir ${{ github.workspace }}/tests/minimal \
--token ${{ secrets.GITHUB_TOKEN }} \
--verbose
test-build:
runs-on: ubuntu-latest
needs: [variables, docker-build]
steps:
- uses: actions/checkout@v4
- name: Run Docker Image (build)
run: |
./.github/scripts/docker_run_test.sh \
build \
--image ${{ needs.variables.outputs.ghpr_docker_image_fqn }} \
--image-tag ${{ needs.variables.outputs.ghpr_docker_image_tag }} \
--repository ${{ github.repository }} \
--dir ${{ github.workspace }}/tests/full \
--token ${{ secrets.GITHUB_TOKEN }} \
--verbose
test-build-no-gemfile:
runs-on: ubuntu-latest
needs: [variables, docker-build]
steps:
- uses: actions/checkout@v4
- name: Run Docker Image (build, no Gemfile)
run: |
./.github/scripts/docker_run_test.sh \
build \
--image ${{ needs.variables.outputs.ghpr_docker_image_fqn }} \
--image-tag ${{ needs.variables.outputs.ghpr_docker_image_tag }} \
--repository ${{ github.repository }} \
--dir ${{ github.workspace }}/tests/minimal \
--token ${{ secrets.GITHUB_TOKEN }} \
--verbose
test-build-gemspec:
runs-on: ubuntu-latest
needs: [variables, docker-build]
steps:
- uses: actions/checkout@v4
- name: Run Docker Image (build with gemspec)
run: |
./.github/scripts/docker_run_test.sh \
build \
--image ${{ needs.variables.outputs.ghpr_docker_image_fqn }} \
--image-tag ${{ needs.variables.outputs.ghpr_docker_image_tag }} \
--repository ${{ github.repository }} \
--dir ${{ github.workspace }}/tests/gemspec \
--token ${{ secrets.GITHUB_TOKEN }} \
--verbose
rspec:
runs-on: ubuntu-latest
env:
working-directory: .docker/entrypoint
defaults:
run:
working-directory: ${{ env.working-directory }}
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
bundler-cache: true
working-directory: ${{ env.working-directory }}
- run: bundle exec rake
- name: codecov
run: bundle exec rake codecov:upload || echo 'Codecov upload failed'
- name: rubocop
run: bundle exec rubocop --fail-level warning --display-only-fail-level-offenses
verify-output:
runs-on: ubuntu-latest
needs: [variables, docker-build]
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
bundler-cache: true
- name: Verify build output
env:
IMAGE_FQN: docker.pkg.github.com/swedbankpay/jekyll-plantuml-docker/jekyll-plantuml:${{ needs.variables.outputs.sha8 }}
run: |
docker login https://docker.pkg.github.com -u ${{ github.repository_owner }} -p "${{ secrets.GITHUB_TOKEN }}"
docker pull "${IMAGE_FQN}"
docker run \
--volume $(pwd)/tests/full:/srv/jekyll \
--env DEBUG=true \
--env GITHUB_BRANCH=${{ needs.variables.outputs.build_branch }} \
--env GITHUB_REPOSITORY_URL=${{ github.event.repository.html_url }} \
"${IMAGE_FQN}" \
build \
--verify \
--env=production \
--log-level=debug \
--site-url=https://example.com/ \
--ignore-url '%r{[/.]?page1}' \
--ignore-url http://www.wikipedia.org \
--ignore-url '%r{https://github.com/SwedbankPay/jekyll-plantuml-docker/tree/.*}' \
--ignore-url https://example.com/link.html
- name: Verify site URL
run: grep 'https://example.com/' ${{ github.workspace }}/tests/full/_site/index.html
- name: Verify GitHub repository URL
run: grep '${{ github.event.repository.html_url }}' ${{ github.workspace }}/tests/full/_site/index.html
- name: Upload build output artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: verify-output-verify-html
path: tests/full/_site/*.html
- name: Build
env:
IMAGE_FQN: docker.pkg.github.com/swedbankpay/jekyll-plantuml-docker/jekyll-plantuml:${{ needs.variables.outputs.sha8 }}
run: |
docker login https://docker.pkg.github.com -u ${{ github.repository_owner }} -p "${{ secrets.GITHUB_TOKEN }}"
docker pull "${IMAGE_FQN}"
docker run \
--volume $(pwd)/tests/full:/srv/jekyll \
--env DEBUG=true \
--env GITHUB_BRANCH=${{ needs.variables.outputs.build_branch }} \
--env GITHUB_REPOSITORY_URL=${{ github.event.repository.html_url }} \
"${IMAGE_FQN}" \
build \
--env=production \
--log-level=debug \
--site-url=https://swedbankpay.github.io/jekyll-plantuml-docker/
- name: Verify base URL
run: grep 'https://swedbankpay.github.io/jekyll-plantuml-docker/' ${{ github.workspace }}/tests/full/_site/index.html
- name: Upload build output artifacts
uses: actions/upload-artifact@v3
if: always()
with:
name: verify-output-build-html
path: tests/full/_site/*.html
test-deploy:
runs-on: ubuntu-latest
needs: [variables, docker-build]
steps:
- uses: actions/checkout@v4
- name: Test Deploy
env:
SHA8: ${{ needs.variables.outputs.sha8 }}
WORK_DIR: ${{ github.workspace }}
GIT_DEPLOY_DIR: _site
GIT_DEPLOY_BRANCH: ${{ needs.variables.outputs.deploy_branch }}
GIT_DEPLOY_REPO: https://${{ secrets.GH_PAGES_TOKEN }}@github.com/${{ github.repository }}.git
IMAGE_TAG: ${{ needs.variables.outputs.sha8 }}
IMAGE_NAME: docker.pkg.github.com/swedbankpay/jekyll-plantuml-docker/jekyll-plantuml
run: |
docker login https://docker.pkg.github.com -u ${{ github.repository_owner }} -p "${{ secrets.GITHUB_TOKEN }}"
docker pull ${IMAGE_NAME}:${IMAGE_TAG}
docker run \
--volume ${WORK_DIR}/tests/minimal:/srv/jekyll \
--env GIT_DEPLOY_DIR="${GIT_DEPLOY_DIR}" \
--env GIT_DEPLOY_BRANCH="${GIT_DEPLOY_BRANCH}" \
--env GIT_DEPLOY_REPO="${GIT_DEPLOY_REPO}" \
--env PAGES_REPO_NWO="${{ github.repository }}" \
--env JEKYLL_GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" \
--env DEBUG="true" \
${IMAGE_NAME}:${IMAGE_TAG} \
deploy \
--env=production \
--log-level=debug
cleanup:
runs-on: ubuntu-latest
needs: [test-deploy, variables]
if: always()
steps:
- uses: actions/checkout@v4
- name: Cleanup
if: always()
run: .github/scripts/cleanup.sh --branch ${{ needs.variables.outputs.deploy_branch }} --commit ${{ github.sha }} --remote --verbose