name: Restart clang-tidy workflow

on:
  push:
    branches: [develop]
  workflow_dispatch:

jobs:
  restart_clang_tidy:
    runs-on: ubuntu-latest

    permissions:
      actions: write

    steps:
      - uses: actions/checkout@v4
      - name: Check last commit matches clang-tidy auto fixes
        id: check
        shell: bash
        run: |
          passed=$(if [[ "$(git log -1 --pretty=format:%s | grep 'style: clang-tidy auto fixes')" ]]; then echo 'true' ; else echo 'false' ; fi)
          echo "passed=\"$passed\"" >> $GITHUB_OUTPUT

      - name: Run clang-tidy workflow
        if: ${{ contains(steps.check.outputs.passed, 'true') }}
        shell: bash
        env:
          GH_TOKEN: ${{ github.token }}
          GH_REPO: ${{ github.repository }}
        run: gh workflow run clang-tidy.yml
