name: Create Release PR

on:
  workflow_dispatch:
    inputs:
      lto-sha:
        required: true
        type: string
      nonlto-sha:
        required: true
        type: string

jobs:
  create-release-pr:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repo
        uses: actions/checkout@v4
      - name: Run create_release.py
        run: python3 scripts/create_release.py -r ${{ inputs.lto-sha }} -a ${{ inputs.nonlto-sha }} --gh-action
      - name: Create PR
        id: cpr
        uses: peter-evans/create-pull-request@v6
        with:
          token: ${{ secrets.EMSCRIPTEN_BOT_TOKEN }}
          title: Release ${{ env.RELEASE_VERSION }}
          commit-message: |
            Release ${{ env.RELEASE_VERSION }}
          team-reviewers: release-reviewers
          labels: release
          body: |
            With emscripten-releases revisions:
              https://chromium.googlesource.com/emscripten-releases/+/${{ inputs.lto-sha }} (LTO)
              https://chromium.googlesource.com/emscripten-releases/+/${{ inputs.nonlto-sha }} (asserts)
          delete-branch: true
      - name: Enable auto-merge
        run: gh pr merge --squash --auto "${{ steps.cpr.outputs.pull-request-number }}"
        env:
          GH_TOKEN: ${{ secrets.EMSCRIPTEN_BOT_TOKEN }}
