Skip to content

Auto Build, Publish, Releasing #5

Auto Build, Publish, Releasing

Auto Build, Publish, Releasing #5

name: Auto Build, Publish, Releasing
on:
workflow_dispatch:
inputs:
publishMaven:
description: 'Whether to publish to Maven'
required: true
type: boolean
default: true
publishCurseForgeAndModrinth:
description: 'Whether to publish to CurseForge and Modrinth'
required: true
type: boolean
default: true
versionType:
description: 'Version type'
required: true
type: choice
options:
- 'alpha'
- 'beta'
- 'release'
default: 'alpha'
dryRun:
description: 'Dry run (build only, no publishing)'
required: false
type: boolean
default: false
env:
JAVA_VERSION: '21'
JAVA_DISTRIBUTION: 'temurin'
jobs:
validate:
name: Validate & Pre-checks
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
should-publish: ${{ steps.check.outputs.should-publish }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
- name: Validate Gradle wrapper
uses: gradle/actions/wrapper-validation@v4
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: false
- name: Grant execute permission
run: chmod +x gradlew
- name: Get version from gradle.properties
id: version
run: |
if [ -f "gradle.properties" ]; then
VERSION=$(grep -E "^mod_version\s*=" gradle.properties | cut -d'=' -f2 | tr -d ' ')
if [ -z "$VERSION" ]; then
echo "❌ Could not find mod_version in gradle.properties"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Project version: $VERSION"
else
echo "❌ gradle.properties not found, falling back to Gradle command"
VERSION=$(./gradlew -q printVersion)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Project version: $VERSION"
fi
- name: Check publish conditions
id: check
run: |
SHOULD_PUBLISH="false"
if [[ "${{ inputs.dryRun }}" == "false" && ("${{ inputs.publishMaven }}" == "true" || "${{ inputs.publishCurseForgeAndModrinth }}" == "true") ]]; then
SHOULD_PUBLISH="true"
fi
echo "should-publish=$SHOULD_PUBLISH" >> $GITHUB_OUTPUT
echo "Should publish: $SHOULD_PUBLISH"
build:
name: Build & Test
runs-on: ubuntu-latest
needs: validate
strategy:
matrix:
include:
- name: "Main Build"
gradle-tasks: "build test"
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1000
fetch-tags: true
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: false
- name: Grant execute permission
run: chmod +x gradlew
- name: Build and test
run: ./gradlew ${{ matrix.gradle-tasks }} --stacktrace --info --parallel
env:
GRADLE_OPTS: "-Dorg.gradle.daemon=true -Dorg.gradle.parallel=true -Dorg.gradle.configureondemand=true"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: build-artifacts-${{ matrix.name }}
path: |
build/libs/
build/reports/
retention-days: 7
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ matrix.name }}
path: build/test-results/
retention-days: 7
publish-maven:
name: Publish to Maven
runs-on: ubuntu-latest
needs: [validate, build]
if: ${{ needs.validate.outputs.should-publish == 'true' && inputs.publishMaven }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1000
fetch-tags: true
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: true
- name: Grant execute permission
run: chmod +x gradlew
- name: Publish to Maven
run: ./gradlew publish --stacktrace
env:
MAVEN_PASS: ${{ secrets.MAVEN_PASS }}
MAVEN_USER: ${{ secrets.MAVEN_USER }}
GRADLE_OPTS: "-Dorg.gradle.daemon=true"
- name: Maven publish summary
run: |
echo "## Maven Publish Summary" >> $GITHUB_STEP_SUMMARY
echo "- Version: ${{ needs.validate.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- Status: ✅ Published successfully" >> $GITHUB_STEP_SUMMARY
publish-platforms:
name: Publish to CurseForge & Modrinth
runs-on: ubuntu-latest
needs: [validate, build]
if: ${{ needs.validate.outputs.should-publish == 'true' && inputs.publishCurseForgeAndModrinth }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1000
fetch-tags: true
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts-Main Build
path: build/
- name: Verify build artifacts
run: |
if [ ! -d "build/libs" ] || [ -z "$(ls -A build/libs)" ]; then
echo "❌ Build artifacts not found!"
echo "Available files in build/:"
find build/ -type f -name "*.jar" || echo "No JAR files found"
exit 1
fi
echo "✅ Build artifacts verified:"
ls -la build/libs/
- name: Publish to CurseForge and Modrinth
uses: Kir-Antipov/mc-publish@v3.3
with:
modrinth-id: B1CBVXHX
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
curseforge-id: 626676
curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
files: |
build/libs/*-@(all).jar
build/libs/!(*-@(all|dev|sources|javadoc|dev-shadow)).jar
build/libs/*-@(sources).jar
name: LDLib2-${{ needs.validate.outputs.version }}-neoforge
version: mc1.21.1-${{ needs.validate.outputs.version }}-neoforge
version-type: ${{ inputs.versionType }}
changelog-file: CHANGELOG.*
loaders: |
neoforge
game-versions: |
${{ github.ref_name }}
1.21.1
game-version-filter: none
java: |
21
retry-attempts: 3
retry-delay: 10000
fail-mode: fail
- name: Platform publish summary
run: |
echo "## Platform Publish Summary" >> $GITHUB_STEP_SUMMARY
echo "- Version: ${{ needs.validate.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- Version Type: ${{ inputs.versionType }}" >> $GITHUB_STEP_SUMMARY
echo "- Platforms: CurseForge & Modrinth" >> $GITHUB_STEP_SUMMARY
echo "- Status: ✅ Published successfully" >> $GITHUB_STEP_SUMMARY
summary:
name: Build & Publish Summary
runs-on: ubuntu-latest
needs: [validate, build, publish-maven, publish-platforms]
if: always()
steps:
- name: Generate final summary
run: |
echo "# 🚀 Build & Publish Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 📋 Configuration" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: ${{ needs.validate.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Version Type**: ${{ inputs.versionType }}" >> $GITHUB_STEP_SUMMARY
echo "- **Dry Run**: ${{ inputs.dryRun }}" >> $GITHUB_STEP_SUMMARY
echo "- **Maven Publish**: ${{ inputs.publishMaven }}" >> $GITHUB_STEP_SUMMARY
echo "- **Platform Publish**: ${{ inputs.publishCurseForgeAndModrinth }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 📊 Job Results" >> $GITHUB_STEP_SUMMARY
VALIDATE_STATUS="${{ needs.validate.result }}"
BUILD_STATUS="${{ needs.build.result }}"
MAVEN_STATUS="${{ needs.publish-maven.result }}"
PLATFORM_STATUS="${{ needs.publish-platforms.result }}"
echo "- **Validation**: $([ "$VALIDATE_STATUS" == "success" ] && echo "✅ Success" || echo "❌ $VALIDATE_STATUS")" >> $GITHUB_STEP_SUMMARY
echo "- **Build**: $([ "$BUILD_STATUS" == "success" ] && echo "✅ Success" || echo "❌ $BUILD_STATUS")" >> $GITHUB_STEP_SUMMARY
if [[ "${{ inputs.publishMaven }}" == "true" && "${{ inputs.dryRun }}" == "false" ]]; then
echo "- **Maven Publish**: $([ "$MAVEN_STATUS" == "success" ] && echo "✅ Success" || echo "❌ $MAVEN_STATUS")" >> $GITHUB_STEP_SUMMARY
fi
if [[ "${{ inputs.publishCurseForgeAndModrinth }}" == "true" && "${{ inputs.dryRun }}" == "false" ]]; then
echo "- **Platform Publish**: $([ "$PLATFORM_STATUS" == "success" ] && echo "✅ Success" || echo "❌ $PLATFORM_STATUS")" >> $GITHUB_STEP_SUMMARY
fi
if [[ "$BUILD_STATUS" == "success" ]]; then
if [[ "${{ inputs.dryRun }}" == "true" ]]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 🔍 Dry Run Completed" >> $GITHUB_STEP_SUMMARY
echo "Build completed successfully. No publishing was performed." >> $GITHUB_STEP_SUMMARY
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 🎉 All Operations Completed Successfully!" >> $GITHUB_STEP_SUMMARY
fi
else
echo "" >> $GITHUB_STEP_SUMMARY
echo "## ❌ Some Operations Failed" >> $GITHUB_STEP_SUMMARY
echo "Please check the job logs for details." >> $GITHUB_STEP_SUMMARY
fi
- name: Check overall status
run: |
if [[ "${{ needs.build.result }}" != "success" ]]; then
echo "Build failed, marking workflow as failed"
exit 1
fi
if [[ "${{ inputs.dryRun }}" == "false" ]]; then
if [[ "${{ inputs.publishMaven }}" == "true" && "${{ needs.publish-maven.result }}" != "success" ]]; then
echo "Maven publish failed, marking workflow as failed"
exit 1
fi
if [[ "${{ inputs.publishCurseForgeAndModrinth }}" == "true" && "${{ needs.publish-platforms.result }}" != "success" ]]; then
echo "Platform publish failed, marking workflow as failed"
exit 1
fi
fi
echo "All requested operations completed successfully!"