fix: proper release workflow with Java build
This commit is contained in:
@@ -7,11 +7,17 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
run: |
|
run: |
|
||||||
echo "Checking out code..."
|
echo "Checking out code..."
|
||||||
git clone https://github.com/actions/checkout.git /tmp/checkout
|
git config --global user.email "action@gitea.com"
|
||||||
|
git config --global user.name "Action"
|
||||||
|
git clone "https://x-access-token:${GITEA_TOKEN}@${GITEA_HOST}/$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]').git" /workspace
|
||||||
|
cd /workspace
|
||||||
|
git checkout ${GITHUB_REF#refs/heads/}
|
||||||
echo "Checkout completed"
|
echo "Checkout completed"
|
||||||
|
|
||||||
- name: Setup Java
|
- name: Setup Java
|
||||||
@@ -19,16 +25,57 @@ jobs:
|
|||||||
echo "Setting up Java..."
|
echo "Setting up Java..."
|
||||||
apt-get update -qq
|
apt-get update -qq
|
||||||
apt-get install -y -qq openjdk-21-jdk-headless maven
|
apt-get install -y -qq openjdk-21-jdk-headless maven
|
||||||
|
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
|
||||||
|
echo "JAVA_HOME=$JAVA_HOME" >> $GITHUB_ENV
|
||||||
echo "Java setup completed"
|
echo "Java setup completed"
|
||||||
|
|
||||||
- name: Build with Maven
|
- name: Build with Maven
|
||||||
|
working-directory: /workspace
|
||||||
run: |
|
run: |
|
||||||
echo "Building with Maven..."
|
echo "Building with Maven..."
|
||||||
mvn --version
|
export PATH="$JAVA_HOME/bin:$PATH"
|
||||||
|
mvn -B clean package -DskipTests
|
||||||
echo "Build completed"
|
echo "Build completed"
|
||||||
|
|
||||||
- name: Verify
|
- name: Verify JAR
|
||||||
|
working-directory: /workspace
|
||||||
run: |
|
run: |
|
||||||
|
echo "Verifying JAR..."
|
||||||
|
ls -la target/*.jar
|
||||||
echo "Verification completed"
|
echo "Verification completed"
|
||||||
ls -la
|
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
working-directory: /workspace
|
||||||
|
env:
|
||||||
|
GITEA_TOKEN: ${GITEA_TOKEN}
|
||||||
|
run: |
|
||||||
|
set -e
|
||||||
|
VERSION=$(grep "^version:" src/main/resources/plugin.yml | awk '{print $2}' | tr -d '\r\n ')
|
||||||
|
TAG="v${VERSION}"
|
||||||
|
BASE="http://${GITEA_HOST}/api/v1/repos/$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]')"
|
||||||
|
echo "Version: ${VERSION}, Tag: ${TAG}"
|
||||||
|
|
||||||
|
echo "=== Checking existing tag ${TAG} ==="
|
||||||
|
RESP=$(curl -s -w "\nHTTP_CODE:%{http_code}" -H "Authorization: token ${GITEA_TOKEN}" "${BASE}/releases/tags/${TAG}")
|
||||||
|
HTTP_CODE=$(echo "$RESP" | grep -o "HTTP_CODE:[0-9]*" | cut -d: -f2)
|
||||||
|
echo "Check tag HTTP: ${HTTP_CODE}"
|
||||||
|
|
||||||
|
if [ "$HTTP_CODE" = "200" ]; then
|
||||||
|
OLD_ID=$(echo "$RESP" | head -1 | python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))" 2>/dev/null)
|
||||||
|
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 ==="
|
||||||
|
curl -s -X POST -H "Authorization: token ${GITEA_TOKEN}" -H "Content-Type: application/json" "${BASE}/releases" -d "{"tag_name":"${TAG}","name":"${TAG}","body":"Auto release by Gitea Actions","draft":false,"prerelease":false}"
|
||||||
|
|
||||||
|
echo "=== Uploading artifact ==="
|
||||||
|
JAR=$(ls target/*.jar | head -1)
|
||||||
|
UPLOAD_RESP=$(curl -s -w "\nHTTP_CODE:%{http_code}" -X POST -H "Authorization: token ${GITEA_TOKEN}" -H "Content-Type: application/jar" "${BASE}/releases/tags/${TAG}/assets?name=$(basename ${JAR})" --data-binary "@${JAR}")
|
||||||
|
UPLOAD_CODE=$(echo "$UPLOAD_RESP" | grep -o "HTTP_CODE:[0-9]*" | cut -d: -f2)
|
||||||
|
echo "Upload HTTP: ${UPLOAD_CODE}"
|
||||||
|
echo "$UPLOAD_RESP" | head -1
|
||||||
|
|
||||||
|
echo "=== Release ${TAG} created successfully ==="
|
||||||
|
|||||||
Reference in New Issue
Block a user