name: Detect Changeset

on:
  push:
    branches:
      - master
  workflow_dispatch:

permissions:
  contents: read

jobs:
  check:
    name: Check
    runs-on: ubuntu-latest
    
    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          fetch-depth: 0
          fetch-tags: true
          ref: ${{ github.ref }}
      
      - name: Detect
        id: detect
        run: |
          BASE=$(git merge-base origin/$GITHUB_REF_NAME HEAD)
          if git diff --name-only $BASE HEAD | grep -q '^\.changeset/'; then
            echo "Changeset found. Starting next workflow."
            exit 0  # success
          else
            echo "No changeset. Stopping workflow."
            exit 1  # failure
          fi
