Skip to content
name: Build Pre-Release version and Publish
on:
workflow_dispatch:
inputs:
release-beta:
description: 'Publish a beta release?'
required: true
type: boolean
push:
branches:
- '**' # Pushes to any branch
jobs:
build-and-publish-pre-release:
strategy:
matrix:
# Use thses Java versions:
java: [17, 20] # Current Java LTS and current latest Java version
# Use these operating systems:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Store all lowercase commit message
run: |
echo "COMMIT_MESSAGE=$(echo ${github.event.head_commit.message} | tr '[:upper:]' '[:lower:]')" >> ${GITHUB_ENV}
- name: Detect if a beta release should be published
if: ${{ contains(env.COMMIT_MESSAGE, '[publish beta]') || inputs.release-beta }}
run: |
echo "PUBLISH_BETA=true" >> ${GITHUB_ENV}
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ matrix.java }}
- name: Show Java version
run: java -version
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Show Gradle version
run: gradle --version
- name: Build with Gradle (DEV)
if : ${{ env.PUBLISH_BETA != 'true' }}
run: gradle build --stacktrace
- name: Build with Gradle (BETA)
if : ${{ env.PUBLISH_BETA == 'true' }}
env:
REDEN_BUILD_TYPE: "BETA"
run: gradle build --stacktrace
- name: Get Mod Info
id: get_mod_info
uses: christian-draeger/read-properties@1.1.1
with:
path: gradle.properties
properties: 'mod_name mod_version'
- name: Get commit SHA
id: get_commit_sha
run: |
short_sha=$(echo ${GITHUB_SHA} | cut -c1-7)
echo "short_sha=$short_sha" >> $GITHUB_OUTPUT
- name: Get commit count
id: get_commit_count
run: |
commit_count=$(git log | grep -e '^commit [a-zA-Z0-9]*' | wc -l)
echo "commit_count=$commit_count" >> $GITHUB_OUTPUT
- name: Upload assets to GitHub Action
uses: actions/upload-artifact@v3
with:
name: "[DEV-CI#${{ github.run_number }}] ${{ steps.get_mod_info.outputs.mod_name }} ${{ steps.get_mod_info.outputs.mod_version }}.${{ steps.get_commit_count.outputs.commit_count }}+${{ steps.get_commit_sha.outputs.short_sha }} - Java ${{ matrix.java }}"
path: build/libs/*.jar
- name: Publish to GitHub Pre-Releases
if: ${{ env.PUBLISH_BETA == 'true' && matrix.java == 17 }} # Only publish the version built with Java LTS
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifacts: build/libs/*.jar
generateReleaseNotes: true
name: "[CI#${{ github.run_number }}] ${{ steps.get_mod_info.outputs.mod_name }} Mod Pre-Release ${{ steps.get_mod_info.outputs.mod_version }}.${{ steps.get_commit_count.outputs.commit_count }}+${{ steps.get_commit_sha.outputs.short_sha }}"
prerelease: true
tag: "beta/${{ steps.get_commit_sha.outputs.short_sha }}"
- name: Publish to Modrinth & CurseForge
if: ${{ env.PUBLISH_BETA == 'true' && matrix.java == 17 }} # Only publish the version built with Java LTS
uses: Kir-Antipov/mc-publish@v3.3
with:
# Publish to Modrinth
modrinth-id: xRu8OXEJ
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
# Publish to CurseForge
#curseforge-id: 903236
#curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }}
# Universal Configurations
files: |
build/libs/*-@(beta).jar
build/libs/*-@(beta)*@(ci)*[0123456789].jar
name: "${{ steps.get_mod_info.outputs.mod_name }} Pre-Release ${{ steps.get_mod_info.outputs.mod_version }}.${{ steps.get_commit_count.outputs.commit_count }}+${{ steps.get_commit_sha.outputs.short_sha }}.github.ci.${{ github.run_number }}"
version: "${{ steps.get_mod_info.outputs.mod_version }}-beta.${{ steps.get_commit_count.outputs.commit_count }}+${{ steps.get_commit_sha.outputs.short_sha }}.github.ci.${{ github.run_number }}"
version-type: beta
loaders: |
fabric
quilt
game-versions: 1.20.1
game-version-filter: any
dependencies:
carpet
fabric-api
fabric-language-kotlin
java: |
17
18
19
20
retry-attempts: 2
retry-delay: 10000