9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-19 06:49:27 +00:00

update release script and workflow (again)

This commit is contained in:
NONPLAYT
2025-12-14 15:31:20 +03:00
parent c74ca05912
commit 735220b6b7
2 changed files with 116 additions and 78 deletions

View File

@@ -10,10 +10,11 @@ jobs:
build:
runs-on: blacksmith-8vcpu-ubuntu-2204
if: "!contains(github.event.commits[0].message, '[ci-skip]')"
env:
BUILD_NUMBER: ${{ github.run_number }}
API_KEY: ${{ secrets.API_KEY }}
outputs:
build_number: ${{ env.BUILD_NUMBER }}
jar_file: ${{ steps.prepare_jar.outputs.jar_file }}
version: ${{ steps.prepare_jar.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
@@ -66,23 +67,46 @@ jobs:
- name: Build Paperclip Jar
run: ./gradlew createMojmapPaperclipJar --stacktrace --parallel --no-daemon
- name: Prepare and Move Paperclip Jar
id: prepare_jar
run: |
VERSION="1.21.10"
BUILD="${BUILD_NUMBER}"
JAR_NAME="divinemc-${VERSION}-${BUILD}.jar"
mv divinemc-server/build/libs/divinemc-paperclip-*-mojmap.jar divinemc-server/build/libs/${JAR_NAME}
echo "jar_file=divinemc-server/build/libs/${JAR_NAME}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "JAR_FILE=divinemc-server/build/libs/${JAR_NAME}" >> $GITHUB_ENV
- name: Upload to API
env:
API_URL: 'https://api.bxteam.org'
API_KEY: ${{ secrets.ATLAS_API_KEY }}
PROJECT_KEY: 'divinemc'
VERSION_BRANCH: 'ver/1.21.10'
BUILD_NUMBER: ${{ github.run_number }}
JAR_FILE: ${{ env.JAR_FILE }}
- name: Upload Build to API
run: bash scripts/uploadBuild.sh
env:
BUILD_NUMBER: ${{ env.BUILD_NUMBER }}
API_KEY: ${{ secrets.API_KEY }}
- name: Get MC Version
id: mcversion
run: |
mcversion=$(grep "mcVersion" gradle.properties | cut -d'=' -f2 | sed 's/\r//')
echo "version=$mcversion" >> $GITHUB_OUTPUT
- name: Update Version Tag
uses: actions/github-script@v8
with:
script: |
const tag = `ver-${{ steps.mcversion.outputs.version }}`;
const ref = `refs/tags/${tag}`;
console.log(`Updating tag: ${tag}`);
try {
await github.rest.git.updateRef({
owner: context.repo.owner,
repo: context. repo.repo,
ref: `tags/${tag}`,
sha: context.sha,
force: true
});
console.log(`✅ Tag ${tag} updated successfully`);
} catch (error) {
if (error.status === 404) {
await github.rest.git. createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: ref,
sha: context. sha
});
console.log(`✅ Tag ${tag} created successfully`);
} else {
throw error;
}
}

View File

