name: Build PR snapshot (1.19)

on:
  pull_request:
    paths:
      - '**.gradle'
      - '**.properties'
      - '**/src/**'
    branches:
      - "1.20.2"
    types: [ opened, synchronize, reopened ]
jobs:
  validate-gradle:
    name: "Validate Gradle wrapper"
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - uses: gradle/wrapper-validation-action@v1
  license:
    name: "Verify License integrity"
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2

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

      - name: Setup Gradle and verify license using Licenser
        uses: gradle/gradle-build-action@v2
        with:
          arguments: licenseCheck

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

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

      - 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-SNAPSHOT.PR${{ github.event.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*/
