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="${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: | # Find the largest JAR file (the main mod file is 120 MiB, others are KiB) JAR_FILE=$(ls -S ./release-artifacts/*.jar | head -n 1) if [ ! -f "$JAR_FILE" ]; then echo "Error: Main JAR not found in ./release-artifacts/" exit 1 fi echo "Uploading largest file: $(basename $JAR_FILE)" curl -X POST \ -H "Authorization: token ${{ secrets.GITEATOKEN }}" \ -H "Content-Type: application/java-archive" \ --data-binary @"$JAR_FILE" \ "${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases/${RELEASE_ID}/assets?name=$(basename $JAR_FILE)"