name: Auto-release internal packages

# Internal packages (no changelog, patch-bump versioning) release on every
# push to main that touches them. Publishing goes through publish.yml with no
# explicit version: the next patch version is computed from the newest tag
# inside the per-package publish concurrency group, and the tag is only
# pushed after a successful upload. Like every publish, the upload itself
# waits for approval by the pypi environment's required reviewers.

on:
  push:
    branches: [main]
    paths:
      - "packages/reflex-components-internal/**"
      - "packages/reflex-site-shared/**"
      - ".github/workflows/auto_release_internal.yml"
  workflow_dispatch:
    inputs:
      package:
        description: "Package to release"
        required: true
        type: choice
        options:
          - reflex-components-internal
          - reflex-site-shared

permissions:
  contents: read

jobs:
  detect:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    outputs:
      packages: ${{ steps.detect.outputs.packages }}
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          fetch-depth: 2
          persist-credentials: false
      - id: detect
        env:
          EVENT_NAME: ${{ github.event_name }}
          DISPATCH_PACKAGE: ${{ inputs.package }}
        run: bash .github/scripts/auto_release_internal/detect.sh

  publish:
    needs: detect
    if: needs.detect.outputs.packages != '[]'
    strategy:
      matrix:
        package: ${{ fromJson(needs.detect.outputs.packages) }}
      fail-fast: false
    # Holds the per-package publish lock for the whole called run, so
    # back-to-back pushes compute and publish strictly one version at a time.
    concurrency:
      group: publish-${{ matrix.package }}
      cancel-in-progress: false
    permissions:
      contents: write
      id-token: write
      actions: read
    uses: ./.github/workflows/publish.yml
    with:
      package: ${{ matrix.package }}
