name: 'Label'

on:
  pull_request:
    types: [labeled]
    paths-ignore:
      - '**.md'
      - '**.bazel'
      - 'WORKSPACE'

jobs:
  build:
    strategy:
      matrix:
        go: [ 'stable', '1.23.x' ]
        os: [ ubuntu-latest ]

    name: Run Build
    if: ${{ github.event.label.name == 'run-build' }}
    runs-on: ${{ matrix.os }}

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup Go
        uses: actions/setup-go@v5
        with:
          go-version: ${{ matrix.go }}
          cache: true
          cache-dependency-path: go.sum

      - name: Format
        run: diff -u <(echo -n) <(go fmt $(go list ./...))

      - name: Test
        run: go test ./... -race -coverprofile=coverage.txt -covermode=atomic -coverpkg=./...

      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v4
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
