forked from BetonQuest/BetonQuest
-
Notifications
You must be signed in to change notification settings - Fork 0
461 lines (436 loc) · 19.1 KB
/
build.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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
name: Build
on: [ push, pull_request ]
jobs:
prepare:
name: Prepare Build Variables
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.save_version.outputs.version }}
VERSION_TYPE: ${{ steps.save_type.outputs.version_type }}
PREVIOUS_VERSION_TAG: ${{ steps.save_tag.outputs.previous_version_tag }}
CHANGES_IN_DOCS_ONLY: ${{ steps.save_changes.outputs.changes_in_docs_only }}
steps:
- name: Validate that a fork does not create a version tag
if: "github.repository != 'BetonQuest/BetonQuest' && startsWith(github.ref,'refs/tags/v')"
run: |
echo "Version tags are not supported in forks!"
exit 1
- name: Checkout source code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Read version from pom.xml
run: |
MAVEN_VERSION="$(mvn help:evaluate -Dexpression=revision -q -DforceStdout)"
echo "MAVEN_VERSION=$MAVEN_VERSION" >> $GITHUB_ENV
echo "Collected the pom.xml version. The version is '$MAVEN_VERSION'"
- name: Get the previous build-number tag from Development Build
id: save_tag
if: "github.repository == 'BetonQuest/BetonQuest' && ( github.ref == 'refs/heads/main' || startsWith(github.ref,'refs/heads/main_v') || startsWith(github.ref,'refs/tags/v') )"
run: |
PREVIOUS_VERSION_TAG="$(git tag -l ${MAVEN_VERSION}-build-number-* | head -n 1)"
echo "PREVIOUS_VERSION_TAG=$PREVIOUS_VERSION_TAG" >> $GITHUB_ENV
echo "previous_version_tag=$PREVIOUS_VERSION_TAG" >> $GITHUB_OUTPUT
echo "Collected the previous build-number tag. The tag is '$PREVIOUS_VERSION_TAG'"
- name: Check for difference in docs only
id: save_changes
if: "github.repository == 'BetonQuest/BetonQuest' && ( github.ref == 'refs/heads/main' || startsWith(github.ref,'refs/heads/main_v') )"
run: |
DIFF_OUTSIDE="$(git diff --quiet ${PREVIOUS_VERSION_TAG} -- . ':(exclude)docs/' && echo Nothing || echo Changes)"
DIFF_INSIDE="$(git diff --quiet ${PREVIOUS_VERSION_TAG} -- docs/ && echo Nothing || echo Changes)"
if [[ $DIFF_OUTSIDE == Nothing && $DIFF_INSIDE == Changes ]]; then CHANGES_IN_DOCS_ONLY=true; else CHANGES_IN_DOCS_ONLY=false; fi
echo "CHANGES_IN_DOCS_ONLY=$CHANGES_IN_DOCS_ONLY" >> $GITHUB_ENV
echo "changes_in_docs_only=$CHANGES_IN_DOCS_ONLY" >> $GITHUB_OUTPUT
echo "Check for difference in docs only. The value is '$CHANGES_IN_DOCS_ONLY'"
- name: Generate build number for Development Build
if: "github.repository == 'BetonQuest/BetonQuest' && ( github.ref == 'refs/heads/main' || startsWith(github.ref,'refs/heads/main_v') ) && env.CHANGES_IN_DOCS_ONLY == 'false'"
uses: onyxmueller/build-tag-number@v1
with:
token: ${{ secrets.github_token }}
prefix: ${{ env.MAVEN_VERSION }}
- name: Set version for 'Release Build'
if: "startsWith(github.ref,'refs/tags/v')"
run: |
TAG_VERSION="${GITHUB_REF#*/*/}"
echo "Collected the tag version. The version is '$TAG_VERSION'"
if [ ${TAG_VERSION:1} != $MAVEN_VERSION ]; then echo "::error::The version of the tag and the version of the pom are not equal! Tag is '$TAG_VERSION' and pom is '$MAVEN_VERSION'."; exit 1; fi
echo "MAVEN_VERSION=$MAVEN_VERSION" >> $GITHUB_ENV
echo "VERSION_TYPE=release" >> $GITHUB_ENV
- name: Set version for 'Development Build'
if: "github.repository == 'BetonQuest/BetonQuest' && ( github.ref == 'refs/heads/main' || startsWith(github.ref,'refs/heads/main_v') )"
run: |
if [ $CHANGES_IN_DOCS_ONLY == true ]; then MAVEN_VERSION=${PREVIOUS_VERSION_TAG/build-number/DEV}; else MAVEN_VERSION=${MAVEN_VERSION}-DEV-${BUILD_NUMBER}; fi
echo "MAVEN_VERSION=$MAVEN_VERSION" >> $GITHUB_ENV
echo "VERSION_TYPE=development" >> $GITHUB_ENV
- name: Set version for 'Artifact Build'
if: "github.repository != 'BetonQuest/BetonQuest' || !startsWith(github.ref,'refs/tags/v') && github.ref != 'refs/heads/main' && !startsWith(github.ref,'refs/heads/main_v')"
run: |
if [ ${{ github.repository }} != 'BetonQuest/BetonQuest' ]; then REPO=${{ github.repository }}-; fi
MAVEN_VERSION=${MAVEN_VERSION}-DEV-ARTIFACT-${REPO}${{ github.run_number }}
echo "MAVEN_VERSION=$MAVEN_VERSION" >> $GITHUB_ENV
echo "VERSION_TYPE=artifact" >> $GITHUB_ENV
- name: Save version to output variable
id: save_version
run: |
echo "The version is '$MAVEN_VERSION'"
echo "version=$MAVEN_VERSION" >> $GITHUB_OUTPUT
- name: Save version type to output variable
id: save_type
run: |
echo "The version type is '$VERSION_TYPE'"
echo "version_type=$VERSION_TYPE" >> $GITHUB_OUTPUT
build-artifacts:
name: Build Artifacts
needs: [ prepare ]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.prepare.outputs.VERSION }}
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }}
PREVIOUS_VERSION_TAG: ${{ needs.prepare.outputs.PREVIOUS_VERSION_TAG }}
CHANGES_IN_DOCS_ONLY: ${{ needs.prepare.outputs.CHANGES_IN_DOCS_ONLY }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Setup JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
cache: 'maven'
- name: Cache target/artifacts
uses: actions/cache@v3
with:
path: target/artifacts
key: ${{ runner.os }}-target/artifacts-${{ github.run_number }}
- name: Set CHANGELOG.md version
run: |
sed -i "s~## \[Unreleased\]~## \[${VERSION}\]~g" ./CHANGELOG.md
- name: Set plugin version
run: |
sed -i "s~\${betonquest\.version}~${VERSION}~g" ./src/main/resources/plugin.yml
- name: Set pom.xml BetonQuest version
if: "env.VERSION_TYPE == 'development'"
run: |
mvn versions:set-property -DgenerateBackupPoms=false -Dproperty=betonquest.version -DnewVersion="$VERSION"
- name: Activate lf line ending check in editorconfig
run: |
sed -i "s~#end_of_line = ~end_of_line = ~g" ./.editorconfig
- name: Build with Maven. Phase 'verify'
run: |
if [ $VERSION_TYPE == 'release' ]; then CHANGELIST=-Dchangelist=; fi
mvn $CHANGELIST -P Test-All -B verify
git diff > target/artifacts/changes.patch
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: BetonQuest-Artifacts
path: |
target/artifacts/BetonQuest.jar
target/artifacts/betonquest-*-*.jar
build-docs:
name: Build Docs
needs: [ prepare ]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.prepare.outputs.VERSION }}
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }}
PREVIOUS_VERSION_TAG: ${{ needs.prepare.outputs.PREVIOUS_VERSION_TAG }}
CHANGES_IN_DOCS_ONLY: ${{ needs.prepare.outputs.CHANGES_IN_DOCS_ONLY }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Create LFS file list
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
- name: Restore LFS cache
uses: actions/cache@v3
id: lfs-cache
with:
path: .git/lfs
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}-v1
- name: Git LFS Pull
run: git lfs pull
- name: Select mkDocs requirements
run: |
[ -z $MKDOCS_MATERIAL_INSIDERS ] && TXT=docs-requirements.txt || TXT=docs-requirements-insiders.txt
echo "TXT=$TXT" >> $GITHUB_ENV
env:
MKDOCS_MATERIAL_INSIDERS: ${{ secrets.MKDOCS_MATERIAL_INSIDERS }}
- name: Setup Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
architecture: 'x64'
cache: 'pip'
cache-dependency-path: '**/config/${{ env.TXT }}'
- name: Cache target/docs
uses: actions/cache@v3
with:
path: target/docs
key: ${{ runner.os }}-target/docs-${{ github.run_number }}
- name: Cache target/docs/.cache/plugins/optimize
uses: actions/cache@v3
with:
path: target/docs/.cache/plugins/optimize
key: ${{ runner.os }}-hardcoded-media-cache
- name: Install pngquant, a CI only dependency for mkdocs-material image optimization
uses: awalsh128/[email protected]
with:
packages: pngquant
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip install -r ./config/$TXT
env:
MKDOCS_MATERIAL_INSIDERS: ${{ secrets.MKDOCS_MATERIAL_INSIDERS }}
- name: Set CHANGELOG.md version
run: |
sed -i "s~## \[Unreleased\]~## \[${VERSION}\]~g" ./CHANGELOG.md
DATE="$(date +%Y-%m-%d)"
sed -i "s~\${maven\.build\.timestamp}~$DATE~g" ./CHANGELOG.md
echo "$(cat ./CHANGELOG.md)" >> './docs/Documentation/CHANGELOG.md'
- name: Set user feedback form version in mkdocs.yml
run: |
sed -i "s~%VERSION%~${VERSION}~g" ./mkdocs.yml
- name: Set secret in downloads.js script
run: |
sed -i "s~\${REPOSITORY_URL}~$REPOSITORY_URL~g" ./docs/_webCode/js/downloads.js
env:
REPOSITORY_URL: ${{ vars.REPOSITORY_URL }}
- name: Build with mkdocs
run: |
if [ "$TXT" = "docs-requirements-insiders.txt" ]
then
mkdocs build --config-file mkdocs.insiders.yml
else
mkdocs build --config-file mkdocs.yml
fi
git diff > target/docs/changes.patch
env:
ANALYTICS_PROPERTY: ${{ vars.ANALYTICS_PROPERTY }}
- name: Upload Docs
uses: actions/upload-artifact@v3
with:
name: BetonQuest-Docs
path: |
target/docs/
!target/docs/changes.patch
deploy-artifacts:
name: Deploy Artifacts
if: "needs.prepare.outputs.VERSION_TYPE == 'release' || needs.prepare.outputs.VERSION_TYPE == 'development' && needs.prepare.outputs.CHANGES_IN_DOCS_ONLY == 'false'"
needs: [ prepare, build-artifacts, build-docs ]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.prepare.outputs.VERSION }}
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }}
PREVIOUS_VERSION_TAG: ${{ needs.prepare.outputs.PREVIOUS_VERSION_TAG }}
CHANGES_IN_DOCS_ONLY: ${{ needs.prepare.outputs.CHANGES_IN_DOCS_ONLY }}
outputs:
UPLOAD_PATH: ${{ steps.save_upload_path.outputs.upload_path }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Setup JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
cache: 'maven'
- name: Cache target/artifacts
uses: actions/cache@v3
with:
path: target/artifacts
key: ${{ runner.os }}-target/artifacts-${{ github.run_number }}
- name: Load patch file
run: |
git apply target/artifacts/changes.patch
rm target/artifacts/changes.patch
- name: Set mirror for all repositories in settings.xml
uses: whelk-io/maven-settings-xml-action@v21
with:
servers: |
[
{
"id": "betonquest",
"username": "${env.REPOSITORY_USER}",
"password": "${env.REPOSITORY_PASS}",
"configuration": {
"httpConfiguration": {
"all": {
"usePreemptive": "true"
}
}
}
}
]
- name: Publish to Maven Repository
run: |
if [ $VERSION_TYPE == 'release' ]; then CHANGELIST=-Dchangelist=; fi
mvn $CHANGELIST -P Skip-Verification,Test-None -B deploy | tee maven-deploy.log
env:
REPOSITORY_URL: ${{ vars.REPOSITORY_URL }}
REPOSITORY_USER: ${{ secrets.REPOSITORY_USER }}
REPOSITORY_PASS: ${{ secrets.REPOSITORY_PASS }}
- name: Get upload URL from deploy log
id: save_upload_path
run: |
UPLOAD_PATH="$(grep -oP "(?<=Uploading to betonquest: $REPOSITORY_URL).*-shaded.jar" maven-deploy.log)"
echo "upload_path=$UPLOAD_PATH" >> $GITHUB_OUTPUT
env:
REPOSITORY_URL: ${{ vars.REPOSITORY_URL }}
deploy-docs:
name: Deploy Docs
concurrency: gh-pages-deploy
if: "needs.prepare.outputs.VERSION_TYPE == 'release' || needs.prepare.outputs.VERSION_TYPE == 'development'"
needs: [ prepare, build-artifacts, build-docs ]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.prepare.outputs.VERSION }}
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }}
PREVIOUS_VERSION_TAG: ${{ needs.prepare.outputs.PREVIOUS_VERSION_TAG }}
CHANGES_IN_DOCS_ONLY: ${{ needs.prepare.outputs.CHANGES_IN_DOCS_ONLY }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Create LFS file list
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
- name: Restore LFS cache
uses: actions/cache@v3
id: lfs-cache
with:
path: .git/lfs
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}-v1
- name: Git LFS Pull
run: git lfs pull
- name: Select mkDocs requirements
run: |
[ -z $MKDOCS_MATERIAL_INSIDERS ] && TXT=docs-requirements.txt || TXT=docs-requirements-insiders.txt
echo "TXT=$TXT" >> $GITHUB_ENV
env:
MKDOCS_MATERIAL_INSIDERS: ${{ secrets.MKDOCS_MATERIAL_INSIDERS }}
- name: Setup Python 3.10
uses: actions/setup-python@v4
with:
python-version: '3.10'
architecture: 'x64'
cache: 'pip'
cache-dependency-path: '**/config/${{ env.TXT }}'
- name: Cache target/docs
uses: actions/cache@v3
with:
path: target/docs
key: ${{ runner.os }}-target/docs-${{ github.run_number }}
- name: Cache target/docs/.cache/plugins/optimize
uses: actions/cache@v3
with:
path: target/docs/.cache/plugins/optimize
key: ${{ runner.os }}-hardcoded-media-cache
- name: Install pngquant, a CI only dependency for mkdocs-material image optimization
uses: awalsh128/[email protected]
with:
packages: pngquant
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip install -r ./config/$TXT
env:
MKDOCS_MATERIAL_INSIDERS: ${{ secrets.MKDOCS_MATERIAL_INSIDERS }}
- name: Load patch file
run: |
git apply target/docs/changes.patch
rm target/docs/changes.patch
- name: Deploy to Github Pages
if: "env.VERSION_TYPE == 'release' || env.VERSION_TYPE == 'development'"
run: |
git config --global user.name "BetonQuest-Bot"
git config --global user.email "[email protected]"
IFS='.' read -r major minor _ <<< "$VERSION"
TWO_DIGIT_VERSION="$major.$minor"
FLAGS=(--push --update-aliases)
VERSION=()
if [ "$TXT" = "docs-requirements-insiders.txt" ]; then FLAGS+=(--config-file mkdocs.insiders.yml); fi
if [ "$VERSION_TYPE" = release ]; then
VERSION+=("$TWO_DIGIT_VERSION" "$TWO_DIGIT_VERSION-DEV")
if [ ${{ github.ref }} == 'refs/heads/main' ] || { mike list --json "$TWO_DIGIT_VERSION" | grep -q '"aliases" *: *\[[^]]*"RELEASE"'; }; then
VERSION+=(RELEASE)
fi
elif [ "$VERSION_TYPE" = development ]; then
VERSION+=("$TWO_DIGIT_VERSION-DEV")
if ! { mike list --json | grep -q "\"version\" *: *\"$TWO_DIGIT_VERSION\""; }; then
VERSION+=("$TWO_DIGIT_VERSION")
fi
fi
if [ ${{ github.ref }} == 'refs/heads/main' ]; then VERSION+=(DEV); fi
if [ "$VERSION_TYPE" = release ]; then
mike delete "$TWO_DIGIT_VERSION-DEV"
fi
mike deploy "${FLAGS[@]}" "${VERSION[@]}"
create-release:
name: Create GitHub Release
if: "needs.prepare.outputs.VERSION_TYPE == 'release' && needs.deploy-artifacts.result == 'success' && needs.deploy-docs.result == 'success'"
needs: [ prepare, deploy-artifacts, deploy-docs ]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.prepare.outputs.VERSION }}
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }}
PREVIOUS_VERSION_TAG: ${{ needs.prepare.outputs.PREVIOUS_VERSION_TAG }}
CHANGES_IN_DOCS_ONLY: ${{ needs.prepare.outputs.CHANGES_IN_DOCS_ONLY }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Cache target/artifacts
uses: actions/cache@v3
with:
path: target/artifacts
key: ${{ runner.os }}-target/artifacts-${{ github.run_number }}
- name: Cache target/docs
uses: actions/cache@v3
with:
path: target/docs
key: ${{ runner.os }}-target/docs-${{ github.run_number }}
- name: Zip Docs
run: |
zip -r target/docs/Docs.zip target/docs/
- name: Set CHANGELOG.md version
run: |
sed -i "s~## \[Unreleased\]~## \[${VERSION}\]~g" ./CHANGELOG.md
DATE="$(date +%Y-%m-%d)"
sed -i "s~\${maven\.build\.timestamp}~$DATE~g" ./CHANGELOG.md
- name: Create release
uses: docker://antonyurchenko/git-release:latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DRAFT_RELEASE: false
PRE_RELEASE: false
CHANGELOG_FILE: CHANGELOG.md
RELEASE_NAME: BetonQuest ${{ env.VERSION }}
with:
args: |
target/artifacts/BetonQuest.jar
target/docs/Docs.zip
- name: Delete obsolete git tag
run: |
git push origin :${PREVIOUS_VERSION_TAG}
discord-announcement:
name: Official Deployment
if: "always() && !cancelled() && ( needs.prepare.outputs.VERSION_TYPE == 'release' || needs.prepare.outputs.VERSION_TYPE == 'development' && ( needs.prepare.outputs.CHANGES_IN_DOCS_ONLY == 'false' || failure() ) )"
needs: [ prepare, deploy-artifacts, deploy-docs, create-release ]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.prepare.outputs.VERSION }}
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }}
PREVIOUS_VERSION_TAG: ${{ needs.prepare.outputs.PREVIOUS_VERSION_TAG }}
CHANGES_IN_DOCS_ONLY: ${{ needs.prepare.outputs.CHANGES_IN_DOCS_ONLY }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Publish to Discord
if: "always() && !cancelled()"
run: |
bash .github/scripts/discord.sh
env:
JOB_STATUS: ${{ job.status }}
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
DOCS_URL: ${{ vars.DOCS_URL }}
UPLOAD_PATH: ${{ needs.deploy-artifacts.outputs.UPLOAD_PATH }}