Skip to content

Publish Plugin

Publish Plugin #3

Workflow file for this run

name: Publish Plugin
on:
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
steps:
- name: Checkout repository
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
with:
fetch-depth: 0 # Fetch full history for changelog generation
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Java 21
uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5
with:
distribution: 'temurin'
java-version: '21'
- name: Generate Changelog
id: changelog
run: |
# Try to get the hash of the last successful publish workflow run
echo "Looking for previous publish workflow runs..."
LAST_RUN=""
# Get the last successful workflow run
echo "Looking for previous successful publish runs..."
echo "Running: gh run list --workflow=publish.yml --status=success --limit=1 --json headSha"
RUNS_OUTPUT=$(gh run list --workflow=publish.yml --status=success --limit=1 --json headSha)
echo "Raw output: $RUNS_OUTPUT"
if echo "$RUNS_OUTPUT" | jq -e '.[0].headSha' >/dev/null 2>&1; then
LAST_RUN=$(echo "$RUNS_OUTPUT" | jq -r '.[0].headSha')
echo "Found previous successful publish at commit: $LAST_RUN"
else
echo "No previous successful publish runs found"
echo "Debugging: trying to parse with jq..."
echo "$RUNS_OUTPUT" | jq '.'
fi
# Generate changelog based on what we found
if [ -z "$LAST_RUN" ] || ! git rev-parse --verify "$LAST_RUN" >/dev/null 2>&1; then
echo "First publish - generating changelog from recent meaningful commits"
# For first run, only include commits from the last few days or major changes
CHANGELOG=$(git log --oneline --since="7 days ago" --pretty=format:"- %s (%h)" 2>/dev/null || git log --oneline -5 --pretty=format:"- %s (%h)" 2>/dev/null || echo "- Initial release")
else
echo "Generating changelog since last publish at $LAST_RUN (excluding that commit)"
CHANGELOG=$(git log --oneline "$LAST_RUN"..HEAD --pretty=format:"- %s (%h)" 2>/dev/null || echo "- No new commits since last publish")
fi
# Fallback if changelog is empty
if [ -z "$CHANGELOG" ] || [ "$CHANGELOG" = "" ]; then
CHANGELOG="- No changes detected"
fi
echo "Generated changelog:"
echo "$CHANGELOG"
# Set the changelog as an environment variable
{
echo "CHANGELOG<<EOF"
echo "$CHANGELOG"
echo "EOF"
} >> $GITHUB_ENV
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Publish to Modrinth
run: ./gradlew modrinth
env:
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
CHANGELOG: ${{ env.CHANGELOG }}
- name: Publish to Hangar
run: ./gradlew publishAllPublicationsToHangar
env:
HANGAR_TOKEN: ${{ secrets.HANGAR_TOKEN }}
CHANGELOG: ${{ env.CHANGELOG }}