name: Release stage 1 - create release PR (Cylc 8+ only)

on:
  workflow_dispatch:
    inputs:
      version:
        description: Version number (PEP 440 compliant e.g., 8.12.4, 8.0a2 etc)
        required: true
      branch:
        description: The branch to open the PR against
        required: false
        default: 'master'

concurrency:
  # Only let this run 1 at a time
  group: ${{ github.workflow }}
  cancel-in-progress: false

defaults:
  run:
    shell: bash

env:
  FORCE_COLOR: 2
  PIP_PROGRESS_BAR: off

jobs:
  create-release-pr:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:

      - name: Sanitise workflow inputs # Should be 1st step
        uses: cylc/release-actions/stage-1/sanitize-inputs@v1

      - name: Checkout repo
        uses: actions/checkout@v5
        with:
          ref: ${{ env.BASE_REF }}
          fetch-depth: 0  # need to fetch all commits to check contributors

      - name: Check CONTRIBUTING.md
        uses: cylc/release-actions/check-shortlog@v1

      - name: Setup Python
        uses: actions/setup-python@v6
        with:
          python-version: '3.x'

      - name: Create & checkout PR branch
        uses: cylc/release-actions/stage-1/checkout-pr-branch@v1

      - name: Set the package version
        uses: cylc/release-actions/stage-1/set-python-package-version@v1
        with:
          init-file: 'cylc/flow/__init__.py'
          pypi-package-name: 'cylc-flow'

      - name: Test build
        uses: cylc/release-actions/build-python-package@v1

      - name: Generate changelog
        run: |
          python3 -m pip install -q towncrier
          towncrier build --yes

      - name: Create pull request
        uses: cylc/release-actions/stage-1/create-release-pr@v1
        with:
          test-workflows: test_fast.yml, test_functional.yml, bash.yml, test_conda-build.yml
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
