name: CI

on:
  pull_request:

env:
  GO_VERSION: "1.26"

jobs:
  test:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: sh
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-go@v5
        with:
          go-version: "1.26"

      - uses: actions/cache@v4
        with:
          path: |
            ~/go/pkg/mod
            ~/.cache/go-build
          key: go-${{ hashFiles('go.sum') }}
          restore-keys: go-

      - name: Install build tools
        run: apk add --no-cache gcc musl-dev

      - name: Download modules
        run: go mod download

      - name: Test
        run: CGO_ENABLED=1 go test -race -timeout 120s ./...

  lint:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: sh
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-go@v5
        with:
          go-version: "1.26"

      - uses: golangci/golangci-lint-action@v7
        with:
          version: v2.11.2

  vulncheck:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: sh
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-go@v5
        with:
          go-version: "1.26"

      - name: Install govulncheck
        run: go install golang.org/x/vuln/cmd/govulncheck@latest

      - name: Run govulncheck
        run: govulncheck ./...
