name: Checks
# Run on push to main and any pull request.
on:
  push:
    branches:
      - main
  pull_request:
permissions:
  checks: write # Allow write access to checks to allow annotation of code in the PR.
  contents: read
  pull-requests: read
env:
  CGO_ENABLED: 0
  GOLANGCI_LINT_VERSION: v2.6.1
  SHELLCHECK_SCRIPTS: ./*.sh
jobs:
  go-lint-checks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-go@v6
        with:
          go-version-file: go.mod
      - name: Run GolangCI-Lint
        uses: golangci/golangci-lint-action@v9
        with:
          version: ${{ env.GOLANGCI_LINT_VERSION }}
  go-mod-checks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-go@v6
        with:
          go-version-file: go.mod
      - name: Check if go.mod is tidy
        run: |
          go mod tidy
          git diff --exit-code go.mod go.sum ||
            (echo "::error::go.mod and go.sum need to be tidy" && exit 1)
      - name: Check if vendor directory is up to date
        run: |
          go mod vendor
          git diff --exit-code vendor ||
            (echo "::error::vendor directory needs to be updated" && exit 1)
