name: 'Publish release'

on:
  workflow_dispatch:
    inputs:
      version:
        type: choice
        description: 'The version you want to publish to NPM'
        options:
          - patch
          - minor
          - prepatch
          - preminor
      distTag:
        type: choice
        description: 'NPM dist-tag'
        default: 'latest'
        options:
          - latest
          - beta
          - rc
          - alpha

jobs:
  publish:
    name: 'Publish'
    runs-on: ubuntu-latest
    if: github.repository == 'strapi/strapi'
    steps:
      - uses: actions/create-github-app-token@v1
        id: app-token
        with:
          app-id: ${{ secrets.RELEASE_APP_ID }}
          private-key: ${{ secrets.RELEASE_APP_SECRET }}
      - uses: actions/checkout@v6
        with:
          token: ${{ steps.app-token.outputs.token }}
          fetch-depth: 0 # Fetch full history
      - name: Setup npmrc
        run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
      - uses: actions/setup-node@v6
        with:
          node-version: 24
      - run: yarn
      - run: ./scripts/publish.sh
        env:
          VERSION: ${{ github.event.inputs.version }}
          DIST_TAG: ${{ github.event.inputs.distTag }}
          PREID: ${{ github.event.inputs.distTag }}
          GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
          GITHUB_ACTOR: ${{ github.actor }}
