Skip to content

Publish Release

Publish Release #6

Workflow file for this run

# This workflow publishes releases to GitHub Packages, Modrinth, CurseForge, and GitHub Releases
name: Publish Release
on:
workflow_dispatch:
env:
JAVA_VERSION: 21
JAVA_DISTRIBUTION: adopt
jobs:
publish:
name: Build and Publish
runs-on: ubuntu-latest
environment: publish
permissions:
contents: write
packages: write
steps:
- name: ✨ Checkout repository
uses: actions/checkout@v4
- name: 📖 Extract version from gradle.properties
id: version
run: |
MOD_VERSION=$(grep '^mod_version' gradle.properties | cut -d'=' -f2 | tr -d ' ')
MC_VERSION=$(grep '^minecraft_version' gradle.properties | cut -d'=' -f2 | tr -d ' ')
TAG="$MOD_VERSION-mc$MC_VERSION"
echo "mod_version=$MOD_VERSION" >> $GITHUB_OUTPUT
echo "minecraft_version=$MC_VERSION" >> $GITHUB_OUTPUT
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "Extracted mod version: $MOD_VERSION"
echo "Extracted minecraft version: $MC_VERSION"
echo "Tag will be: $TAG"
- name: ❌ Check if tag already exists
run: |
if git ls-remote --tags origin | grep -q "refs/tags/${{ steps.version.outputs.tag }}$"; then
echo "❌ Tag ${{ steps.version.outputs.tag }} already exists!"
echo "Please update the mod_version in gradle.properties to create a new release."
exit 1
fi
echo "✅ Tag ${{ steps.version.outputs.tag }} does not exist, proceeding..."
- name: 🏷️ Create and push tag
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag ${{ steps.version.outputs.tag }}
git push origin ${{ steps.version.outputs.tag }}
echo "✅ Created and pushed tag: ${{ steps.version.outputs.tag }}"
- name: 🛂 Validate Gradle wrapper
uses: gradle/actions/wrapper-validation@v4
- name: 🏗 Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
- name: 📷 Begin Gradle cache
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: 🔨 Build artifacts and Run Tests
env:
IS_PIPELINE: true
run: gradle clean build
- name: 📦 Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: '**/build/libs/'
- name: 📝 Upload test reports
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: test-reports
path: '**/build/reports/'
- name: 📤 Publish to GitHub Packages
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IS_PIPELINE: true
run: gradle publishMavenJavaPublicationToGitHubRepository
- name: 📤 Publish to Modrinth
env:
MODRINTH: ${{ secrets.MODRINTH }}
IS_PIPELINE: true
run: gradle publishModrinth
- name: 📤 Publish to CurseForge
env:
CURSEFORGE: ${{ secrets.CURSEFORGE }}
IS_PIPELINE: true
run: gradle publishCurseForge
- name: 📤 Create GitHub Release
env:
GITHUB: ${{ secrets.GITHUB_TOKEN }}
IS_PIPELINE: true
run: gradle publishGithubRelease
- name: 🧨 Cleanup Gradle cache
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties