name: PR Check

on:
  pull_request:
    types: [opened, synchronize, reopened, edited]
  push:
    branches:
      - main
      - staging

permissions: read-all

jobs:

  semantic-pull-request:
    name: "Compliance: Check PR Title"
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    steps:
      - name: Check PR title
        uses: amannn/action-semantic-pull-request@v6
        id: lint_pr_title
        continue-on-error: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      
      - name: Warn on failure
        if: steps.lint_pr_title.outcome == 'failure'
        run: echo "::warning::PR title does not follow semantic commit convention"

  lint:
    name: "Code Quality: Lint"
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Set up Go
        uses: actions/setup-go@v6
        with:
          go-version: '1.25'

      - name: Verify formatting
        run: |
          if [ -n "$(find . -name "*.go" -not -path "./vendor/*" | xargs gofmt -l)" ]; then
            echo "Go code is not formatted:"
            find . -name "*.go" -not -path "./vendor/*" | xargs gofmt -d
            exit 1
          fi

  vet:
    name: "Code Quality: Vet"
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Set up Go
        uses: actions/setup-go@v6
        with:
          go-version: '1.25'

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

  test:
    name: "Tests: Unit"
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Set up Go
        uses: actions/setup-go@v6
        with:
          go-version: '1.25'

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