name: PR check

on:
  pull_request:
    paths:
      - '**'
      - '!**.md'
      - '!.github/**'
      - '.github/workflows/build_pull_request.yml'

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
  cancel-in-progress: true

env:
  CI_CHUNK_SIZE: 65
  IS_PR_CHECK: true

jobs:
  prepare:
    name: Prepare job
    runs-on: 'ubuntu-24.04'
    outputs:
      matrix: ${{ steps.generate-matrices.outputs.matrix }}
      delete: ${{ steps.generate-matrices.outputs.delete }}
    steps:
      - name: Checkout PR
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          fetch-depth: 0

      - name: Set up Java
        uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
        with:
          java-version: 17
          distribution: temurin

      - name: Set up Gradle
        uses: gradle/actions/setup-gradle@06832c7b30a0129d7fb559bcc6e43d26f6374244 # v4.3.1
        with:
          cache-read-only: true

      - id: generate-matrices
        name: Generate build matrices
        run: |
          python ./.github/scripts/generate-build-matrices.py origin/master Debug

  build:
    name: Build extensions (${{ matrix.chunk.number }})
    needs: prepare
    runs-on: 'ubuntu-24.04'
    if: ${{ toJson(fromJson(needs.prepare.outputs.matrix).chunk) != '[]' }}
    strategy:
      matrix: ${{ fromJSON(needs.prepare.outputs.matrix) }}
    steps:
      - name: Checkout PR
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

      - name: Set up Java
        uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
        with:
          java-version: 17
          distribution: temurin

      - name: Set up Gradle
        uses: gradle/actions/setup-gradle@06832c7b30a0129d7fb559bcc6e43d26f6374244 # v4.3.1
        with:
          cache-read-only: true

      - name: Build extensions (${{ matrix.chunk.number }})
        run: |
          ./gradlew $(echo '${{ toJson(matrix.chunk.modules) }}' | jq -r 'join(" ")')
