name: build & test

permissions: {}

on:
  push:
    branches:
      - master
    paths-ignore:
      - 'docs/**'
      - README.md
  pull_request:
    branches:
      - master
    paths-ignore:
      - 'docs/**'
      - README.md
  workflow_dispatch:

jobs:
  # check-if-duplicate-action:
  #   continue-on-error: true
  #   runs-on: ubuntu-latest
  #   outputs:
  #     should_skip: ${{ steps.skip_check.outputs.should_skip }}
  #   steps:
  #     - id: skip_check
  #       uses: fkirc/skip-duplicate-actions@v5
  #       with:
  #         concurrent_skipping: 'never'
  #         skip_after_successful_duplicate: 'true'
  #         paths_ignore: '["master/docs/**"]'
  #         paths: '["master/**.go", "master/.github"]'

  build:
    # needs: check-if-duplicate-action
    # if: needs.check-if-duplicate-action.outputs.should_skip != 'true'
    runs-on: ubuntu-latest
    steps:
      - name: Check out code
        uses: actions/checkout@v4

      - name: Install Go
        uses: actions/setup-go@v5
        with:
          go-version: "1.24.x"

      - name: Go Format
        run: gofmt -s -w . && git diff --exit-code

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

      - name: Go Tidy
        run: go mod tidy && git diff --exit-code

      - name: Go Mod
        run: go mod download

      - name: Go Mod Verify
        run: go mod verify

      - name: Go Build
        run: ./build.sh

      - name: Go Test
        run: go test -count=1 ./... # should probably also add -race flag in the future

      - name: Go Benchmark
        run: go test -run=- -bench=. -benchtime=1x ./...