@@ -1,76 +1,90 @@
#!/bin/bash
#!/usr/bin/env bash
set -e
prop() {
grep "${1}" gradle.properties | cut -d'=' -f2 | sed 's/\r//'
}
[ -z "$API_URL" ] && { echo "Error: API_URL not set"; exit 1; }
[ -z "$API_KEY" ] && { echo "Error: API_KEY not set"; exit 1; }
[ -z "$PROJECT_KEY" ] && { echo "Error: PROJECT_KEY not set"; exit 1; }
commitid=$(git log --pretty='%h' -1)
mcversion=$(prop mcVersion)
version=$(prop version)
experimental=$(prop experimental)
tagid="$mcversion-$BUILD_NUMBER-$commitid"
jarName="divinemc-$mcversion-$BUILD_NUMBER.jar"
divinemcid="DivineMC-$tagid"
MC_VERSION=$(prop mcVersion)
[ -z "$MC_VERSION" ] && { echo "Error: mcVersion not found in gradle.properties"; exit 1; }
channel=$([ "$experimental" = "true" ] && echo "BETA" || echo "STABLE")
VERSION_BRANCH=${VERSION_BRANCH:-"ver/$MC_VERSION"}
mv divinemc-server/build/libs/divinemc-paperclip-"$version"-mojmap.jar "$jarName"
if [ "$(prop experimental)" = "true" ]; then
CHANNEL="BETA"
else
CHANNEL="STABLE"
fi
echo "📦 Collecting commits..."
last_tag=$(git describe --tags --abbrev=0)
number=$(git log --oneline "$last_tag"..HEAD | wc -l)
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
COMMIT_COUNT=$(git log --oneline "$VERSION_BRANCH" ^"$LAST_TAG" 2>/dev/null | wc -l | tr -d ' ')
else
COMMIT_COUNT=$(git log --oneline "$VERSION_BRANCH" 2>/dev/null | wc -l | tr -d ' ')
fi
commits_json="["
first=true
if [ "$COMMIT_COUNT" -gt 0 ]; then
COMMITS_JSON="["
FIRST=true
while IFS= read -r sha && IFS= read -r message && IFS= read -r time; do
if [ "$FIRST" = true ]; then
FIRST=false
else
COMMITS_JSON="$COMMITS_JSON,"
fi
while IFS= read -r line; do
commit_sha=$(echo "$line" | awk '{print $1}')
commit_message=$(echo "$line" | cut -d' ' -f2-)
commit_time=$(git show -s --format=%cI "$commit_sha")
message=$(echo "$message" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed 's/\t/\\t/g' | tr -d '\n\r')
COMMITS_JSON="$COMMITS_JSON{\"sha\":\"$sha\",\"message\":\"$message\",\"time\":\"$time\"}"
done < <(git log --pretty='%H%n%s%n%cI' "$VERSION_BRANCH" -"$COMMIT_COUNT")
COMMITS_JSON="$COMMITS_JSON]"
else
COMMITS_JSON="[]"
fi
if [ "$first" = true ]; then
first=false
else
commits_json+=","
fi
METADATA=$(cat <<EOF
{
"buildNumber": ${BUILD_NUMBER},
"channel": "$CHANNEL",
"commits": $COMMITS_JSON
}
EOF
)
escaped_message=$(echo "$commit_message" | sed 's/"/\\"/g')
echo "Uploading: $PROJECT_KEY $MC_VERSION build #$BUILD_NUMBER ($CHANNEL)"
commits_json+="{\"sha\":\"$commit_sha\",\"message\":\"$escaped_message\",\"time\":\"$commit_time\"}"
done < <(git log --pretty='%h %s' "-$number")
UPLOAD_RESPONSE=$(curl -s -w "\n%{http_code}" \
-X POST "$API_URL/v2/projects/$PROJECT_KEY/versions/$MC_VERSION/builds/upload" \
-H "x-api-key: $API_KEY" \
-F "file=@$JAR_FILE" \
-F "metadata=$METADATA")
commits_json+="]"
HTTP_BODY=$(echo "$UPLOAD_RESPONSE" | head -n -1)
HTTP_CODE=$(echo "$UPLOAD_RESPONSE" | tail -n 1)
metadata_json="{\"buildNumber\":$BUILD_NUMBER,\"channel\":\"$channel\",\"commits\":$commits_json}"
if [ "$HTTP_CODE" -eq 200 ] || [ "$HTTP_CODE" -eq 201 ]; then
BUILD_ID=$(echo "$HTTP_BODY" | grep -o '"id":[0-9]*' | grep -o '[0-9]*')
echo "✓ Build #$BUILD_ID uploaded successfully"
exit 0
else
echo "✗ Upload failed (HTTP $HTTP_CODE)"
echo "$HTTP_BODY"
echo "$metadata_json" | jq . > metadata.json 2>/dev/null || echo "$metadata_json" > metadata.json
API_URL="https://api.bxteam.org/v2/projects/divinemc/versions/$mcversion/builds/upload"
API_KEY="${API_KEY:-}"
if [ -z "$API_KEY" ]; then
echo "❌ Error: API_KEY environment variable is not set"
exit 1
fi
echo ""
echo "🚀 Uploading build to API..."
echo " URL: $API_URL"
echo " File: $jarName"
echo " Build: $BUILD_NUMBER"
echo " Channel: $channel"
echo " Commits: $number"
response=$(curl -X POST "$API_URL" \
-H "Authorization: Bearer $API_KEY" \
-F "file=@$jarName" \
-F "metadata=$metadata_json" \
-w "\n%{http_code}" \
-s)
http_code=$(echo "$response" | tail -n1)
response_body=$(echo "$response" | sed '$d')
echo ""
echo "📡 Response:"
echo "$response_body" | jq . 2>/dev/null || echo "$response_body"
if [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then
echo ""
echo "✅ Build uploaded successfully!"
echo " Build Number: $BUILD_NUMBER"
echo " Version: $mcversion"
echo " Channel: $channel"
else
echo ""
echo "❌ Upload failed with HTTP status: $http_code"
exit 1
fi