Skip to content

Update changelog

Update changelog #45

name: Build Snapshot
on:
push:
branches: [ development ]
workflow_dispatch:
permissions:
contents: write
pull-requests: write
concurrency:
group: build-snapshot-${{ github.ref }}
cancel-in-progress: true
jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 30
env:
JAVA_VERSION: '21'
PROJECT_VERSION: ""
BUILD_NUMBER: 0
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
GH_TOKEN: ${{ secrets.TOKEN_GITHUB }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
HANGAR_TOKEN: ${{ secrets.HANGAR_TOKEN }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
POLYMART_TOKEN: ${{ secrets.POLYMART_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Java ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ env.JAVA_VERSION }}
cache: gradle
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: Read version from build.gradle.kts
id: ver
shell: bash
run: |
VERSION=$(grep -Po 'version\s*=\s*"([^"]+)' build.gradle.kts | cut -d'"' -f2)
echo "PROJECT_VERSION=$VERSION"
echo "PROJECT_VERSION=$VERSION" >> "$GITHUB_ENV"
- name: Ensure PR to master exists with release title
env:
HEAD_BRANCH: ${{ github.ref_name }}
BASE_BRANCH: master
shell: bash
run: |
set -euo pipefail
: "${PROJECT_VERSION?Missing PROJECT_VERSION}"
TITLE="Release (${PROJECT_VERSION})"
# Skip if on base branch
if [[ "$HEAD_BRANCH" == "$BASE_BRANCH" ]]; then
echo "On $BASE_BRANCH; nothing to do."; exit 0
fi
OWNER_REPO="${GITHUB_REPOSITORY}"
OWNER="${OWNER_REPO%%/*}"
echo "Checking for existing open PR from $HEAD_BRANCH to $BASE_BRANCH"
PR_NUMBER=$(gh pr list \
--state open \
--base "$BASE_BRANCH" \
--head "$HEAD_BRANCH" \
--json number \
--jq '.[0].number' || true)
if [[ -z "${PR_NUMBER}" || "${PR_NUMBER}" == "null" ]]; then
PR_NUMBER=$(gh pr list \
--state open \
--base "$BASE_BRANCH" \
--head "$OWNER:$HEAD_BRANCH" \
--json number \
--jq '.[0].number' || true)
fi
if [[ -z "${PR_NUMBER}" || "${PR_NUMBER}" == "null" ]]; then
echo "No open PR found. Creating one with title: $TITLE"
BODY=$(cat <<'EOF'
This pull request was automatically created by the snapshot build to keep master up to date with development.
EOF
)
# Try unqualified head first, then qualified
if ! gh pr create --base "$BASE_BRANCH" --head "$HEAD_BRANCH" --title "$TITLE" --body "$BODY"; then
gh pr create --base "$BASE_BRANCH" --head "$OWNER:$HEAD_BRANCH" --title "$TITLE" --body "$BODY"
fi
else
echo "Open PR #$PR_NUMBER exists. Ensuring title is set to: $TITLE"
gh pr edit "$PR_NUMBER" --title "$TITLE" || echo "Warning: failed to update PR title"
fi
- name: Compute beta BUILD_NUMBER from GitHub Releases
shell: bash
run: |
set -euo pipefail
: "${PROJECT_VERSION?Missing PROJECT_VERSION}"
# List existing release tag names, strip quotes, and normalize optional leading 'v'
LINES=$(gh release list --limit 200 --json tagName --jq '.[].tagName' | tr -d '"' || true)
LINES=$(printf '%s\n' "$LINES" | sed -E 's/^v//' )
# Match exact tags like "<version>-SNAPSHOT-bNN"
CANDS=$(printf '%s\n' "$LINES" | grep -E "^${PROJECT_VERSION}-SNAPSHOT-b[0-9]+$" || true)
NUMS=$(printf '%s\n' "$CANDS" | sed -E "s/^${PROJECT_VERSION}-SNAPSHOT-b([0-9]+)$/\1/" || true)
MAX_B=$(printf '%s\n' "${NUMS:-}" | grep -E '^[0-9]+$' | sort -n | tail -1 || true)
[[ -z "${MAX_B:-}" ]] && MAX_B=0
BUILD_NUMBER=$((MAX_B + 1))
echo "BUILD_NUMBER=$BUILD_NUMBER" >> "$GITHUB_ENV"
echo "Next build number: $BUILD_NUMBER for ${PROJECT_VERSION}-SNAPSHOT"
- name: Build MyPet
run: |
./gradlew --no-daemon build -PbuildType=dev -PBUILD_NUMBER=${BUILD_NUMBER} -PSENTRY_AUTH_TOKEN=${SENTRY_AUTH_TOKEN}
- name: Find and rename shaded JAR with build number
id: findjar
shell: bash
run: |
set -euo pipefail
shopt -s nullglob
CANDIDATES=(build/libs/MyPet-*.jar)
# Filter out sources/javadoc/plain jars
FILTERED=()
for j in "${CANDIDATES[@]}"; do
[[ "$j" =~ -(sources|javadoc|plain)\.jar$ ]] || FILTERED+=("$j")
done
if (( ${#FILTERED[@]} == 0 )); then
echo "No candidate jar found in build/libs" >&2
ls -la build/libs || true
exit 1
fi
JAR="${FILTERED[0]}"
DIR=$(dirname "$JAR")
BASE=$(basename "$JAR" .jar)
NEW_NAME="${BASE}-SNAPSHOT-b${BUILD_NUMBER}.jar"
NEW_PATH="${DIR}/${NEW_NAME}"
mv "$JAR" "$NEW_PATH"
echo "jar=$NEW_PATH" >> "$GITHUB_OUTPUT"
echo "filename=$NEW_NAME" >> "$GITHUB_OUTPUT"
echo "Renamed to: $NEW_NAME"
- name: Upload workflow artifact (jar)
uses: actions/upload-artifact@v4
with:
name: mypet-snapshot-jar
path: ${{ steps.findjar.outputs.jar }}
if-no-files-found: error
retention-days: 90
- name: Read changelog
id: changelog
shell: bash
run: |
CHANGELOG_FILE=".github/changelogs/${PROJECT_VERSION}-SNAPSHOT.md"
if [[ -f "$CHANGELOG_FILE" ]]; then
echo "Found changelog: $CHANGELOG_FILE"
{
echo 'content<<EOF'
cat "$CHANGELOG_FILE"
echo ""
echo 'EOF'
} >> "$GITHUB_OUTPUT"
else
echo "No changelog found at $CHANGELOG_FILE, using default message"
echo "content=Development snapshot. **Do NOT use in production!**" >> "$GITHUB_OUTPUT"
fi
- name: Extract supported NMS modules
id: modules
shell: bash
run: |
# Extract bukkitPackets from build.gradle.kts for update checker compatibility
BUKKIT_PACKETS=$(grep -Po 'val bukkitPackets by extra\("([^"]+)"\)' build.gradle.kts | sed 's/.*("\(.*\)")/\1/')
echo "list=$BUKKIT_PACKETS" >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.PROJECT_VERSION }}-SNAPSHOT-b${{ env.BUILD_NUMBER }}
name: v${{ env.PROJECT_VERSION }}-SNAPSHOT-b${{ env.BUILD_NUMBER }}
prerelease: true
overwrite_files: false
files: ${{ steps.findjar.outputs.jar }}
body: |
${{ steps.changelog.outputs.content }}
---
Supported NMS Versions:
${{ steps.modules.outputs.list }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to Modrinth
uses: cloudnode-pro/modrinth-publish@v2
with:
token: ${{ env.MODRINTH_TOKEN }}
project: SnE2iTno
version: ${{ env.PROJECT_VERSION }}-SNAPSHOT-b${{ env.BUILD_NUMBER }}
name: v${{ env.PROJECT_VERSION }}-SNAPSHOT-b${{ env.BUILD_NUMBER }}
changelog: ${{ steps.changelog.outputs.content }}
channel: alpha
featured: false
loaders: |-
paper
spigot
game-versions: |-
1.8.8
1.12.2
1.16.5
1.17.1
1.18.2
1.19.x
1.20.x
1.21.x
files: ${{ steps.findjar.outputs.jar }}
# - name: Publish to Hangar
# run: |
# ./gradlew publishPluginPublicationToHangar --no-daemon \
# -PbuildType=dev \
# -PHANGAR_VERSION=${PROJECT_VERSION}-SNAPSHOT-b${BUILD_NUMBER} \
# -PHANGAR_FILE=${{ steps.findjar.outputs.jar }} \
# -PHANGAR_CHANGELOG="${{ steps.changelog.outputs.content }}"
- name: Publish to Polymart
run: ./gradlew createPolymartRelease --no-daemon -PPOLYMART_TOKEN=${POLYMART_TOKEN} -PPOLYMART_VERSION=${PROJECT_VERSION}-SNAPSHOT-b${BUILD_NUMBER} -PPOLYMART_FILE=${{ steps.findjar.outputs.jar }}
- name: Send a Discord webhook notification
env:
CHANGELOG: ${{ steps.changelog.outputs.content }}
run: |
VERSION="${{ env.PROJECT_VERSION }}-SNAPSHOT-b${{ env.BUILD_NUMBER }}"
MODRINTH_URL="https://modrinth.com/plugin/mypet/version/${VERSION}"
# Truncate changelog if it exceeds Discord's 4096 char limit
if [[ ${#CHANGELOG} -gt 4000 ]]; then
CHANGELOG="${CHANGELOG:0:3997}..."
fi
# Build JSON payload safely with jq
PAYLOAD=$(jq -n \
--arg version "$VERSION" \
--arg changelog "$CHANGELOG" \
--arg modrinth_url "$MODRINTH_URL" \
'{
content: ("MyPet **" + $version + "** has released!\n<@&1431929679626895450>\n**Please test on development servers only.**\n**We may be unable to help resolve issues when using snapshots on production servers!**"),
embeds: [
{
title: "Changelog",
description: $changelog,
color: 4429633,
fields: []
},
{
title: "Download from Modrinth",
url: $modrinth_url
}
],
components: [],
username: "MyPet Snapshot",
avatar_url: "https://raw.githubusercontent.com/MyPetORG/MyPet/master/.github/readme-images/logo.png"
}')
RESPONSE=$(curl -H "Content-Type: application/json" -X POST -d "$PAYLOAD" ${{ secrets.WEBHOOK_URL }})
echo "Webhook server response: $RESPONSE"