name: CI Pull Request

on:
  pull_request:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  check_wrapper:
    name: Validate Gradle Wrapper
    runs-on: ubuntu-latest

    steps:
      - name: Clone repo
        uses: actions/checkout@v4

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

  build:
    name: Build pull request
    needs: check_wrapper
    runs-on: ubuntu-latest

    steps:
      - name: Checkout pull request
        uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha }}
          path: master
          fetch-depth: 0

      - name: Set up JDK 1.8
        uses: actions/setup-java@v4
        with:
          java-version: 8
          distribution: 'temurin'

      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@v4

      - name: Copy CI gradle.properties
        run: |
          cd master
          mkdir -p ~/.gradle
          cp .github/runner-files/ci-gradle.properties ~/.gradle/gradle.properties

      - name: Build Jar
        working-directory: master
        run: ./gradlew ktlintCheck :server:shadowJar --stacktrace

