name: CI · Changes

# Path-filter gate (#788) as a reusable job, for workflows that have no job of their own to run
# it in (preview.yml). ci.yml runs the same classification inside its preflight job instead, to
# save a runner dispatch; both go through the one definition in .github/actions/changes
# (action.yml + filters.yml), so the gates cannot drift apart.
#
# Consumers branch on the boolean outputs via `needs` + `if:` - NEVER a top-level `on: paths:`
# filter, which would leave a skipped check unreported instead of green. Only a PR into a
# branch other than main is filtered; every other event forces all outputs to 'true'.

on:
  workflow_call:
    outputs:
      web:
        description: "'true' when the pnpm/TS workspace (apps/*, packages/*) or shared config changed"
        value: ${{ jobs.detect.outputs.web }}
      ui:
        description: "'true' when packages/* (@bloom/ui Storybook and its workspace deps), root shared config, or a Storybook-governing CI file changed"
        value: ${{ jobs.detect.outputs.ui }}
      infra:
        description: "'true' when deploy assets (Helm chart, OpenTofu module, deploy scripts) or CI definitions changed"
        value: ${{ jobs.detect.outputs.infra }}
      docs:
        description: "'true' when the docs site (apps/docs), its rendered content (docs/), the TypeDoc-documented packages, or shared config changed"
        value: ${{ jobs.detect.outputs.docs }}
      landing:
        description: "'true' when the landing site (apps/landing), the @bloom/ui sources it compiles, or shared config changed"
        value: ${{ jobs.detect.outputs.landing }}

# The filter reads the PR's changed files via the GitHub API, so the token needs
# pull-requests: read - callers must grant it on their calling job.
permissions:
  contents: read
  pull-requests: read

jobs:
  detect:
    name: Detect changed paths
    runs-on: bloom-arc
    outputs:
      web: ${{ steps.changes.outputs.web }}
      ui: ${{ steps.changes.outputs.ui }}
      infra: ${{ steps.changes.outputs.infra }}
      docs: ${{ steps.changes.outputs.docs }}
      landing: ${{ steps.changes.outputs.landing }}
    steps:
      # Only the action and its filters are needed; the changed files come from the API.
      - uses: actions/checkout@v4
        with:
          sparse-checkout: .github/actions/changes

      - id: changes
        uses: ./.github/actions/changes
