name: Patch and Build

on:
  push:
    branches: [ "**" ]
  pull_request:

jobs:
  build:
    # Only run on PRs if the source branch is on someone else's repo
    if: ${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Git Repository
        uses: actions/checkout@v4
      - name: Set up JDK
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '21'
      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@v4
      - name: Configure Git User Details
        run: git config --global user.email "actions@github.com" && git config --global user.name "Github Actions"
      - name: Apply Patches
        run: ./gradlew applyAllPatches --stacktrace
      - name: Build
        run: ./gradlew build
