name: Build pull request

on:
  workflow_dispatch:
    inputs:
      pr:
        description: "PR to build"
        required: true
  pull_request:
    branches:
      - dev

jobs:
  release:
    name: Build
    runs-on: ubuntu-latest
    permissions:
      contents: read

    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          ref: ${{ inputs.pr && format('refs/pull/{0}/merge', inputs.pr) || github.ref }}

      - name: Setup Java
        uses: actions/setup-java@v5
        with:
          distribution: 'temurin'
          java-version: '17'

      - name: Cache Gradle
        uses: burrunan/gradle-cache-action@v3

      - name: Build
        env:
          ORG_GRADLE_PROJECT_githubPackagesUsername: ${{ github.actor }}
          ORG_GRADLE_PROJECT_githubPackagesPassword: ${{ secrets.GITHUB_TOKEN }}
        run: ./gradlew :patches:buildAndroid --no-daemon

      - name: Upload artifacts
        uses: actions/upload-artifact@v7
        with:
          name: revanced-patches
          path: patches/build/libs
          archive: false
