name: 'Release: Update pointer tag'
run-name: 'Update pointer tag: ${{ inputs.track }} -> ${{ inputs.version-tag }}'

on:
  workflow_call:
    inputs:
      track:
        required: true
        type: string
      version-tag:
        required: true
        type: string
  workflow_dispatch:
    inputs:
      track:
        description: 'Release Track'
        required: true
        type: choice
        options: [stable, beta, v1]
      version-tag:
        description: 'Version tag (e.g. n8n@2.7.0). Track tag will point to this version tag.'
        required: true
        type: string

permissions:
  contents: write

jobs:
  update-pointer-tags:
    name: Update pointer tags
    runs-on: ubuntu-slim
    environment: minor-release-tag-merge

    steps:
      - name: Generate GitHub App Token
        id: generate_token
        uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
        with:
          app-id: ${{ secrets.RELEASE_TAG_MERGE_APP_ID }}
          private-key: ${{ secrets.RELEASE_TAG_MERGE_PRIVATE_KEY }}
          skip-token-revoke: false

      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          token: ${{ steps.generate_token.outputs.token }}
          # We can manage with a shallow clone, since `ensureTagExists` in github-helpers.mjs
          # does a targeted fetch for the tags it needs.
          fetch-depth: 1

      - name: Setup NodeJS
        uses: ./.github/actions/setup-nodejs
        with:
          build-command: ''
          install-command: pnpm install --frozen-lockfile --dir ./.github/scripts --ignore-workspace
          cache-dependency-path: .github/scripts/pnpm-lock.yaml

      - name: Configure git author
        run: |
          git config user.name "n8n-release-tag-merge[bot]"
          git config user.email "256767729+n8n-release-tag-merge[bot]@users.noreply.github.com"

      - name: Move track tag
        env:
          TRACK: ${{ inputs.track }}
          VERSION_TAG: ${{ inputs.version-tag }}
        run: node ./.github/scripts/move-track-tag.mjs
