.github/workflows/ci.yml

name: ci

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

permissions:
  contents: read

jobs:
  test:
    name: test (go ${{ matrix.go }})
    runs-on: ubuntu-22.04
    strategy:
      fail-fast: false
      matrix:
        go: ["1.21", "1.22", "1.23"]
    steps:
      - name: checkout
        uses: actions/checkout@v4

      - name: setup-go
        uses: actions/setup-go@v5
        with:
          go-version: ${{ matrix.go }}
          cache: true

      - name: go vet
        run: go vet ./...

      - name: go test -race
        run: |
          go test -race \
                  -covermode=atomic \
                  -coverprofile=coverage.out \
                  ./...

      - name: publish coverage badge
        if: matrix.go == '1.23'
        env:
          BADGE_ENDPOINT: https://mercemay.top/src/lambdalog/coverage
          BADGE_TOKEN: ${{ secrets.BADGE_TOKEN }}
        run: |
          pct=$(go tool cover -func=coverage.out | awk '/^total:/ {print $3}')
          curl -fsS \
                  -H "Authorization: Bearer ${BADGE_TOKEN}" \
                  -H "Content-Type: application/json" \
                  -d "{\"coverage\":\"${pct}\"}" \
                  "${BADGE_ENDPOINT}"