name: CI
on:
  push:
    branches: ["main", "devel"]
    paths:
      - '**.go'
      - '**.yml'
      - '**.yaml'
  pull_request:
    branches: ["main", "devel"]

permissions:
  contents: read

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  test:
    strategy:
      fail-fast: true
      matrix:
        go-version: ['stable', 'oldstable']
        os: [ubuntu-latest, macos-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-go@v6
        with:
          go-version: ${{ matrix.go-version }}
          cache: true
      - run: go test -v ./...
      - if: runner.os == 'Linux'
        run: go test -v -race -run='(Persist|Example)' ./...

  govulncheck:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-go@v6
        with:
          go-version: stable
          cache: true
      - uses: golang/govulncheck-action@v1
        id: govulncheck

  coverage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-go@v6
        with:
          go-version: stable
          cache: true

      - name: Test Coverage
        run: go test -v -coverprofile=profile.cov ./...

      - uses: shogo82148/actions-goveralls@v1
        with:
          path-to-profile: profile.cov

  linting:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-go@v6
        with:
          go-version: stable
          cache: true

      - name: golangci-lint
        uses: golangci/golangci-lint-action@v9
        with:
          version: v2.12.0
