name: CI Build and Test for PR

permissions:
  contents: read

on:
  pull_request:

jobs:
  check:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

      - name: check format
        run: make check_format

  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

      - name: build and test
        run: make docker_tests

  precommits:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

      - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
        with:
          python-version: "3.9"

      - uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
        with:
          go-version: "1.21.5"

      - name: run pre-commits
        run: |
          make precommit_install
          pre-commit run -a

      # If previous stage fails, print resolution steps
      - if: ${{ failure() }}
        name: Read for resolution steps
        run: |
          echo "Pre-commits failed! Run 'make precommit_install' then 'pre-commits run -a' to fix."
          exit 1