Files
Content-Monorepo/.forgejo/workflows/publish.yml
2026-04-18 17:56:57 -06:00

149 lines
4.8 KiB
YAML

name: "Publish"
on:
push:
branches: ["main"]
paths:
- 'modpacks/**/manifest.json'
- 'datapacks/**/manifest.json'
workflow_dispatch:
jobs:
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
filter: blob:none
sparse-checkout: |
modpacks
datapacks
- name: Install jq
run: |
if ! command -v jq &> /dev/null; then
apt-get update && apt-get install -y jq
fi
- 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: always()
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
with:
node-version: '20'
- name: Generate Changelog
id: changelog
run: |
git config user.name "Forgejo Action"
git config user.email "actions@noreply.forgejo"
git add .
git commit -m "internal: prepare changelog" --allow-empty
npx tsx tools/changelog/generate-changelog.ts "${{ matrix.manifest }}"
- name: Cache Publisher Binary
id: cache-publisher
uses: actions/cache@v4
with:
path: ./publisher-bin
key: publisher-v1-${{ runner.os }}-${{ hashFiles('src/actions/publish/**/*.rs', 'src/actions/publish/Cargo.toml', 'src/actions/publish/Cargo.lock') }}
- name: Rust Cache
if: steps.cache-publisher.outputs.cache-hit != 'true'
uses: https://github.com/Swatinem/rust-cache@v2
with:
workspaces: "src/actions/publish -> target"
- name: Install Rust
if: steps.cache-publisher.outputs.cache-hit != 'true'
uses: https://github.com/dtolnay/rust-toolchain@stable
- 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-packwiz-v1-${{ runner.os }}
- 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 Go bin to PATH
run: echo "$HOME/go/bin" >> $GITHUB_PATH
- name: Run Publisher
id: meta
run: |
chmod +x ./publisher-bin/publish
./publisher-bin/publish "${{ matrix.manifest }}"
- 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
with:
modrinth-id: ${{ steps.meta.outputs.mr_id }}
modrinth-token: ${{ secrets.MR }}
modrinth-files: "${{ github.workspace }}/${{ steps.meta.outputs.path }}/artifacts/*.mrpack"
curseforge-id: ${{ steps.meta.outputs.cf_id }}
curseforge-token: ${{ secrets.CF }}
curseforge-files: "${{ github.workspace }}/${{ steps.meta.outputs.path }}/artifacts/*.zip"
name: "${{ steps.meta.outputs.name }}"
version: "${{ steps.meta.outputs.ver }}"
changelog: "${{ steps.changelog.outputs.notes }}"
loaders: ${{ steps.meta.outputs.type == 'modpack' && steps.meta.outputs.loader || 'minecraft' }}
game-versions: "${{ steps.meta.outputs.mc }}"