name: History Rewrite Tests

on:
  workflow_run:
    workflows: ["Docker Build, Publish & Test"]
    types: [completed]

concurrency:
  group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.workflow_run.head_branch || github.head_ref || github.ref_name }}
  cancel-in-progress: true

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'success' }}
    steps:
      - name: Checkout with full history
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
        with:
          fetch-depth: 0
          ref: ${{ github.event.workflow_run.head_sha || github.sha }}

      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y bats shellcheck

      - name: Run Bats tests
        run: |
          bats ./scripts/history-rewrite/tests || exit 1

      - name: ShellCheck scripts
        run: |
          shellcheck scripts/history-rewrite/*.sh || true
