name: Publish

on:
  workflow_dispatch:

  push:
    branches:
      - next

jobs:
  publish:
    runs-on: ubuntu-latest

    permissions:
      id-token: write
      contents: write

    steps:
      - name: Checkout code
        uses: actions/checkout@v6
        with:
          ref: ${{ github.ref_name }}
          fetch-depth: 0

      - name: Prepare
        uses: ./.github/actions/prepare

      - name: Build
        run: yarn run build

      - name: Detect publish flag
        id: flag
        uses: ./.github/actions/detect-publish-flag

      - name: Determine the versions
        run: yarn run publish:version "$PUBLISH_FLAG"
        env:
          PUBLISH_FLAG: ${{ steps.flag.outputs.flag }}

      - name: Check the versions
        run: yarn run publish:check
        env:
          GH_TOKEN: ${{ github.token }}

      - name: Publish packages
        run: yarn run publish
        env:
          GH_TOKEN: ${{ github.token }}
