# Fast unit/race/coverage checks for the Go CLI. Database integration is in
# cli-integration.yml.
name: CLI

on:
  push:
    paths:
      - "cli/**"
      - ".github/workflows/cli.yml"
  pull_request:
    paths:
      - "cli/**"
      - ".github/workflows/cli.yml"

permissions:
  contents: read

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

jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 20
    defaults:
      run:
        working-directory: cli
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
        with:
          go-version-file: cli/go.mod
          cache-dependency-path: cli/go.sum
      - name: Test with coverage
        run: go test -count=1 -coverprofile=coverage.out ./...
      - name: Race
        run: go test -race -count=1 ./...
      - name: Coverage report
        run: go tool cover -func=coverage.out
      - name: Upload coverage
        uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
        with:
          name: cli-coverage
          path: cli/coverage.out
          if-no-files-found: error
      - name: Upload to Codecov
        uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
        with:
          files: cli/coverage.out
          flags: unit
          fail_ci_if_error: false
      - name: Vet
        run: go vet ./...
      - name: Build
        run: go build -trimpath -o pg_integrity_checksums ./cmd/pg_integrity_checksums
