name: Test

on:
  push:
    paths-ignore:
      - docs/**

jobs:
  test:
    strategy:
      matrix:
        go-version: [ 1.24.x ]

    runs-on: ubuntu-latest

    steps:
      - name: Set up Go 1.x
        uses: actions/setup-go@v5
        with:
          go-version: ${{ matrix.go-version }}
        id: go

      - name: Check out code into the Go module directory
        uses: actions/checkout@v4

      - name: Unit tests
        run: make test.unit

      - name: Process coverage report
        run: bash ./.github/workflows/scripts/coverage-report.sh
        env:
          INPUT_COVERAGE: coverage.txt

      - name: Upload badge to Gist
        uses: popsiclestick/gist-sync-action@88f8633178625914f2a01abf1a765f7272a580fa # v1.2.0
        if: >
          success()
          && hashFiles('coverage.svg') != ''
          && !github.event.repository.fork
          && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
        with:
          gist_url: https://gist.github.com/maypok86/2aae2cd39836dc7c258df7ffec602d1c
          auth: ${{ secrets.GIST_TOKEN }}
          gist_description: Otter's coverage badge
          github_file: coverage.svg
          gist_title: coverage.svg

      - name: Upload report to Gist
        uses: popsiclestick/gist-sync-action@88f8633178625914f2a01abf1a765f7272a580fa # v1.2.0
        if: >
          success()
          && hashFiles('coverage.html') != ''
          && !github.event.repository.fork
          && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
        with:
          gist_url: https://gist.github.com/maypok86/97c79c864eb1e0fea3a7c430f39acc82
          auth: ${{ secrets.GIST_TOKEN }}
          gist_description: Otter's coverage report
          github_file: coverage.html
          gist_title: coverage.html
