From ae5783aa1d691f640c3d50783f155b5c0d604ea6 Mon Sep 17 00:00:00 2001 From: TGGamesYT Date: Tue, 31 Mar 2026 14:05:03 +0200 Subject: [PATCH] gitea workflow I hope --- .gitea/workflows/build.yml | 128 +++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 .gitea/workflows/build.yml diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..3cd48f9 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,128 @@ +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: 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)" \ No newline at end of file