name: test

on:
  push:
    branches:
      - 'main'
      - 'releases/v*'
    tags:
      - 'v*'
  pull_request:

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout
        uses: actions/checkout@v4
      -
        name: Run
        uses: docker/bake-action@v5
        with:
          targets: validate

  test:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout
        uses: actions/checkout@v4
      -
        name: Run
        uses: docker/bake-action@v5
        with:
          targets: test
      -
        name: Upload coverage
        uses: codecov/codecov-action@v4
        with:
          file: ./coverage.txt
          token: ${{ secrets.CODECOV_TOKEN }}

  example:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout
        uses: actions/checkout@v4
      -
        name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version: "1.20"
      -
        name: Download modules
        run: |
          go mod download
        working-directory: ./example
      -
        name: Run
        run: |
          go run main.go
        working-directory: ./example
      -
        name: List docs
        run: |
          tree -nh ./example/docs
      -
        name: Upload docs
        uses: actions/upload-artifact@v4
        with:
          name: example-docs
          path: ./example/docs/*
          if-no-files-found: error
