name: build-test
on:
  push:
    branches:
      - "main"
      - "dev-v3"
      - "release-**"
  pull_request:
    branches:
      - "main"
      - "dev-v3"

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source code
        uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # pin@v5.0.0
      - name: Add variables to environment file
        run: cat ".github/env" >> "$GITHUB_ENV"
      - name: Setup Go
        uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # pin@5.5.0
        with:
          go-version: '${{ env.GOLANG_VERSION }}'
          check-latest: true
      - name: Test source headers are present
        run: make test-source-headers
      - name: Check if go modules need to be tidied
        run: go mod tidy -diff
      - name: Run unit tests
        run: make test-coverage
      - name: Test build
        run: make build
