name: Create Release Pull Request

on:
  workflow_dispatch:
    inputs:
      base-branch:
        description: 'The base branch, tag, or SHA for git operations and the pull request.'
        required: true
      semver-version:
        description: 'A semantic version. eg: x.x.x'
        required: true
      version-number:
        description: 'A natural version number. eg: 862'
        required: true

jobs:
  create-release-pr:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    steps:
      - uses: actions/checkout@v2
        with:
          # This is to guarantee that the most recent tag is fetched.
          # This can be configured to a more reasonable value by consumers.
          fetch-depth: 0
          # We check out the specified branch, which will be used as the base
          # branch for all git operations and the release PR.
          ref: ${{ github.event.inputs.base-branch }}
      - name: Get Node.js version
        id: nvm
        run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
      - uses: actions/setup-node@v2
        with:
          node-version: ${{ steps.nvm.outputs.NODE_VERSION }}
      - name: Set Versions
        id: set-versions
        shell: bash
        run: SEMVER_VERSION=${{ github.event.inputs.semver-version }} VERSION_NUMBER=${{ github.event.inputs.version-number }} yarn create-release
      - name: Create Release PR
        id: create-release-pr
        shell: bash
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          ./scripts/create-release-pr.sh ${{ github.event.inputs.semver-version }}
