name: Check commit

on: [push]

jobs:
  check-commit:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Detect commit type
        id: check-commit-type
        run: |
          echo "BRANCH=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV
          readonly COMM_MSG=$(git log -1 --pretty=%B)
          if [ "${GITHUB_EVENT_NAME}" == "push" ]; then
              if [[ "${COMM_MSG}" == *"initial"* ]]; then
                  echo "run_builder=true" >> $GITHUB_ENV
              else
                  echo "run_builder=false" >> $GITHUB_ENV
              fi
          elif [ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]; then
              echo "run_builder=true" >> $GITHUB_ENV
          fi

      - name: Run release workflow
        id: run-rel-workflow
        if: env.run_builder == 'true'
        uses: benc-uk/workflow-dispatch@v1
        with:
          workflow: 'build.yml'
          token: ${{ secrets.PMT_WORKFLOW_GTOKEN }}
          ref: ${{ env.BRANCH }}
