forked from BetonQuest/BetonQuest
-
Notifications
You must be signed in to change notification settings - Fork 0
322 lines (295 loc) · 12.9 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
name: Build
on: [ push, pull_request ]
jobs:
prepare:
name: Prepare Build Variables
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.version.outputs.VERSION }}
VERSION_TYPE: ${{ steps.version.outputs.VERSION_TYPE }}
VERSION_MAVEN: ${{ steps.version.outputs.VERSION_MAVEN }}
VERSION_IS_NEW: ${{ steps.version.outputs.VERSION_IS_NEW }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: BetonQuest/Workflows/.github/actions/version@main
id: version
with:
ROOT_REPOSITORY: BetonQuest/BetonQuest
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EXCLUDE_PATHS: |
docs
build-code:
name: Build Code
needs: [ prepare ]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.prepare.outputs.VERSION }}
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }}
VERSION_MAVEN: ${{ needs.prepare.outputs.VERSION_MAVEN }}
VERSION_IS_NEW: ${{ needs.prepare.outputs.VERSION_IS_NEW }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
- uses: BetonQuest/Workflows/.github/actions/setup-java-maven@main
with:
JAVA_CACHE: 'maven'
MAVEN_TARGET_DIR: 'target/artifacts'
- uses: BetonQuest/Workflows/.github/actions/replace-code-variables@main
with:
VERSION: ${{ env.VERSION }}
VERSION_TYPE: ${{ env.VERSION_TYPE }}
VERSION_NAMESPACE: "betonquest"
- name: Build with Maven. Phase 'verify'
shell: bash --noprofile --norc -euo pipefail {0}
run: |
if [ $VERSION_TYPE == 'release' ]; then CHANGELIST=-Dchangelist=; fi
./mvnw ${CHANGELIST-} -P Test-All -B verify
git diff > target/artifacts/changes.patch
- name: Upload Artifact
uses: actions/upload-artifact@v4
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 }}
VERSION_MAVEN: ${{ needs.prepare.outputs.VERSION_MAVEN }}
VERSION_IS_NEW: ${{ needs.prepare.outputs.VERSION_IS_NEW }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
submodules: ${{ env.VERSION_TYPE == 'release' || env.VERSION_TYPE == 'development' }}
- uses: BetonQuest/Workflows/.github/actions/setup-git-lfs@main
- uses: BetonQuest/Workflows/.github/actions/setup-mkdocs-material@main
with:
MKDOCS_MATERIAL_INSIDERS: ${{ secrets.MKDOCS_MATERIAL_INSIDERS }}
MKDOCS_SITE_DIR: 'target/docs'
PYTHON_CACHE: 'pip'
PYTHON_CACHE_DEPENDENCY_PATH: 'docs/setup-docs-dependencies.py'
- uses: ./.github/actions/replace-docs-variables
with:
VERSION: ${{ env.VERSION }}
VERSION_TYPE: ${{ env.VERSION_TYPE }}
VERSION_MAVEN: ${{ env.VERSION_MAVEN }}
REPOSITORY_URL: ${{ vars.REPOSITORY_URL }}
- name: Build with mkdocs
shell: bash --noprofile --norc -euo pipefail {0}
run: |
mkdocs build --strict
git diff > target/docs/changes.patch
env:
MKDOCS_MATERIAL_INSIDERS_ENABLED: ${{ secrets.MKDOCS_MATERIAL_INSIDERS != '' }}
MKDOCS_MATERIAL_INSIDERS_ENABLED_CI: ${{ secrets.MKDOCS_MATERIAL_INSIDERS != '' }}
- name: Upload Docs
uses: actions/upload-artifact@v4
with:
name: BetonQuest-Docs
path: |
target/docs/
!target/docs/changes.patch
deploy-code:
name: Deploy Code
if: "needs.prepare.outputs.VERSION_TYPE == 'release' || needs.prepare.outputs.VERSION_TYPE == 'development' && needs.prepare.outputs.VERSION_IS_NEW == 'true'"
needs: [ prepare, build-code, build-docs ]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.prepare.outputs.VERSION }}
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }}
VERSION_MAVEN: ${{ needs.prepare.outputs.VERSION_MAVEN }}
VERSION_IS_NEW: ${{ needs.prepare.outputs.VERSION_IS_NEW }}
outputs:
UPLOAD_PATH: ${{ steps.save_upload_path.outputs.upload_path }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
- uses: BetonQuest/Workflows/.github/actions/setup-java-maven@main
with:
JAVA_CACHE: 'maven'
JAVA_REPOSITORY_ID: 'betonquest'
JAVA_REPOSITORY_USER: MAVEN_SERVER_USERNAME
JAVA_REPOSITORY_PASS: MAVEN_SERVER_PASSWORD
MAVEN_TARGET_DIR: 'target/artifacts'
- name: Load patch file
shell: bash --noprofile --norc -euo pipefail {0}
run: |
git apply target/artifacts/changes.patch
rm target/artifacts/changes.patch
- name: Publish to Maven Repository
shell: bash --noprofile --norc -euo pipefail {0}
run: |
if [ $VERSION_TYPE == 'release' ]; then CHANGELIST=-Dchangelist=; fi
./mvnw ${CHANGELIST-} -P Skip-Verification,Test-None -B deploy | tee maven-deploy.log
env:
REPOSITORY_URL: ${{ vars.REPOSITORY_URL }}
MAVEN_SERVER_USERNAME: ${{ secrets.MAVEN_SERVER_USERNAME }}
MAVEN_SERVER_PASSWORD: ${{ secrets.MAVEN_SERVER_PASSWORD }}
- name: Get upload URL from deploy log
id: save_upload_path
shell: bash --noprofile --norc -euo pipefail {0}
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-code, build-docs ]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.prepare.outputs.VERSION }}
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }}
VERSION_MAVEN: ${{ needs.prepare.outputs.VERSION_MAVEN }}
VERSION_IS_NEW: ${{ needs.prepare.outputs.VERSION_IS_NEW }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: ${{ env.VERSION_TYPE == 'release' }}
token: ${{ secrets.ALL_REPOSITORIES_ACCESS_TOKEN }}
- uses: BetonQuest/Workflows/.github/actions/setup-git-lfs@main
- uses: BetonQuest/Workflows/.github/actions/setup-mkdocs-material@main
with:
MKDOCS_MATERIAL_INSIDERS: ${{ secrets.MKDOCS_MATERIAL_INSIDERS }}
MKDOCS_SITE_DIR: 'target/docs'
PYTHON_CACHE: 'pip'
PYTHON_CACHE_DEPENDENCY_PATH: 'docs/setup-docs-dependencies.py'
- name: Load patch file
shell: bash --noprofile --norc -euo pipefail {0}
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'"
shell: bash --noprofile --norc -euo pipefail {0}
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)
VERSIONS=()
if [ "$VERSION_TYPE" = release ]; then
VERSIONS+=("$TWO_DIGIT_VERSION" "$TWO_DIGIT_VERSION-DEV")
if [ -n "$(git branch -r --contains tags/v${VERSION} --remote origin/main)" ]; then
VERSIONS+=(RELEASE DEV)
elif { mike list --json "$TWO_DIGIT_VERSION" | grep -q '"aliases" *: *\[[^]]*"RELEASE"'; }; then
VERSIONS+=(RELEASE)
fi
echo "mike delete $TWO_DIGIT_VERSION-DEV"
mike delete "$TWO_DIGIT_VERSION-DEV"
elif [ "$VERSION_TYPE" = development ]; then
VERSIONS+=("$TWO_DIGIT_VERSION-DEV")
if ! { mike list --json | grep -q "\"version\" *: *\"$TWO_DIGIT_VERSION\""; }; then
VERSIONS+=("$TWO_DIGIT_VERSION")
fi
if [ ${{ github.ref }} == 'refs/heads/main' ]; then
VERSIONS+=(DEV);
OLD_DEV_VERSION=$(mike list --json DEV | awk -F\" '/version/{print $4}')
if [ "$TWO_DIGIT_VERSION-DEV" != "$OLD_DEV_VERSION" ] && [[ "$OLD_DEV_VERSION" == *"-DEV" ]]; then
echo "mike delete $OLD_DEV_VERSION"
mike delete "$OLD_DEV_VERSION"
echo "mike alias ${OLD_DEV_VERSION%-DEV} $OLD_DEV_VERSION"
mike alias ${OLD_DEV_VERSION%-DEV} $OLD_DEV_VERSION
fi
fi
fi
echo "mike deploy ${FLAGS[@]} ${VERSIONS[@]}"
mike deploy "${FLAGS[@]}" "${VERSIONS[@]}"
env:
MKDOCS_MATERIAL_INSIDERS_ENABLED: ${{ secrets.MKDOCS_MATERIAL_INSIDERS != '' }}
MKDOCS_MATERIAL_INSIDERS_ENABLED_CI: ${{ secrets.MKDOCS_MATERIAL_INSIDERS != '' }}
- name: Set version Tag for Quest-Tutorials submodule
if: "env.VERSION_TYPE == 'release'"
shell: bash --noprofile --norc -euo pipefail {0}
run: |
git config --global user.name "BetonQuest-Bot"
git config --global user.email "[email protected]"
cd docs/_tutorials/
git tag "v$VERSION"
git push origin "v$VERSION"
create-release:
name: Create GitHub Release
if: "needs.prepare.outputs.VERSION_TYPE == 'release' && needs.deploy-code.result == 'success' && needs.deploy-docs.result == 'success'"
needs: [ prepare, deploy-code, deploy-docs ]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.prepare.outputs.VERSION }}
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }}
VERSION_MAVEN: ${{ needs.prepare.outputs.VERSION_MAVEN }}
VERSION_IS_NEW: ${{ needs.prepare.outputs.VERSION_IS_NEW }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
- uses: BetonQuest/Workflows/.github/actions/setup-java-maven/cache@main
with:
MAVEN_TARGET_DIR: 'target/artifacts'
- uses: BetonQuest/Workflows/.github/actions/setup-mkdocs-material/cache@main
with:
MKDOCS_SITE_DIR: 'target/docs'
- name: Zip Docs
shell: bash --noprofile --norc -euo pipefail {0}
run: |
zip -r target/docs/Docs.zip target/docs/
- name: Set CHANGELOG.md version
shell: bash --noprofile --norc -euo pipefail {0}
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:v6
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
discord-announcement:
name: Official Deployment
if: "always() && !cancelled() && ( needs.prepare.outputs.VERSION_TYPE == 'release' || needs.prepare.outputs.VERSION_TYPE == 'development' && ( needs.prepare.outputs.VERSION_IS_NEW == 'true' || failure() ) )"
needs: [ prepare, deploy-code, deploy-docs, create-release ]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.prepare.outputs.VERSION }}
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }}
VERSION_MAVEN: ${{ needs.prepare.outputs.VERSION_MAVEN }}
VERSION_IS_NEW: ${{ needs.prepare.outputs.VERSION_IS_NEW }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Set NEEDED_JOB_STATES
if: always() && !cancelled()
shell: bash --noprofile --norc -euo pipefail {0}
run: |
if [[ "${{ needs.prepare.result }}" == "failure" || "${{ needs.deploy-code.result }}" == "failure" || "${{ needs.deploy-docs.result }}" == "failure" || "${{ needs.create-release.result }}" == "failure" ]]; then
echo "NEEDED_JOB_STATES=failure" >> $GITHUB_ENV
else
echo "NEEDED_JOB_STATES=success" >> $GITHUB_ENV
fi
- name: Publish to Discord
if: "always() && !cancelled()"
shell: bash --noprofile --norc -euo pipefail {0}
run: |
bash .github/scripts/discord.sh
env:
JOB_STATUS: ${{ env.NEEDED_JOB_STATES }}
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
DOCS_URL: ${{ vars.DOCS_URL }}
UPLOAD_PATH: ${{ needs.deploy-code.outputs.UPLOAD_PATH }}