mirror of
https://github.com/Nostalgica-Reverie/Content-Monorepo.git
synced 2026-05-09 00:24:15 +00:00
chore(ci): improve auto publish
This commit is contained in:
@@ -2,21 +2,63 @@ name: "Publish"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
branches: ["main"]
|
||||
paths:
|
||||
- 'modpacks/**/manifest.json'
|
||||
- 'datapacks/**/manifest.json'
|
||||
- 'resourcepacks/**/manifest.json'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
detect:
|
||||
runs-on: technocality
|
||||
outputs:
|
||||
manifests: ${{ steps.find.outputs.manifests }}
|
||||
has_manifests: ${{ steps.find.outputs.has_manifests }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
fetch-depth: 2
|
||||
filter: blob:none
|
||||
sparse-checkout: |
|
||||
modpacks
|
||||
datapacks
|
||||
|
||||
- name: Find changed manifests
|
||||
id: find
|
||||
run: |
|
||||
MANIFESTS=$(git diff-tree --no-commit-id --name-only -r HEAD \
|
||||
| grep -E '^(modpacks|datapacks)/.*/manifest\.json$' || true)
|
||||
if [ -z "$MANIFESTS" ]; then
|
||||
echo "has_manifests=false" >> $GITHUB_OUTPUT
|
||||
echo "manifests=[]" >> $GITHUB_OUTPUT
|
||||
echo "no changed manifests."
|
||||
else
|
||||
JSON=$(echo "$MANIFESTS" | jq -R -s -c 'split("\n") | map(select(length > 0))')
|
||||
echo "has_manifests=true" >> $GITHUB_OUTPUT
|
||||
echo "manifests=$JSON" >> $GITHUB_OUTPUT
|
||||
echo "manifests to publish: $JSON"
|
||||
fi
|
||||
|
||||
publish:
|
||||
needs: detect
|
||||
if: needs.detect.outputs.has_manifests == 'true'
|
||||
runs-on: technocality
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
manifest: ${{ fromJson(needs.detect.outputs.manifests) }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
filter: blob:none
|
||||
sparse-checkout: |
|
||||
modpacks
|
||||
datapacks
|
||||
src/actions/publish
|
||||
tools/changelog
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v4
|
||||
@@ -25,48 +67,61 @@ jobs:
|
||||
|
||||
- name: Generate Changelog
|
||||
id: changelog
|
||||
run: |
|
||||
# The blobless fetch allows this git command to work perfectly
|
||||
MANIFEST=$(git diff-tree --no-commit-id --name-only -r HEAD | grep 'manifest.json' | head -n 1)
|
||||
echo "manifest=$MANIFEST" >> $GITHUB_OUTPUT
|
||||
|
||||
npx tsx src/scripts/changelog.ts "$MANIFEST"
|
||||
run: npx tsx tools/changelog/generate-changelog.ts "${{ matrix.manifest }}"
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
- name: Cache Publisher Binary
|
||||
id: cache-publisher
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
go-version: 'stable'
|
||||
cache: true
|
||||
path: ./publisher-bin
|
||||
key: publisher-v1-${{ runner.os }}-${{ hashFiles('src/actions/publish/**/*.rs', 'src/actions/publish/Cargo.toml', 'src/actions/publish/Cargo.lock') }}
|
||||
|
||||
- name: Install Rust
|
||||
if: steps.cache-publisher.outputs.cache-hit != 'true'
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Rust Cache
|
||||
if: steps.cache-publisher.outputs.cache-hit != 'true'
|
||||
uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
workspaces: "src/actions/publish -> target"
|
||||
|
||||
- name: Build Publisher
|
||||
if: steps.cache-publisher.outputs.cache-hit != 'true'
|
||||
run: |
|
||||
cargo build --release --manifest-path src/actions/publish/Cargo.toml --bin publish
|
||||
mkdir -p ./publisher-bin
|
||||
cp src/actions/publish/target/release/publish ./publisher-bin/publish
|
||||
|
||||
- name: Cache Packwiz Binaries
|
||||
id: cache-go
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/go/bin
|
||||
key: go-bin-v1-${{ runner.os }}
|
||||
key: go-bin-packwiz-v1-${{ runner.os }}
|
||||
|
||||
- name: Install packwiz
|
||||
- name: Setup Go
|
||||
if: steps.cache-go.outputs.cache-hit != 'true'
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 'stable'
|
||||
cache: true
|
||||
|
||||
- name: Install Packwiz
|
||||
if: steps.cache-go.outputs.cache-hit != 'true'
|
||||
run: go install github.com/packwiz/packwiz@latest
|
||||
|
||||
- name: Add Path
|
||||
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
|
||||
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Rust Cache
|
||||
uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
workspaces: "src/actions -> target"
|
||||
- name: Add Go bin to PATH
|
||||
run: echo "$HOME/go/bin" >> $GITHUB_PATH
|
||||
|
||||
- name: Run Publisher
|
||||
id: meta
|
||||
run: |
|
||||
cargo run --release --manifest-path src/actions/Cargo.toml --bin publish -- "${{ steps.changelog.outputs.manifest }}"
|
||||
chmod +x ./publisher-bin/publish
|
||||
./publisher-bin/publish "${{ matrix.manifest }}"
|
||||
|
||||
- name: Upload to Platforms
|
||||
if: "steps.meta.outputs.mr_id != ''"
|
||||
if: "steps.meta.outputs.mr_id != '' || steps.meta.outputs.cf_id != ''"
|
||||
uses: https://github.com/Kir-Antipov/mc-publish@v3.3
|
||||
with:
|
||||
modrinth-id: ${{ steps.meta.outputs.mr_id }}
|
||||
@@ -78,5 +133,5 @@ jobs:
|
||||
name: "${{ steps.meta.outputs.name }}"
|
||||
version: "${{ steps.meta.outputs.ver }}"
|
||||
changelog: "${{ steps.changelog.outputs.notes }}"
|
||||
loaders: ${{ steps.meta.outputs.type == 'modpack' && 'fabric' || 'minecraft' }}
|
||||
game-versions: "${{ steps.meta.outputs.mc }}"
|
||||
loaders: ${{ steps.meta.outputs.type == 'modpack' && steps.meta.outputs.loader || 'minecraft' }}
|
||||
game-versions: "${{ steps.meta.outputs.mc }}"
|
||||
|
||||
Reference in New Issue
Block a user