-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (115 loc) · 4.66 KB
/
Copy pathdeploy.yml
File metadata and controls
119 lines (115 loc) · 4.66 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
name: Build and Deploy
on: [push]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout 🛎️
uses: actions/checkout@v7
with:
persist-credentials: false
- name: Setup Java ☕
uses: actions/setup-java@v5
with:
java-version: 21
distribution: temurin
- name: Setup Node.js 🟢
uses: actions/setup-node@v6
with:
node-version: 24
- name: Cache Minecraft server files 💾
uses: actions/cache@v6
with:
path: |
server
headlessmc/game
key: minecraft-${{ hashFiles('modpack.pom.xml') }}
- name: Install and Build 🔧
run: |
npm install --legacy-peer-deps
npm run build
npm run lint
npm test
- name: Submit coverage results
uses: coverallsapp/github-action@v2
- name: Generate modpack.json from POM 📋
run: npm run generate:modpack
- name: Download mods and generate metadata 📦
run: npm run generate:metadata
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Inject custom language files 🌐
run: |
python3 - <<'PYEOF'
import json, os
for modid in os.listdir('lang'):
lang_dir = os.path.join('lang', modid)
if not os.path.isdir(lang_dir):
continue
for lang_file in os.listdir(lang_dir):
src = os.path.join(lang_dir, lang_file)
dst_dir = os.path.join('mod_assets', modid, 'lang')
dst = os.path.join(dst_dir, lang_file)
os.makedirs(dst_dir, exist_ok=True)
try:
with open(dst) as f:
existing = json.load(f)
except (FileNotFoundError, json.JSONDecodeError):
existing = {}
with open(src) as f:
custom = json.load(f)
existing.update(custom)
with open(dst, 'w') as f:
json.dump(existing, f, indent=2)
print(f'Merged {src} into {dst}')
PYEOF
- name: Install Xvfb 🖥️
run: sudo apt-get install -y xvfb
- name: Generate icons 🎨
run: xvfb-run --auto-servernum --server-args="-screen 0 1920x1080x24" npm run generate:icons --headlessmc-version 2.9.0
- name: Generate HTML 📄
run: npm run generate:html
- name: Compress icons 🗜️
run: npm run generate:compress
- name: Restore unchanged icons and track Minecraft version 🔄
run: |
# Read the current Minecraft version from modpack.json
MC_VERSION=$(python3 -c "import json; print(json.load(open('modpack.json'))['minecraft'])")
echo "Current Minecraft version: $MC_VERSION"
# Try to fetch gh-pages (may not exist on the very first deployment)
PREV_VERSION=""
if git fetch origin gh-pages --depth=1 2>/dev/null; then
PREV_VERSION=$(git cat-file blob origin/gh-pages:minecraft-version.txt 2>/dev/null || echo "")
fi
echo "Previous Minecraft version: '${PREV_VERSION}'"
if [ "$MC_VERSION" = "$PREV_VERSION" ]; then
echo "Minecraft version unchanged — restoring existing icons from gh-pages (only new icons will be added)"
RESTORED=0
SKIPPED=0
while IFS= read -r icon_path; do
local_path="output/$icon_path"
if [ -f "$local_path" ]; then
git cat-file blob "origin/gh-pages:$icon_path" > "$local_path"
RESTORED=$((RESTORED + 1))
else
SKIPPED=$((SKIPPED + 1))
fi
done < <(git ls-tree -r --name-only origin/gh-pages -- 'assets/icon/' 2>/dev/null || true)
echo "Restored $RESTORED existing icons from gh-pages; $SKIPPED icons from gh-pages no longer present in new export"
else
echo "Minecraft version changed from '${PREV_VERSION}' to '${MC_VERSION}' — using all freshly generated icons"
fi
# Write the current Minecraft version into output/ so it is tracked on gh-pages
# and future deployments can detect whether the Minecraft version has changed.
echo "$MC_VERSION" > output/minecraft-version.txt
echo "Written output/minecraft-version.txt"
- name: Deploy 🚀
if: github.ref == 'refs/heads/master'
uses: JamesIves/github-pages-deploy-action@v4.8.0
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: output
CLEAN: true