This repository was archived by the owner on May 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
204 lines (180 loc) · 6.67 KB
/
build.yml
File metadata and controls
204 lines (180 loc) · 6.67 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
name: Datapack Multi-Version Build
on:
push:
branches: [main]
pull_request:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
# Base format + overlay pairs — each row is a target MC version
- label: "1_20_3"
pack_format: 26
overlays: "1_20_3"
- label: "1_20_5"
pack_format: 41
overlays: "1_20_5"
- label: "pre_1_21_4"
pack_format: 48
overlays: "_pre_1_21_4 compat_1_21_4"
- label: "1_21_5"
pack_format: 71
overlays: "1_21_5"
- label: "1_21_6"
pack_format: 80
overlays: "1_21_6"
- label: "full"
pack_format: 101
overlays: ""
steps:
- uses: actions/checkout@v6
# 🔒 Repo lock — prevent running from wrong fork
- name: Repo lock
run: |
if [ "$GITHUB_REPOSITORY" != "runtoolkit/dataLib" ]; then
echo "::error::This workflow may only run in runtoolkit/dataLib."
exit 1
fi
# 📁 Prepare build directory
- name: Prepare build directory
run: mkdir -p build
# 📂 Copy base layer (excluding overlay directories)
- name: Copy base layer
run: |
OVERLAY_DIRS="1_20_3 1_20_5 _pre_1_21_4 compat_1_21_4 1_21_5 1_21_6 26_1"
EXCLUDES=""
for d in $OVERLAY_DIRS; do
EXCLUDES="$EXCLUDES --exclude=$d"
done
rsync -a $EXCLUDES \
--exclude='.git' \
--exclude='.github' \
--exclude='.gitattributes' \
--exclude='.gitignore' \
--exclude='README.md' \
--exclude='version.json' \
--exclude='dependencies.json' \
./ build/
# 📂 Copy overlays
- name: Copy target overlays
run: |
ALL_OVERLAYS="1_20_3 1_20_5 _pre_1_21_4 compat_1_21_4 1_21_5 1_21_6 26_1"
TARGET="${{ matrix.overlays }}"
if [ -z "$TARGET" ]; then
# Full build: copy all overlay directories
for d in $ALL_OVERLAYS; do
[ -d "$d" ] && cp -r "$d" build/ || echo "::warning::Overlay '$d' not found, skipping."
done
else
# Targeted build: copy only the relevant overlay(s)
for overlay in $TARGET; do
if [ -d "$overlay" ]; then
cp -r "$overlay" build/
else
echo "::warning::Overlay '$overlay' not found, skipping."
fi
done
fi
# 🧩 pack.mcmeta — update pack_format, keep only relevant overlay entries
- name: Patch pack.mcmeta
run: |
LABEL="${{ matrix.label }}"
FORMAT="${{ matrix.pack_format }}"
OVERLAYS="${{ matrix.overlays }}"
# Convert overlay list to jq array (may be empty for full build)
JQ_ARRAY="[]"
for ov in $OVERLAYS; do
JQ_ARRAY=$(echo "$JQ_ARRAY" | jq --arg d "$ov" '. + [$d]')
done
jq \
--argjson fmt "$FORMAT" \
--argjson keep "$JQ_ARRAY" \
--arg label "$LABEL" \
'
.pack.pack_format = $fmt |
if .overlays.entries and $label != "full" then
.overlays.entries = [
.overlays.entries[] |
select(.directory as $d | $keep | index($d) != null)
]
else . end
' \
build/pack.mcmeta > build/pack.mcmeta.tmp
mv build/pack.mcmeta.tmp build/pack.mcmeta
# 🔍 Sanity check — is pack.mcmeta valid JSON?
- name: Validate pack.mcmeta
run: |
jq empty build/pack.mcmeta && echo "pack.mcmeta is valid JSON." \
|| { echo "::error::pack.mcmeta is malformed!"; exit 1; }
# 📦 Zip
- name: Package datapack
run: |
cd build
zip -r ../dataLib-${{ matrix.label }}.zip .
echo "Archive size: $(du -sh ../dataLib-${{ matrix.label }}.zip | cut -f1)"
# 🚀 Upload as artifact
- uses: actions/upload-artifact@v6
with:
name: dataLib-${{ matrix.label }}
path: dataLib-${{ matrix.label }}.zip
retention-days: 14
if-no-files-found: error
# ───────────────────────────────────────────────
# Release — only on main pushes, with full ZIP
# ───────────────────────────────────────────────
release:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: write
steps:
- uses: actions/checkout@v6
# 🔒 Repo lock
- name: Repo lock
run: |
if [ "$GITHUB_REPOSITORY" != "runtoolkit/dataLib" ]; then
echo "::error::This workflow may only run in runtoolkit/dataLib."
exit 1
fi
# 📥 Download full ZIP from artifact
- uses: actions/download-artifact@v7
with:
name: dataLib-full
path: dist/
# 🏷️ Read version number from pack.mcmeta
- name: Read version
id: ver
run: |
# Extract version like "v5.1.1" from the description array in pack.mcmeta
VERSION=$(jq -r '
.pack.description |
if type == "array" then
.[] | select(type == "object") |
.text // empty
else . end |
select(test("^\\s*\\|\\s*v[0-9]")) |
gsub("^\\s*\\|\\s*"; "") | ltrimstr(" ")
' pack.mcmeta | head -1)
# Fallback: if description is a plain string, extract directly
if [ -z "$VERSION" ]; then
VERSION=$(jq -r '.pack.description' pack.mcmeta | grep -oP 'v[\d.]+' | head -1)
fi
echo "version=${VERSION:-latest}" >> "$GITHUB_OUTPUT"
# 🚀 Create or update GitHub Release
- name: Create or update release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="${{ steps.ver.outputs.version }}"
ZIP="dist/dataLib-full.zip"
# Delete existing tag if it exists, otherwise continue
gh release delete "$TAG" --yes 2>/dev/null || true
git push origin ":refs/tags/$TAG" 2>/dev/null || true
gh release create "$TAG" \
--title "dataLib $TAG" \
--notes "**Full multi-version datapack build** (pack_format 101, all overlays included)." \
--latest \
"$ZIP#dataLib-full.zip"