Files
Content-Monorepo/.forgejo/workflows/build.yml
2026-04-20 19:01:00 -06:00

149 lines
4.8 KiB
YAML

name: "Build"
on:
push:
branches: ["main"]
paths:
- 'modpacks/**'
- 'datapacks/**'
- 'src/actions/builder/**'
pull_request:
branches: ["main"]
paths:
- 'modpacks/**'
- 'datapacks/**'
- 'src/actions/builder/**'
workflow_dispatch:
jobs:
build:
runs-on: technocality
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 2
filter: blob:none
sparse-checkout: |
modpacks
datapacks
src/actions/builder
- name: Meta
id: meta
run: |
set -eu
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
CHANGED=$(git diff-tree --no-commit-id --name-only -r HEAD)
CHANGED_MODPACKS=$(echo "$CHANGED" | grep -E '^modpacks/[^/]+/' | cut -d/ -f1-2 | sort -u || true)
CHANGED_DATAPACKS=$(echo "$CHANGED" | grep -E '^datapacks/[^/]+/' | cut -d/ -f1-2 | sort -u || true)
{
echo "has_modpacks=$( [ -n "$CHANGED_MODPACKS" ] && echo true || echo false )"
echo "has_datapacks=$( [ -n "$CHANGED_DATAPACKS" ] && echo true || echo false )"
echo "changed_modpacks<<EOF"
echo "$CHANGED_MODPACKS"
echo "EOF"
echo "changed_datapacks<<EOF"
echo "$CHANGED_DATAPACKS"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Cache Builder Binaries
id: cache-builder
uses: actions/cache@v4
with:
path: ./builder-bin
key: builder-v2-${{ runner.os }}-${{ hashFiles('src/actions/builder/**/*.rs', 'src/actions/builder/Cargo.toml', 'src/actions/builder/Cargo.lock') }}
- name: Install Rust
if: steps.cache-builder.outputs.cache-hit != 'true'
uses: https://github.com/dtolnay/rust-toolchain@stable
- name: Rust Cache
if: steps.cache-builder.outputs.cache-hit != 'true'
uses: https://github.com/Swatinem/rust-cache@v2
with:
workspaces: "src/actions/builder -> target"
- name: Build Binaries
if: steps.cache-builder.outputs.cache-hit != 'true'
run: |
cargo build --release --manifest-path src/actions/builder/Cargo.toml --bin builder --bin minify-json
mkdir -p ./builder-bin
cp src/actions/builder/target/release/{builder,minify-json} ./builder-bin/
chmod +x ./builder-bin/builder ./builder-bin/minify-json
- name: Cache Packwiz
if: steps.meta.outputs.has_modpacks == 'true'
id: cache-go
uses: actions/cache@v4
with:
path: ~/go/bin
key: go-bin-packwiz-v1-${{ runner.os }}
- name: Setup Go
if: steps.meta.outputs.has_modpacks == 'true' && steps.cache-go.outputs.cache-hit != 'true'
uses: https://github.com/actions/setup-go@v5
with: { go-version: 'stable', cache: true }
- name: Install Packwiz
if: steps.meta.outputs.has_modpacks == 'true' && steps.cache-go.outputs.cache-hit != 'true'
run: go install github.com/packwiz/packwiz@latest
- name: Add Go bin to PATH
if: steps.meta.outputs.has_modpacks == 'true'
run: echo "$HOME/go/bin" >> $GITHUB_PATH
- name: Minify datapacks
if: steps.meta.outputs.has_datapacks == 'true'
run: |
set -eu
while IFS= read -r pack; do
[ -n "$pack" ] || continue
target="$pack/content"
[ -d "$target" ] || continue
(
cp -r "$target" "$target.original"
./builder-bin/minify-json "$target"
) &
done <<< "${{ steps.meta.outputs.changed_datapacks }}"
wait
- name: Minify modpacks
if: steps.meta.outputs.has_modpacks == 'true'
run: |
set -eu
while IFS= read -r pack; do
[ -n "$pack" ] || continue
for sub in "$pack"/*-{mr,cf}/config; do
[ -d "$sub" ] || continue
(
cp -r "$sub" "$sub.original"
./builder-bin/minify-json "$sub"
) &
done
done <<< "${{ steps.meta.outputs.changed_modpacks }}"
wait
- name: Run Build
run: ./builder-bin/builder "${{ steps.meta.outputs.short_sha }}"
- name: Restore JSON sources
if: always()
run: |
set -eu
for orig in datapacks/*/content.original modpacks/*/*-{mr,cf}/config.original; do
[ -d "$orig" ] || continue
target="${orig%.original}"
rm -rf "$target"
mv "$orig" "$target"
done
- name: Upload
uses: https://code.forgejo.org/forgejo/upload-artifact@v4
with:
name: "build-${{ steps.meta.outputs.short_sha }}"
path: "artifacts/"
compression-level: 0