name: Build and Upload JAR

on:
  release:
    types: [published]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up JDK 21
        uses: actions/setup-java@v4.6.0
        with:
          distribution: 'temurin'
          java-version: '21'

      - name: Grant execute permission for gradlew
        run: chmod +x gradlew

      - name: Update mod_version in gradle.properties
        run: |
          sed -i "s/^mod_version=.*$/mod_version=${{ github.event.release.tag_name }}/" gradle.properties

      - name: Build with Gradle
        run: ./gradlew build

      - name: Upload to Modrinth
        uses: cloudnode-pro/modrinth-publish@2.0.0
        with:
          # Configure the action as needed. The following is an example.
          token: ${{ secrets.MODRINTH_TOKEN }}
          project: nuggetmod
          name: ${{ github.event.release.name }}
          version: ${{ github.event.release.tag_name }}
          changelog: ${{ github.event.release.body }}
          loaders: |-
            forge
          game-versions: |-
            1.21.0
            1.21.1
          files: build/libs/nuggetmod-${{ github.event.release.tag_name )}.jar