whitelist-neoforge/.gitea/workflows/build.yml

73 lines
2.4 KiB
YAML

name: Build and Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
jobs:
build:
runs-on: node-latest
timeout-minutes: 15
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: |
apt-get update
apt-get install -y default-jdk-headless jq curl
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
cache: 'gradle'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Extract version from gradle.properties
id: version
run: |
VERSION=$(grep "^mod_version=" gradle.properties | cut -d'=' -f2 | tr -d ' ')
echo "mod_version=$VERSION" >> $GITHUB_OUTPUT
echo "Mod version: $VERSION"
- name: Build with Gradle
run: ./gradlew jar --no-daemon
- name: Find JAR file
id: jar
run: |
JAR_PATH=$(find build/libs -name "*.jar" ! -name "*-sources.jar" ! -name "*-javadoc.jar" -type f | head -n 1)
JAR_NAME=$(basename "$JAR_PATH")
echo "jar_path=$JAR_PATH" >> $GITHUB_OUTPUT
echo "jar_name=$JAR_NAME" >> $GITHUB_OUTPUT
echo "Found JAR: $JAR_NAME at $JAR_PATH"
- name: Create Release
id: create_release
run: |
TAG_NAME="${{ github.ref_name }}"
RESPONSE=$(curl -s -X POST \
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"tag_name\":\"$TAG_NAME\",\"name\":\"Release $TAG_NAME\",\"draft\":false,\"prerelease\":false}" \
"https://git.itqop.pw/api/v1/repos/itqop/whitelist-neoforge/releases")
RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id')
echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT
echo "Release ID: $RELEASE_ID"
- name: Upload JAR to Release
run: |
curl -s -X POST \
-H "Authorization: token ${{ secrets.RELEASE_TOKEN }}" \
-F "attachment=@${{ steps.jar.outputs.jar_path }}" \
"https://git.itqop.pw/api/v1/repos/itqop/whitelist-neoforge/releases/${{ steps.create_release.outputs.release_id }}/assets?name=${{ steps.jar.outputs.jar_name }}"
echo "✓ JAR uploaded to Release"