name: Add New Release to Pongo

on:
  push:
    tags:
    - '[1-9]+.[0-9]+.[0-9]+'

jobs:
  set_vars:
    name: Set Vars
    runs-on: ubuntu-latest-kong
    env:
      REF_NAME: ${{ github.ref_name }}
      RELEASE_TAG_NAME: ${{ github.event.release.tag_name }}
    outputs:
      code_base: ${{ steps.define_vars.outputs.CODE_BASE }}
      tag_version: ${{ steps.define_vars.outputs.TAG_VERSION }}
    steps:
    - name: Define Vars
      id: define_vars
      shell: bash
      run: |
        if [[ "${GITHUB_REPOSITORY,,}" = "kong/kong" ]] ; then
          CODE_BASE=CE
        elif [[ "${GITHUB_REPOSITORY,,}" = "kong/kong-ee" ]] ; then
          CODE_BASE=EE
        fi
        echo "CODE_BASE=$CODE_BASE" >> "$GITHUB_OUTPUT"

        if [[ "${{ github.event_name }}" == "push" ]] ; then
          TAG_VERSION="$REF_NAME"
        elif [[ "${{ github.event_name }}" == "release" ]] ; then
          TAG_VERSION="$RELEASE_TAG_NAME"
        fi
        echo "TAG_VERSION=$TAG_VERSION" >> "$GITHUB_OUTPUT"
  add_release_to_pongo:
    name: Add Release to Pongo
    runs-on: ubuntu-latest-kong
    needs:
    - set_vars
    env:
      GITHUB_TOKEN: ${{ secrets.PAT }}
    steps:
    - name: Checkout Pongo
      id: checkout_pongo
      uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      with:
        token: ${{ env.GITHUB_TOKEN }}
        repository: kong/kong-pongo
        ref: master
    - name: Set git Env
      id: set_git_env
      shell: bash
      run: |
        git config --global user.email "ci-bot@konghq.com"
        git config --global user.name "CI Bot"
    - name: Create PR
      id: create_pr
      shell: bash
      run: |
        ./assets/add_version.sh "${{ needs.set_vars.outputs.code_base }}" "${{ needs.set_vars.outputs.tag_version }}"
