# Reminds PR authors to refresh the GMD coverage baseline when production
# code changes. Path-filtered on `app/src/main/**` so it only fires when
# something that *could* affect coverage is touched. Purely informational —
# never fails the PR.
name: Baseline Reminder
permissions:
  contents: read
  pull-requests: write

on:
  pull_request:
    branches: [ "master" ]
    paths:
      - 'app/src/main/**'

concurrency:
  group: baseline-reminder-${{ github.ref }}
  cancel-in-progress: true

jobs:
  remind:
    name: Coverage Baseline Reminder
    runs-on: ubuntu-latest
    steps:
      - name: Build comment body
        id: body
        run: |
          NOW=$(date -u +'%F %H:%M UTC')
          SHORT_SHA=$(echo "${{ github.event.pull_request.head.sha }}" | cut -c1-7)
          {
            echo 'body<<EOF'
            echo '🔁 **Coverage baseline may need a refresh.**'
            echo ''
            echo 'This PR touches `app/src/main/**`. If the changes affect what smoke covers, please refresh the baseline before merging:'
            echo ''
            echo '```bash'
            echo './gradlew generateGmdCoverage'
            echo 'git add app/coverage-baselines/gmd_smoke.ec'
            echo 'git commit -m "chore: refresh smoke coverage baseline"'
            echo '```'
            echo ''
            echo "_Last checked: ${NOW} · commit \`${SHORT_SHA}\`_"
            echo 'EOF'
          } >> "$GITHUB_OUTPUT"

      - name: Upsert sticky PR comment
        uses: marocchino/sticky-pull-request-comment@v3
        continue-on-error: true
        with:
          header: baseline-reminder-bot
          message: ${{ steps.body.outputs.body }}
