Skip to content

Build Datapacks (separate artifacts) #3

Build Datapacks (separate artifacts)

Build Datapacks (separate artifacts) #3

name: Build Datapacks (separate artifacts)
on:
push:
branches: ["**"]
tags: ["v*"]
workflow_dispatch:
permissions:
contents: write
concurrency:
group: build-datapacks-${{ github.ref }}
cancel-in-progress: true
jobs:
discover:
runs-on: ubuntu-latest
outputs:
packs: ${{ steps.find.outputs.packs }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Find pack folders (must contain pack.mcmeta)
id: find
shell: bash
run: |
set -euo pipefail
shopt -s nullglob
json="["
sep=""
for d in packs/*/ ; do
if [ -f "${d}pack.mcmeta" ]; then
name=$(basename "$d")
json="${json}${sep}\"${name//\"/\\\"}\""
sep=","
fi
done
json="${json}]"
if [ "$json" = "[]" ]; then
echo "No valid packs (with pack.mcmeta) found in /packs"
exit 1
fi
echo "Found packs: $json"
echo "packs=$json" >> "$GITHUB_OUTPUT"
build:
needs: discover
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
pack: ${{ fromJSON(needs.discover.outputs.packs) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install zip
run: sudo apt-get update && sudo apt-get install -y zip
- name: Validate ${{ matrix.pack }}
shell: bash
run: |
set -euo pipefail
d="packs/${{ matrix.pack }}/"
test -d "$d" || { echo "Missing dir $d"; exit 1; }
test -f "${d}pack.mcmeta" || { echo "Missing ${d}pack.mcmeta"; exit 1; }
pf=$(grep -oE '"pack_format"\s*:\s*[0-9]+' "${d}pack.mcmeta" | grep -oE '[0-9]+' || true)
if [ -z "$pf" ]; then
echo "Invalid pack.mcmeta (pack.pack_format must be a number)"; exit 1
fi
echo "OK: ${{ matrix.pack }} (pack_format=$pf)"
- name: Zip ${{ matrix.pack }}
shell: bash
run: |
set -euo pipefail
d="packs/${{ matrix.pack }}/"
mkdir -p artifacts
zip -r -9 "artifacts/${{ matrix.pack }}.zip" "$d" \
-x "*.git*" "*/.DS_Store" "*/Thumbs.db"
ls -lh artifacts
- name: Upload artifact (${{ matrix.pack }})
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.pack }}
path: artifacts/${{ matrix.pack }}.zip
if-no-files-found: error
retention-days: 14
release:
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Download all pack artifacts
uses: actions/download-artifact@v4
with:
pattern: "*"
merge-multiple: true
path: artifacts
- name: Sanity check
shell: bash
run: |
set -euo pipefail
ls -lh artifacts || true
count=$(ls artifacts/*.zip 2>/dev/null | wc -l || echo 0)
if [ "$count" -eq 0 ]; then
echo "No ZIPs found in artifacts/; nothing to release."
exit 1
fi
echo "Found $count zip(s) to attach."
- name: Generate checksums
shell: bash
run: |
set -euo pipefail
cd artifacts
sha256sum *.zip > SHASUMS.txt
cat SHASUMS.txt
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: |
artifacts/*.zip
artifacts/SHASUMS.txt
generate_release_notes: true
draft: false
prerelease: false
name: ${{ github.ref_name }}
body: |
Automated build for ${{ github.ref_name }}.
Includes individually downloadable datapack zips for all packs in /packs.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}