name: Build and Release (1.19)

on:
  push:
    paths:
      - '**.gradle'
      - '**.properties'
      - '**/src/**'
    branches:
      - "1.20.4"
  workflow_dispatch:
    inputs:
      norelease:
        description: 'Do not publish'
        required: true
        default: 'false'

jobs:
  build:
    name: "Build and Release"
    runs-on: ubuntu-20.04
    if: |
      !contains(github.event.head_commit.message, '[ci skip]')
    steps:
      - uses: actions/checkout@v2

      - name: Set up JDK 17
        uses: actions/setup-java@v2
        with:
          java-version: 17
          distribution: 'temurin'

      - name: Validate Gradle Wrapper
        uses: gradle/wrapper-validation-action@v1

      - name: Verify license using Licenser
        uses: gradle/gradle-build-action@v2
        with:
          arguments: licenseCheck

      - name: Setup and Build with Gradle
        uses: gradle/gradle-build-action@v2
        with:
          arguments: build --stacktrace --no-daemon

      - name: Setting mod version
        run: |
          cat $GITHUB_WORKSPACE/gradle.properties | grep ^archives_base_name= >> $GITHUB_ENV
          cat $GITHUB_WORKSPACE/gradle.properties | grep ^minecraft_version= >> $GITHUB_ENV
          cat $GITHUB_WORKSPACE/gradle.properties | grep ^base_version= >> $GITHUB_ENV
      - name: Create package name
        run: echo "package_name=[$minecraft_version] $archives_base_name-$base_version.${{ github.run_number }}" >> $GITHUB_ENV
      - uses: actions/upload-artifact@v2
        with:
          name: ${{ env.package_name }}
          path: |
            **/build/libs/
            !build/libs/
            !**/*-dev.jar
            !**/*-shadow.jar
            !**/*-transformProduction*.jar
            !**/testmod*/

      - name: Release to Maven and CurseForge
        uses: gradle/gradle-build-action@v2
        if: |
          !contains(github.event.head_commit.message, '[norelease]') && github.event.inputs.norelease != 'true'
        env:
          # currently unused, may want to use these for changelogs though!
          # GIT_COMMIT: ${{ github.event.after }}
          # GIT_PREVIOUS_COMMIT: ${{ github.event.before }}
          MAVEN_PASS: ${{ secrets.MAVEN_PASS }}
          CURSE_API_KEY: ${{ secrets.CURSE_API_KEY }}
          MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
        with:
          arguments: publish publishUnified --stacktrace --no-daemon
