name: 'Util: Ensure release candidate branches'

on:
  workflow_dispatch:
  workflow_call:

jobs:
  ensure-release-candidate-branches:
    name: Ensure release-candidate branches
    runs-on: ubuntu-slim
    permissions:
      contents: write
    steps:
      - name: Generate GitHub App Token
        id: generate_token
        uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
        with:
          app-id: ${{ secrets.N8N_ASSISTANT_APP_ID }}
          private-key: ${{ secrets.N8N_ASSISTANT_PRIVATE_KEY }}

      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          fetch-depth: 1
          fetch-tags: true

      - 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: Ensure release-candidate branches
        env:
          GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
        run: node ./.github/scripts/ensure-release-candidate-branches.mjs
