Files
szar/.gitea/workflows/build.yml
TGGamesYT 034fac759c
Some checks failed
Build Minecraft Mod / build (push) Successful in 3m57s
Build Minecraft Mod / release (push) Failing after 17s
only upload the correct jar file
2026-03-31 17:05:57 +02:00

143 lines
4.0 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 "ERROR: gradlew not found in repository!"
echo "Please run 'gradle wrapper' locally and push the files."
exit 1
fi
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Build mod
run: ./gradlew build --no-daemon --max-workers=1 -Dorg.gradle.jvmargs="-Xmx1g -XX:MaxMetaspaceSize=256m"
- 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: apt-get update && apt-get install -y jq
- name: Read mod info from gradle.properties
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"
echo "NAME=$NAME" >> $GITEA_ENV
echo "VERSION=$VERSION" >> $GITEA_ENV
echo "JAR=$JAR" >> $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
uses: softprops/action-gh-release@v1
with:
files: build/libs/*.jar
tag_name: ${{ env.TAG }}
env:
GITHUB_TOKEN: ${{ secrets.GITEATOKEN }}
- 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 the mod JAR
run: |
if [ ! -f "$JAR" ]; then
echo "Error: JAR not found: $JAR"
exit 1
fi
curl -X POST \
-H "Authorization: token ${{ secrets.GITEATOKEN }}" \
-H "Content-Type: application/java-archive" \
--data-binary @"$JAR" \
"${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases/${RELEASE_ID}/assets?name=$(basename $JAR)"