name: Upgrade Casks

on:
  schedule:
    - cron: '0 */3 * * *'
  workflow_dispatch:

jobs:
  upgrade:
    name: Upgrade Casks
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - uses: actions/setup-java@v3
        with:
          distribution: 'zulu'
          java-version: 17

      - name: Run Updater
        uses: gradle/gradle-build-action@v2
        with:
          arguments: run --args='..'
          build-root-directory: updater

      - name: Generate Github Token
        uses: tibdex/github-app-token@v1
        id: generate_token
        with:
          app_id: ${{ secrets.APP_ID }}
          private_key: ${{ secrets.APP_PRIVATE_KEY }}    

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v4
        with:
          token: ${{ steps.generate_token.outputs.token }}
          commit-message: Upgrade JDK Casks to the latest versions
          title: Upgrade JDK Casks
          body: |
            Upgraded JDK Casks to the latest versions.

            _Auto-generated by `Upgrade Casks` Github workflow._
          branch: upgrade-casks
          delete-branch: true
