144 lines
3.9 KiB
YAML
144 lines
3.9 KiB
YAML
name: Build Minecraft Mod
|
||
|
||
on:
|
||
push:
|
||
branches: [ main ]
|
||
|
||
jobs:
|
||
build:
|
||
runs-on: ubuntu-latest
|
||
|
||
steps:
|
||
- name: Checkout
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Set up JDK 21
|
||
uses: actions/setup-java@v4
|
||
with:
|
||
distribution: temurin
|
||
java-version: 21
|
||
|
||
- name: Ensure Gradle wrapper exists
|
||
run: |
|
||
if [ ! -f "./gradlew" ]; then
|
||
echo "gradlew not found, generating wrapper..."
|
||
|
||
# Install Gradle temporarily
|
||
sudo apt-get update
|
||
sudo apt-get install -y gradle
|
||
|
||
# Generate wrapper (uses project’s build.gradle)
|
||
gradle wrapper
|
||
|
||
else
|
||
echo "gradlew already exists"
|
||
fi
|
||
|
||
- name: Make gradlew executable
|
||
run: chmod +x ./gradlew
|
||
|
||
- name: Build mod
|
||
run: ./gradlew build
|
||
|
||
- name: Read mod info
|
||
id: mod_info
|
||
run: |
|
||
NAME=$(grep "^archives_base_name" gradle.properties | cut -d'=' -f2)
|
||
VERSION=$(grep "^mod_version" gradle.properties | cut -d'=' -f2)
|
||
|
||
if [ -z "$NAME" ] || [ -z "$VERSION" ]; then
|
||
echo "Failed to read mod info"
|
||
exit 1
|
||
fi
|
||
|
||
JAR="build/libs/${NAME}-${VERSION}.jar"
|
||
|
||
if [ ! -f "$JAR" ]; then
|
||
echo "Jar not found: $JAR"
|
||
exit 1
|
||
fi
|
||
|
||
echo "NAME=$NAME" >> $GITEA_ENV
|
||
echo "VERSION=$VERSION" >> $GITEA_ENV
|
||
echo "JAR=$JAR" >> $GITEA_ENV
|
||
|
||
- name: Upload artifact
|
||
uses: actions/upload-artifact@v3
|
||
with:
|
||
name: minecraft-mod
|
||
path: ${{ env.JAR }}
|
||
|
||
release:
|
||
runs-on: ubuntu-latest
|
||
needs: build
|
||
|
||
steps:
|
||
- name: Checkout
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Download artifact
|
||
uses: actions/download-artifact@v3
|
||
with:
|
||
name: minecraft-mod
|
||
path: ./release-artifacts/
|
||
|
||
- name: Install jq
|
||
run: sudo apt-get update && sudo apt-get install -y jq
|
||
|
||
- name: Read mod info again
|
||
run: |
|
||
NAME=$(grep "^archives_base_name" gradle.properties | cut -d'=' -f2)
|
||
VERSION=$(grep "^mod_version" gradle.properties | cut -d'=' -f2)
|
||
|
||
echo "NAME=$NAME" >> $GITEA_ENV
|
||
echo "VERSION=$VERSION" >> $GITEA_ENV
|
||
|
||
- name: Determine tag
|
||
run: |
|
||
BASE="${NAME}-${VERSION}"
|
||
TAG="$BASE"
|
||
i=1
|
||
|
||
while true; do
|
||
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
|
||
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \
|
||
"${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases/tags/$TAG")
|
||
|
||
if [ "$STATUS" = "404" ]; then
|
||
break
|
||
fi
|
||
|
||
TAG="${BASE}($i)"
|
||
i=$((i+1))
|
||
done
|
||
|
||
echo "TAG=$TAG" >> $GITEA_ENV
|
||
|
||
- name: Create release
|
||
run: |
|
||
curl -X POST "${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases" \
|
||
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \
|
||
-H "Content-Type: application/json" \
|
||
-d "{
|
||
\"tag_name\": \"${TAG}\",
|
||
\"name\": \"${TAG}\"
|
||
}"
|
||
|
||
- name: Get release ID
|
||
run: |
|
||
RELEASE_ID=$(curl -s \
|
||
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \
|
||
"${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases/tags/${TAG}" \
|
||
| jq -r '.id')
|
||
|
||
echo "RELEASE_ID=$RELEASE_ID" >> $GITEA_ENV
|
||
|
||
- name: Upload jar to release
|
||
run: |
|
||
FILE=$(ls ./release-artifacts/*.jar | head -n 1)
|
||
|
||
curl -X POST \
|
||
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \
|
||
-H "Content-Type: application/java-archive" \
|
||
--data-binary @"$FILE" \
|
||
"${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases/${RELEASE_ID}/assets?name=$(basename $FILE)" |