mirror of
https://github.com/Nostalgica-Reverie/Content-Monorepo.git
synced 2026-05-09 00:24:15 +00:00
feat(ci): minify json to both build and pub
This commit is contained in:
@@ -35,12 +35,12 @@ jobs:
|
||||
SHORT_SHA=$(git rev-parse --short HEAD)
|
||||
echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Cache Builder Binary
|
||||
- name: Cache Builder Binaries
|
||||
id: cache-builder
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ./builder-bin
|
||||
key: builder-v1-${{ runner.os }}-${{ hashFiles('src/actions/builder/**/*.rs', 'src/actions/builder/Cargo.toml', 'src/actions/builder/Cargo.lock') }}
|
||||
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'
|
||||
@@ -52,12 +52,15 @@ jobs:
|
||||
with:
|
||||
workspaces: "src/actions/builder -> target"
|
||||
|
||||
- name: Build Builder
|
||||
- name: Build Binaries
|
||||
if: steps.cache-builder.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
cargo build --release --manifest-path src/actions/builder/Cargo.toml --bin builder
|
||||
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 ./builder-bin/builder
|
||||
cp src/actions/builder/target/release/minify-json ./builder-bin/minify-json
|
||||
|
||||
- name: Cache Go Binaries
|
||||
id: cache-go
|
||||
@@ -88,11 +91,71 @@ jobs:
|
||||
restore-keys: |
|
||||
packwiz-cache-${{ runner.os }}-
|
||||
|
||||
- name: Minify JSON configs
|
||||
run: |
|
||||
set -eu
|
||||
chmod +x ./builder-bin/minify-json
|
||||
|
||||
if [ -d datapacks ]; then
|
||||
for pack_dir in datapacks/*/; do
|
||||
[ -d "$pack_dir" ] || continue
|
||||
TARGET="${pack_dir}content"
|
||||
if [ -d "$TARGET" ]; then
|
||||
cp -r "$TARGET" "${TARGET}.original"
|
||||
./builder-bin/minify-json "$TARGET"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -d modpacks ]; then
|
||||
for pack_dir in modpacks/*/; do
|
||||
[ -d "$pack_dir" ] || continue
|
||||
for subdir in "$pack_dir"*-mr "$pack_dir"*-cf; do
|
||||
[ -d "$subdir" ] || continue
|
||||
CONFIG_DIR="$subdir/config"
|
||||
if [ -d "$CONFIG_DIR" ]; then
|
||||
cp -r "$CONFIG_DIR" "${CONFIG_DIR}.original"
|
||||
./builder-bin/minify-json "$CONFIG_DIR"
|
||||
fi
|
||||
done
|
||||
done
|
||||
fi
|
||||
|
||||
- name: Run Build
|
||||
run: |
|
||||
chmod +x ./builder-bin/builder
|
||||
./builder-bin/builder "${{ steps.meta.outputs.short_sha }}"
|
||||
|
||||
- name: Restore JSON sources
|
||||
if: always()
|
||||
run: |
|
||||
set -eu
|
||||
|
||||
if [ -d datapacks ]; then
|
||||
for pack_dir in datapacks/*/; do
|
||||
[ -d "$pack_dir" ] || continue
|
||||
TARGET="${pack_dir}content"
|
||||
if [ -d "${TARGET}.original" ]; then
|
||||
rm -rf "$TARGET"
|
||||
mv "${TARGET}.original" "$TARGET"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -d modpacks ]; then
|
||||
for pack_dir in modpacks/*/; do
|
||||
[ -d "$pack_dir" ] || continue
|
||||
for subdir in "$pack_dir"*-mr "$pack_dir"*-cf; do
|
||||
[ -d "$subdir" ] || continue
|
||||
CONFIG_DIR="$subdir/config"
|
||||
if [ -d "${CONFIG_DIR}.original" ]; then
|
||||
rm -rf "$CONFIG_DIR"
|
||||
mv "${CONFIG_DIR}.original" "$CONFIG_DIR"
|
||||
fi
|
||||
done
|
||||
done
|
||||
fi
|
||||
|
||||
- name: Upload
|
||||
uses: https://code.forgejo.org/actions/upload-artifact@v3
|
||||
with:
|
||||
|
||||
@@ -73,6 +73,7 @@ jobs:
|
||||
modpacks
|
||||
datapacks
|
||||
src/actions/publish
|
||||
src/actions/builder
|
||||
tools/changelog
|
||||
|
||||
- name: Set up Node
|
||||
@@ -91,16 +92,29 @@ jobs:
|
||||
path: ./publisher-bin
|
||||
key: publisher-v1-${{ runner.os }}-${{ hashFiles('src/actions/publish/**/*.rs', 'src/actions/publish/Cargo.toml', 'src/actions/publish/Cargo.lock') }}
|
||||
|
||||
- name: Cache Minify-JSON Binary
|
||||
id: cache-minify
|
||||
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-publisher.outputs.cache-hit != 'true'
|
||||
if: steps.cache-publisher.outputs.cache-hit != 'true' || steps.cache-minify.outputs.cache-hit != 'true'
|
||||
uses: https://github.com/dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Rust Cache
|
||||
- name: Rust Cache (publish)
|
||||
if: steps.cache-publisher.outputs.cache-hit != 'true'
|
||||
uses: https://github.com/Swatinem/rust-cache@v2
|
||||
with:
|
||||
workspaces: "src/actions/publish -> target"
|
||||
|
||||
- name: Rust Cache (builder)
|
||||
if: steps.cache-minify.outputs.cache-hit != 'true'
|
||||
uses: https://github.com/Swatinem/rust-cache@v2
|
||||
with:
|
||||
workspaces: "src/actions/builder -> target"
|
||||
|
||||
- name: Build Publisher
|
||||
if: steps.cache-publisher.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
@@ -108,6 +122,13 @@ jobs:
|
||||
mkdir -p ./publisher-bin
|
||||
cp src/actions/publish/target/release/publish ./publisher-bin/publish
|
||||
|
||||
- name: Build minify-json
|
||||
if: steps.cache-minify.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
cargo build --release --manifest-path src/actions/builder/Cargo.toml --bin minify-json
|
||||
mkdir -p ./builder-bin
|
||||
cp src/actions/builder/target/release/minify-json ./builder-bin/minify-json
|
||||
|
||||
- name: Cache Packwiz Binaries
|
||||
id: cache-go
|
||||
uses: actions/cache@v4
|
||||
@@ -137,12 +158,63 @@ jobs:
|
||||
restore-keys: |
|
||||
packwiz-cache-${{ runner.os }}-
|
||||
|
||||
- name: Minify JSON configs
|
||||
run: |
|
||||
set -eu
|
||||
chmod +x ./builder-bin/minify-json
|
||||
|
||||
MANIFEST='${{ matrix.manifest }}'
|
||||
PACK_DIR="$(dirname "$MANIFEST")"
|
||||
|
||||
if [[ "$MANIFEST" == datapacks/* ]]; then
|
||||
# Datapack: minify content/
|
||||
TARGET="${PACK_DIR}/content"
|
||||
if [ -d "$TARGET" ]; then
|
||||
cp -r "$TARGET" "${TARGET}.original"
|
||||
./builder-bin/minify-json "$TARGET"
|
||||
fi
|
||||
elif [[ "$MANIFEST" == modpacks/* ]]; then
|
||||
# Modpack: minify each platform subdir's config/ folder
|
||||
for subdir in "$PACK_DIR"/*-mr "$PACK_DIR"/*-cf; do
|
||||
[ -d "$subdir" ] || continue
|
||||
CONFIG_DIR="$subdir/config"
|
||||
if [ -d "$CONFIG_DIR" ]; then
|
||||
cp -r "$CONFIG_DIR" "${CONFIG_DIR}.original"
|
||||
./builder-bin/minify-json "$CONFIG_DIR"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
- name: Run Publisher
|
||||
id: meta
|
||||
run: |
|
||||
chmod +x ./publisher-bin/publish
|
||||
./publisher-bin/publish "${{ matrix.manifest }}"
|
||||
|
||||
- name: Restore JSON sources
|
||||
if: always()
|
||||
run: |
|
||||
set -eu
|
||||
MANIFEST='${{ matrix.manifest }}'
|
||||
PACK_DIR="$(dirname "$MANIFEST")"
|
||||
|
||||
if [[ "$MANIFEST" == datapacks/* ]]; then
|
||||
TARGET="${PACK_DIR}/content"
|
||||
if [ -d "${TARGET}.original" ]; then
|
||||
rm -rf "$TARGET"
|
||||
mv "${TARGET}.original" "$TARGET"
|
||||
fi
|
||||
elif [[ "$MANIFEST" == modpacks/* ]]; then
|
||||
for subdir in "$PACK_DIR"/*-mr "$PACK_DIR"/*-cf; do
|
||||
[ -d "$subdir" ] || continue
|
||||
CONFIG_DIR="$subdir/config"
|
||||
if [ -d "${CONFIG_DIR}.original" ]; then
|
||||
rm -rf "$CONFIG_DIR"
|
||||
mv "${CONFIG_DIR}.original" "$CONFIG_DIR"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
- name: Upload to Platforms
|
||||
if: "steps.meta.outputs.mr_id != '' || steps.meta.outputs.cf_id != ''"
|
||||
uses: https://github.com/Kir-Antipov/mc-publish@v3.3
|
||||
|
||||
Reference in New Issue
Block a user