name: "build and codecov"

on:
  push:
    branches: [ main ]
  pull_request:
    branches: ["*"]

jobs:
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest
    strategy:
      matrix:
        golang:
          - 1.19
    steps:
      - name: "set up go"
        uses: actions/setup-go@v3
        with:
          go-version: 1.19

      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: "checkout ${{ github.ref }}"
        uses: actions/checkout@v3
        with:
          fetch-depth: 2

      - name: "run go build"
        run: GOPROXY="https://proxy.golang.org,direct" make build

      - name: "run go test and out codecov"
        run: make prebuild; go test ./cmd/... ./pkg/... -race -coverprofile=coverage.out -covermode=atomic

      - name: "upload coverage"
        uses: codecov/codecov-action@v3
