-
-
Notifications
You must be signed in to change notification settings - Fork 3
428 lines (380 loc) · 19.5 KB
/
cd.yml
File metadata and controls
428 lines (380 loc) · 19.5 KB
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
name: Continuous Deployment
on:
workflow_dispatch:
inputs:
tag:
description: 'Version of the data pack'
required: true
default: '1.0'
mc_upper:
description: 'Upper bound of Minecraft version range (exact version), e.g. "1.21.5". Leave empty to use the latest version from pack.mcmeta.'
required: false
mc_lower:
description: 'Lower bound of Minecraft version range (exact version), e.g. "1.17"'
required: false
default: '1.17'
dry_run:
description: 'If true, skip uploading steps'
required: false
default: false
type: boolean
separate_forge:
description: 'If false, separate Modrinth Forge mod version will not be uploaded'
required: false
default: true
type: boolean
jobs:
deploy:
runs-on: ubuntu-latest
name: Build and publish project
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
show-progress: false
# Determine Minecraft versions from pack.mcmeta using Spyglass API
- name: Determine Minecraft version bounds from pack.mcmeta using Spyglass API
id: determine_versions
shell: bash
run: |
set -euo pipefail
if [ -n "${{ github.event.inputs.mc_upper }}" ]; then
MC_UPPER="${{ github.event.inputs.mc_upper }}"
MC_LOWER="${{ github.event.inputs.mc_lower }}"
if [ -z "$MC_LOWER" ]; then
echo "::error:: MC_LOWER is required when MC_UPPER is provided!"
exit 1
fi
echo "Using provided Minecraft version bounds: MC_LOWER=$MC_LOWER, MC_UPPER=$MC_UPPER"
# Build ranges
MACHINE_RANGE_FABRIC=">=${MC_LOWER} <=${MC_UPPER}"
MACHINE_RANGE_FORGE="[${MC_LOWER},${MC_UPPER}]"
MACHINE_RANGE_NEOFORGE="[1.20.5,${MC_UPPER}]"
MACHINE_RANGE_PLATFORM=">=${MC_LOWER} <=${MC_UPPER}"
MC_HUMAN_VERSION_RANGE="${MC_LOWER}-${MC_UPPER}"
else
echo "::group::Determining Minecraft version bounds..."
echo "Reading supported_formats from pack.mcmeta..."
if [ -f pack.mcmeta ]; then
LOWER_DP=$(jq -r '.pack.supported_formats[0]' pack.mcmeta)
UPPER_DP=$(jq -r '.pack.supported_formats[1]' pack.mcmeta)
else
echo "::error:: pack.mcmeta file not found!"
exit 1
fi
echo "Lower data pack format: $LOWER_DP, Upper: $UPPER_DP"
echo "Fetching versions from Spyglass API..."
API_JSON=$(curl -s https://api.spyglassmc.com/mcje/versions || true)
if [ -z "$API_JSON" ] || ! echo "$API_JSON" | jq empty > /dev/null 2>&1; then
echo "::error:: Spyglass API unreachable!"
echo " Response: $API_JSON"
exit 1
fi
# Determine MC_LOWER: oldest version matching LOWER_DP
# LIMITATION: Mod loaders don't accept snapshot versions, so we assume lower pack format is a release (and not a snapshot)
MC_LOWER=$(echo "$API_JSON" | jq -r --argjson lower_dp "$LOWER_DP" '[.[] | select(.data_pack_version == $lower_dp and .type == "release")] | sort_by(.release_time | sub("\\+00:00$"; "Z") | fromdateiso8601) | .[0].id')
if [ -z "$MC_LOWER" ] || [ "$MC_LOWER" = "null" ]; then
echo "::error:: Expected a release version for pack format ($LOWER_DP), but none was found!"
exit 1
fi
# Determine MC_UPPER: newest version matching UPPER_DP
CHOSEN_UPPER_OBJ=$(echo "$API_JSON" | jq -c --argjson upper_dp "$UPPER_DP" '[.[] | select(.data_pack_version == $upper_dp)] | sort_by(.release_time | sub("\\+00:00$"; "Z") | fromdateiso8601) | reverse | .[0]')
if [ -z "$CHOSEN_UPPER_OBJ" ] || [ "$CHOSEN_UPPER_OBJ" = "null" ]; then
echo "::error:: Expected a version for pack format ($UPPER_DP), but none was found!"
exit 1
fi
MC_UPPER=$(echo "$CHOSEN_UPPER_OBJ" | jq -r '.id')
echo "Found MC_LOWER=$MC_LOWER, MC_UPPER=$MC_UPPER"
# Check if upper version is a release
CHOSEN_UPPER_TYPE=$(echo "$CHOSEN_UPPER_OBJ" | jq -r '.type')
if [ "$CHOSEN_UPPER_TYPE" != "release" ]; then
echo "Exact upper version is not a release. Attempting to find the next release version for mod version ranges..."
# Exact upper is not a release, try to find the next higher release (i.e. one with a release_time greater than the chosen upper one)
CHOSEN_TIME_NUM=$(echo "$CHOSEN_UPPER_OBJ" | jq -r '.release_time | sub("\\+00:00$"; "Z") | fromdateiso8601')
NEXT_RELEASE_OBJ=$(echo "$API_JSON" | jq -c --argjson chosen_time_num "$CHOSEN_TIME_NUM" 'map(select(.type == "release" and (.release_time | sub("\\+00:00$"; "Z") | fromdateiso8601 > $chosen_time_num))) | sort_by(.release_time | sub("\\+00:00$"; "Z") | fromdateiso8601) | .[0]')
NEXT_RELEASE=$(echo "$NEXT_RELEASE_OBJ" | jq -r '.id')
if [ -n "$NEXT_RELEASE" ] && [ "$NEXT_RELEASE" != "null" ]; then
# Next release version is available, use it as the upper bound
MACHINE_RANGE_FABRIC=">=${MC_LOWER} <${NEXT_RELEASE}"
MACHINE_RANGE_FORGE="[${MC_LOWER},${NEXT_RELEASE})"
MACHINE_RANGE_NEOFORGE="[1.20.5,${NEXT_RELEASE})"
echo "Next release version found: $NEXT_RELEASE"
else
# Next release version is not available, omit the upper bound for Fabric and Forge
MACHINE_RANGE_FABRIC=">=${MC_LOWER}"
MACHINE_RANGE_FORGE="[${MC_LOWER},)"
MACHINE_RANGE_NEOFORGE="[1.20.5,)"
echo "::error:: No next release version found, please set the upper bound manually!"
exit 1
fi
else
# Exact upper is a release, use it as the upper bound
MACHINE_RANGE_FABRIC=">=${MC_LOWER} <=${MC_UPPER}"
MACHINE_RANGE_FORGE="[${MC_LOWER},${MC_UPPER}]"
MACHINE_RANGE_NEOFORGE="[1.20.5,${MC_UPPER}]"
fi
# Use exact values for platform and human-readable version range
MACHINE_RANGE_PLATFORM=">=${MC_LOWER} <=${MC_UPPER}"
MC_HUMAN_VERSION_RANGE="${MC_LOWER}-${MC_UPPER}"
echo "::endgroup::"
fi
echo "MC_LOWER=$MC_LOWER" >> $GITHUB_ENV
echo "MC_UPPER=$MC_UPPER" >> $GITHUB_ENV
echo "MC_HUMAN_VERSION_RANGE=$MC_HUMAN_VERSION_RANGE" >> $GITHUB_ENV
echo "MACHINE_RANGE_PLATFORM=$MACHINE_RANGE_PLATFORM" >> $GITHUB_ENV
echo "MACHINE_RANGE_FABRIC=$MACHINE_RANGE_FABRIC" >> $GITHUB_ENV
echo "MACHINE_RANGE_FORGE=$MACHINE_RANGE_FORGE" >> $GITHUB_ENV
echo "MACHINE_RANGE_NEOFORGE=$MACHINE_RANGE_NEOFORGE" >> $GITHUB_ENV
echo "Determined versions:"
echo " Human range: $MC_HUMAN_VERSION_RANGE"
echo " Platform range: $MACHINE_RANGE_PLATFORM"
echo " Fabric range: $MACHINE_RANGE_FABRIC"
echo " Forge range: $MACHINE_RANGE_FORGE"
echo " NeoForge range: $MACHINE_RANGE_NEOFORGE"
# Update version info in files via find/replace actions
- name: Replace uninstall file name
uses: jacobtomlinson/gha-find-replace@v3
with:
find: "${file_name}"
replace: ${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}-datapack.zip
regex: false
include: "**uninstall.mcfunction"
- name: Set data pack version
uses: jacobtomlinson/gha-find-replace@v3
with:
find: "${version}"
replace: ${{ github.event.inputs.tag }}
regex: false
- name: Set supported Minecraft version range (Human-readable)
uses: jacobtomlinson/gha-find-replace@v3
with:
find: "${mc_human_version_range}"
replace: "${{ env.MC_HUMAN_VERSION_RANGE }}"
regex: false
- name: Set supported Minecraft version range (Fabric)
uses: jacobtomlinson/gha-find-replace@v3
with:
find: "${mc_version_range_fabric}"
replace: "${{ env.MACHINE_RANGE_FABRIC }}"
regex: false
- name: Set supported Minecraft version range (Forge)
uses: jacobtomlinson/gha-find-replace@v3
with:
find: "${mc_version_range_forge}"
replace: "${{ env.MACHINE_RANGE_FORGE }}"
regex: false
- name: Set supported Minecraft version range (NeoForge)
uses: jacobtomlinson/gha-find-replace@v3
with:
find: "${mc_version_range_neoforge}"
replace: "${{ env.MACHINE_RANGE_NEOFORGE }}"
regex: false
# Check for existence of directories
- name: Check for data folder
id: check_datapack_folder
uses: andstor/file-existence-action@v3
with:
files: "data"
- name: Check for mod folders
id: check_mod_folder
uses: andstor/file-existence-action@v3
with:
files: "META-INF, net, fabric.mod.json, assets"
- name: Check for resource pack folder
id: check_assets_folder
uses: andstor/file-existence-action@v3
with:
files: "assets/minecraft"
# Package project
- name: Create data pack zip file
uses: montudor/action-zip@v1
if: steps.check_datapack_folder.outputs.files_exists == 'true'
with:
args: zip -qq "${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}-datapack.zip" -r . -x assets/* net/* META-INF/* fabric.mod.json unused/* src/* wiki/* CHANGES.md ".*"
- name: Create mod jar file
uses: montudor/action-zip@v1
if: steps.check_mod_folder.outputs.files_exists == 'true'
with:
args: zip -qq "${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}-mod.jar" -r . -x unused/* src/* wiki/* CHANGES.md ".*" "${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}-datapack.zip"
- name: Create asset pack zip file
uses: montudor/action-zip@v1
if: steps.check_assets_folder.outputs.files_exists == 'true'
with:
args: zip -qq "${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}-resourcepack.zip" -r . -x data/* net/* META-INF/* fabric.mod.json unused/* src/* wiki/* CHANGES.md ".*" "${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}-datapack.zip" "${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}-mod.jar"
# Upload artifacts for dry run testing
- name: Upload artifacts
id: upload
uses: actions/upload-artifact@v7
if: github.event.inputs.dry_run == 'true'
with:
name: "${{ github.event.repository.name }} v${{ github.event.inputs.tag }} Test Builds (Unzip Me)"
path: |
./${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}-datapack.zip
./${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}-mod.jar
./${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}-resourcepack.zip
# Upload
- name: Upload data pack version to Modrinth
id: upload_modrinth_dp
uses: Kir-Antipov/mc-publish@v3.3
if: steps.check_datapack_folder.outputs.files_exists == 'true' && github.event.inputs.dry_run == 'false'
with:
modrinth-id: 7YjclEGc
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
game-versions: ${{ env.MACHINE_RANGE_PLATFORM }}
game-version-filter: any
fail-mode: skip
name: "[DP] Release v${{ github.event.inputs.tag }}"
version: ${{ github.event.inputs.tag }}
changelog-file: CHANGES.md
loaders: |
datapack
files: |
./${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}-datapack.zip
- name: Upload Forge mod version to Modrinth # Forge mod version is uploaded separately atm due to it not being compatible with Minecraft 1.21.6 or above
id: upload_forge_modrinth_mod
uses: Kir-Antipov/mc-publish@v3.3
if: steps.check_mod_folder.outputs.files_exists == 'true' && github.event.inputs.dry_run == 'false' && github.event.inputs.separate_forge == 'true'
with:
modrinth-id: 7YjclEGc
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
game-versions: |
>=1.17 <=1.21.5
game-version-filter: any
fail-mode: skip
name: "[Mod] Release v${{ github.event.inputs.tag }}"
version: ${{ github.event.inputs.tag }}+mod
changelog-file: CHANGES.md
dependencies: |
midnightlib(optional){modrinth:codAaoxh}
loaders: |
forge
files: |
./${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}-mod.jar
- name: Upload mod version to Modrinth
id: upload_modrinth_mod
uses: Kir-Antipov/mc-publish@v3.3
if: steps.check_mod_folder.outputs.files_exists == 'true' && github.event.inputs.dry_run == 'false'
with:
modrinth-id: 7YjclEGc
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
game-versions: ${{ env.MACHINE_RANGE_PLATFORM }}
game-version-filter: any
fail-mode: skip
name: "[Mod] Release v${{ github.event.inputs.tag }}"
version: ${{ github.event.inputs.tag }}+mod
changelog-file: CHANGES.md
dependencies: |
fabric-api(required){modrinth:P7dR8mSH}
qsl(required){modrinth:qvIfYCYJ}
modmenu(optional){modrinth:mOgUt4GM}
modmenu-badges-lib(optional){modrinth:eUw8l2Vi}
midnightlib(optional){modrinth:codAaoxh}
loaders: |
fabric
quilt
neoforge
files: |
./${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}-mod.jar
- name: Upload data pack version to CurseForge
id: upload_curseforge_dp
uses: Kir-Antipov/mc-publish@v3.3
if: steps.check_datapack_folder.outputs.files_exists == 'true' && github.event.inputs.dry_run == 'false'
with:
curseforge-id: 831385
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
game-versions: ${{ env.MACHINE_RANGE_PLATFORM }}
game-version-filter: any
fail-mode: skip
name: "Release v${{ github.event.inputs.tag }}"
version: ${{ github.event.inputs.tag }}
changelog-file: CHANGES.md
loaders: |
datapack
files: |
./${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}-datapack.zip
- name: Upload mod version to CurseForge # Duplicate uploads sadly don't work on CurseForge
id: upload_curseforge_mod
uses: Kir-Antipov/mc-publish@v3.3
if: steps.check_mod_folder.outputs.files_exists == 'true' && github.event.inputs.dry_run == 'false'
with:
curseforge-id: 910095
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
game-versions: ${{ env.MACHINE_RANGE_PLATFORM }}
game-version-filter: any
fail-mode: skip
name: "Release v${{ github.event.inputs.tag }}"
version: ${{ github.event.inputs.tag }}+mod
changelog-file: CHANGES.md
dependencies: |
catalogue(optional){curseforge:459701}
midnightlib(optional){curseforge:488090}
java: |
Java 21
Java 17
loaders: |
fabric
quilt
neoforge
files: |
./${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}-mod.jar
- name: Add changelog header for GitHub release
if: github.event.inputs.dry_run == 'false'
run: sed -i '1i_Changelog:_' CHANGES.md
- name: Upload outputs to GitHub releases
id: upload_github
uses: Kir-Antipov/mc-publish@v3.3
if: github.event.inputs.dry_run == 'false'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
github-tag: v${{ github.event.inputs.tag }}
game-versions: ${{ env.MACHINE_RANGE_PLATFORM }}
name: Release v${{ github.event.inputs.tag }}
version: v${{ github.event.inputs.tag }}
changelog-file: CHANGES.md
files: |
./${{ github.event.repository.name }}-v${{ github.event.inputs.tag }}-mc${{ env.MC_HUMAN_VERSION_RANGE }}*.@(zip|jar)
# Build summary
- name: Set job summary
if: always()
shell: bash
run: |
echo "Building summary..."
if [ "${{ job.status }}" == "success" ]; then
SUMMARY_CONTENT="<picture>
<source media=\"(prefers-color-scheme: light)\" srcset=\"https://raw.githubusercontent.com/Mqxx/GitHub-Markdown/main/blockquotes/badge/light-theme/success.svg\">
<img alt=\"✅ Success\" src=\"https://raw.githubusercontent.com/Mqxx/GitHub-Markdown/main/blockquotes/badge/dark-theme/success.svg\">
</picture><br>
**${{ github.event.repository.name }} v${{ github.event.inputs.tag }}** for **Minecraft ${{ env.MC_HUMAN_VERSION_RANGE }}** published successfully!
[View Changelog](https://github.com/${{ github.repository }}/blob/v${{ github.event.inputs.tag }}/CHANGES.md)
**Downloads:**
"
if [ -n "${{ steps.upload_modrinth_dp.outputs.modrinth-url }}" ]; then
SUMMARY_CONTENT+="- [Modrinth (Data Pack)](${{ steps.upload_modrinth_dp.outputs.modrinth-url }})
"
fi
if [ -n "${{ steps.upload_modrinth_mod.outputs.modrinth-url }}" ]; then
SUMMARY_CONTENT+="- [Modrinth (Mod)](${{ steps.upload_modrinth_mod.outputs.modrinth-url }})
"
fi
if [ -n "${{ steps.upload_curseforge_dp.outputs.curseforge-url }}" ]; then
SUMMARY_CONTENT+="- [CurseForge (Data Pack)](${{ steps.upload_curseforge_dp.outputs.curseforge-url }})
"
fi
if [ -n "${{ steps.upload_curseforge_mod.outputs.curseforge-url }}" ]; then
SUMMARY_CONTENT+="- [CurseForge (Mod)](${{ steps.upload_curseforge_mod.outputs.curseforge-url }})
"
fi
if [ -n "${{ steps.upload_github.outputs.github-url }}" ]; then
SUMMARY_CONTENT+="- [GitHub Releases](${{ steps.upload_github.outputs.github-url }})
"
fi
echo -e "$SUMMARY_CONTENT" >> $GITHUB_STEP_SUMMARY
else
cat << EOF >> $GITHUB_STEP_SUMMARY
<picture>
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/Mqxx/GitHub-Markdown/main/blockquotes/badge/light-theme/error.svg">
<img alt="❌ Error" src="https://raw.githubusercontent.com/Mqxx/GitHub-Markdown/main/blockquotes/badge/dark-theme/error.svg">
</picture><br>
The publish job for v${{ github.event.inputs.tag }} (mc${{ env.MC_HUMAN_VERSION_RANGE }}) failed! Please check the action logs for details.
EOF
fi