Skip to content

v26.2-1.2.15

v26.2-1.2.15 #52

Workflow file for this run

name: Auto Release
on:
push:
branches:
- main
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g. 26.2-1.0.3-beta). Leave empty to use version.txt.'
required: false
default: ''
type: string
permissions:
contents: write
jobs:
release:
name: Build and publish release
if: github.event_name == 'workflow_dispatch' || startsWith(github.event.head_commit.message, 'v')
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate Gradle wrapper
uses: gradle/actions/wrapper-validation@v4
- name: Set up JDK 25
uses: actions/setup-java@v4
with:
java-version: '25'
distribution: microsoft
- name: Make Gradle wrapper executable
run: chmod +x ./gradlew
- name: Parse release version and channel
id: release
shell: bash
env:
COMMIT_TITLE: ${{ github.event.head_commit.message }}
VERSION_INPUT: ${{ inputs.version }}
EVENT_NAME: ${{ github.event_name }}
run: |
set -euo pipefail
# On a push the first line of the commit message is used; on a manual
# dispatch the version input is used (falling back to version.txt).
# Examples:
# v26.2-1.0.0 -> stable release
# v26.2-1.0.0-beta -> beta prerelease
# v26.2-1.0.0-alpha.1 -> alpha prerelease
# v26.2-1.0.0-rc1 -> release-candidate prerelease
if [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
RELEASE_INPUT="${VERSION_INPUT}"
if [[ -z "$RELEASE_INPUT" ]]; then
RELEASE_INPUT="$(cat version.txt)"
fi
else
RELEASE_INPUT="${COMMIT_TITLE%%$'\n'*}"
fi
RELEASE_INPUT="${RELEASE_INPUT#v}"
RELEASE_INPUT="${RELEASE_INPUT// /-}"
RELEASE_INPUT="${RELEASE_INPUT,,}"
if [[ "$RELEASE_INPUT" =~ ^(.+)-(stable|beta|alpha|rc)([.-]?[0-9]+)?$ ]]; then
BASE_VERSION="${BASH_REMATCH[1]}"
CHANNEL="${BASH_REMATCH[2]}"
CHANNEL_SUFFIX="${BASH_REMATCH[3]:-}"
else
BASE_VERSION="$RELEASE_INPUT"
CHANNEL="stable"
CHANNEL_SUFFIX=""
fi
if [[ ! "$BASE_VERSION" =~ ^[0-9]+([.][0-9]+)*(-[0-9]+([.][0-9]+)*)?$ ]]; then
echo "Invalid release commit format: v${RELEASE_INPUT}" >&2
echo "Expected examples: v26.2-1.0.0, v26.2-1.0.0-beta, v26.2-1.0.0-alpha.1, or v26.2-1.0.0-rc1" >&2
exit 1
fi
if [[ "$CHANNEL" == "stable" && -z "$CHANNEL_SUFFIX" ]]; then
VERSION="$BASE_VERSION"
PRERELEASE=false
elif [[ "$CHANNEL" == "stable" ]]; then
VERSION="${BASE_VERSION}-stable${CHANNEL_SUFFIX}"
PRERELEASE=false
else
VERSION="${BASE_VERSION}-${CHANNEL}${CHANNEL_SUFFIX}"
PRERELEASE=true
fi
# The release tag has no "v" prefix (e.g. 26.2-1.0.0-beta),
# even though the triggering commit message starts with "v".
TAG="${VERSION}"
RELEASE_NAME="DedicatedPower ${VERSION}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "name=${RELEASE_NAME}" >> "$GITHUB_OUTPUT"
echo "channel=${CHANNEL}" >> "$GITHUB_OUTPUT"
echo "prerelease=${PRERELEASE}" >> "$GITHUB_OUTPUT"
echo "Version: ${VERSION}"
echo "Channel: ${CHANNEL}"
echo "Prerelease: ${PRERELEASE}"
echo "Tag: ${TAG}"
- name: Extract changelog section
id: changelog
shell: bash
run: |
set -euo pipefail
VERSION="${{ steps.release.outputs.version }}"
# Grab the Keep a Changelog section for this version (## [<version>] ...)
if [[ ! -f CHANGELOG.md ]]; then
SECTION=""
else
SECTION="$(awk -v v="$VERSION" '
index($0, "## [" v "]") == 1 { found = 1; print; next }
found && /^## / { exit }
found { print }
' CHANGELOG.md)"
fi
if [[ -z "$SECTION" ]]; then
SECTION="*No changelog entry found for version ${VERSION}.*"
fi
# EOF-delimited output so multiline content survives workflow outputs
{
echo "section<<CHANGELOG_EOF"
echo "$SECTION"
echo "CHANGELOG_EOF"
} >> "$GITHUB_OUTPUT"
- name: Check for an existing release tag
env:
RELEASE_TAG: ${{ steps.release.outputs.tag }}
run: |
set -euo pipefail
if git ls-remote --exit-code --refs origin "refs/tags/${RELEASE_TAG}" >/dev/null 2>&1; then
echo "A release tag named ${RELEASE_TAG} already exists. Use a new version in the commit message." >&2
exit 1
fi
- name: Build mod
run: ./gradlew clean build -Pmod_version="${{ steps.release.outputs.version }}"
- name: Select release JAR
id: artifact
shell: bash
run: |
set -euo pipefail
mapfile -t JARS < <(find build/libs -maxdepth 1 -type f -name '*.jar' \
! -name '*-sources.jar' \
! -name '*-dev.jar' \
-print | sort)
if [[ "${#JARS[@]}" -ne 1 ]]; then
echo "Expected exactly one release JAR, found ${#JARS[@]}" >&2
printf '%s\n' "${JARS[@]}"
ls -la build/libs
exit 1
fi
JAR="${JARS[0]}"
echo "path=${JAR}" >> "$GITHUB_OUTPUT"
echo "Selected artifact: ${JAR}"
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.release.outputs.tag }}
name: ${{ steps.release.outputs.name }}
target_commitish: ${{ github.sha }}
prerelease: ${{ steps.release.outputs.prerelease }}
generate_release_notes: true
fail_on_unmatched_files: true
body: |
## DedicatedPower ${{ steps.release.outputs.version }}
**Release channel:** `${{ steps.release.outputs.channel }}`
**Minecraft target:** See the Minecraft version declared in the project metadata.
${{ steps.changelog.outputs.section }}
---
This release was built automatically from commit `${{ github.sha }}`.
files: ${{ steps.artifact.outputs.path }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}