name: CI

on:
  push:
    branches:
      - main
  pull_request:
  workflow_dispatch:

permissions:
  contents: read

jobs:
  verify:
    runs-on: ubuntu-latest
    timeout-minutes: 20

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

      - name: Setup Go
        uses: actions/setup-go@v5
        with:
          go-version-file: go.mod
          cache: true

      - name: Verify formatting
        run: |
          gofmt -w $(find . -name '*.go' -not -path './vendor/*')
          git diff --exit-code

      - name: Run unit and integration tests
        run: go test ./... -count=1

      - name: Run race tests
        run: go test -race ./...

      - name: Run vet
        run: go vet ./...

      - name: Check Gate scripts syntax
        run: |
          bash -n scripts/verify_preprod_gate_b.sh
          bash -n scripts/verify_gate_c_rollback.sh
