124 lines
4.9 KiB
YAML
124 lines
4.9 KiB
YAML
name: Auto Release
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- name: Setup JDK 25
|
|
run: |
|
|
echo "Setting up JDK 25..."
|
|
apt-get update -qq
|
|
apt-get install -y -qq wget unzip
|
|
wget -q https://api.adoptium.net/v3/binary/latest/25/ga/linux/x64/jdk/hotspot/normal/eclipse?project=jdk -O /tmp/jdk25.tar.gz
|
|
tar -xzf /tmp/jdk25.tar.gz -C /opt
|
|
export JAVA_HOME=$(ls -d /opt/jdk-25* | head -1)
|
|
echo "JAVA_HOME=$JAVA_HOME" >> $GITHUB_ENV
|
|
echo "$JAVA_HOME/bin" >> $GITHUB_PATH
|
|
echo "JDK 25 installed: $($JAVA_HOME/bin/java -version 2>&1 | head -1)"
|
|
echo "Setup completed"
|
|
|
|
- name: Setup Maven
|
|
run: |
|
|
echo "Setting up Maven..."
|
|
apt-get install -y -qq maven
|
|
echo "Maven version: $(mvn -version 2>&1 | head -1)"
|
|
echo "Setup completed"
|
|
|
|
- name: Checkout code
|
|
run: |
|
|
echo "Checking out code..."
|
|
GIT_HOST=${GITHUB_SERVER_URL#http://}
|
|
GIT_HOST=${GIT_HOST#https://}
|
|
rm -rf /workspace/youpaishidifu/Sdf1_login/*
|
|
rm -rf /workspace/youpaishidifu/Sdf1_login/.[!.]*
|
|
git clone "http://${GIT_HOST}/$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]').git" .
|
|
echo "Checkout completed"
|
|
|
|
- name: Build with Maven
|
|
run: |
|
|
echo "Building with Maven..."
|
|
mvn -B clean package -DskipTests
|
|
echo "Build completed"
|
|
|
|
- name: Verify JAR
|
|
run: |
|
|
echo "Verifying JAR..."
|
|
ls -la target/*.jar
|
|
echo "Verification completed"
|
|
|
|
- name: Generate Release Notes
|
|
run: |
|
|
echo "Generating release notes..."
|
|
VERSION=$(grep "^version:" src/main/resources/plugin.yml | awk '{print $2}' | tr -d '\r\n ')
|
|
TAG="v$VERSION"
|
|
|
|
# Generate release notes from last 10 commits
|
|
echo "## Changes in $TAG" > /tmp/release_body.md
|
|
echo "" >> /tmp/release_body.md
|
|
git log --format="- **%h** %s (%an, %ad)" --date=short -10 >> /tmp/release_body.md
|
|
echo "" >> /tmp/release_body.md
|
|
echo "### Full changelog" >> /tmp/release_body.md
|
|
echo "" >> /tmp/release_body.md
|
|
echo "[View all commits](/youpaishidifu/Sdf1_login/commits/main)" >> /tmp/release_body.md
|
|
|
|
echo "Release notes generated for $TAG"
|
|
cat /tmp/release_body.md
|
|
|
|
- name: Create Release
|
|
env:
|
|
GITEA_TOKEN: 194187cbdc8e1f1d3bc810b1b9e07ddc904a1f73
|
|
run: |
|
|
set -e
|
|
VERSION=$(grep "^version:" src/main/resources/plugin.yml | awk '{print $2}' | tr -d '\r\n ')
|
|
TAG="v$VERSION"
|
|
BASE="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY"
|
|
echo "Version: $VERSION, Tag: $TAG"
|
|
|
|
echo "=== Checking existing tag $TAG ==="
|
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -H "Authorization: token $GITEA_TOKEN" "$BASE/releases/tags/$TAG")
|
|
echo "Check tag HTTP: $HTTP_CODE"
|
|
|
|
if [ "$HTTP_CODE" = "200" ]; then
|
|
OLD_ID=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$BASE/releases/tags/$TAG" | python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))")
|
|
echo "Tag $TAG exists (release #$OLD_ID), deleting..."
|
|
curl -s -X DELETE -H "Authorization: token $GITEA_TOKEN" "$BASE/releases/$OLD_ID"
|
|
curl -s -X DELETE -H "Authorization: token $GITEA_TOKEN" "$BASE/tags/$TAG"
|
|
sleep 1
|
|
fi
|
|
|
|
echo "=== Creating release ==="
|
|
# Use python3 to construct proper JSON
|
|
python3 -c "
|
|
import json, sys
|
|
body = open('/tmp/release_body.md').read()
|
|
data = {'tag_name': '$TAG', 'name': '$TAG', 'body': body, 'draft': False, 'prerelease': False}
|
|
print(json.dumps(data))
|
|
" > /tmp/release_payload.json
|
|
|
|
RESP=$(curl -s -X POST \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-H "Content-Type: application/json" \
|
|
"$BASE/releases" \
|
|
-d @/tmp/release_payload.json)
|
|
|
|
RELEASE_ID=$(echo "$RESP" | python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))")
|
|
echo "Created release #$RELEASE_ID"
|
|
|
|
echo "=== Uploading artifact ==="
|
|
JAR=$(ls target/*.jar | head -1)
|
|
UPLOAD_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
|
|
-H "Authorization: token $GITEA_TOKEN" \
|
|
-H "Content-Type: application/jar" \
|
|
"$BASE/releases/$RELEASE_ID/assets?name=$(basename $JAR)" \
|
|
--data-binary "@$JAR")
|
|
echo "Upload HTTP: $UPLOAD_CODE"
|
|
|
|
echo "=== Release $TAG created successfully ==="
|
|
|