name: Test showbridge

on:
  pull_request:
    branches:
      - main
    paths:
      - "**/*.go"
      - "go.mod"
      - "go.sum"
  push:
    branches:
      - main
    paths:
      - "**/*.go"
      - "go.mod"
      - "go.sum"

permissions:
  contents: write

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Install alsa
        run: sudo apt-get install -y libasound2-dev

      - uses: actions/checkout@v6
      - uses: actions/setup-go@v6
        with:
          go-version-file: "go.mod"
      - name: mod tidy
        run: go mod tidy

      - name: run tests
        run: go test ./... -count=1 -coverpkg "github.com/jwetzell/showbridge-go/..." -coverprofile coverage.out

      - name: clean up coverage report
        run: cat coverage.out | grep -v "github.com/jwetzell/showbridge-go/cmd" > coverage.nocmd.out
      - name: Update coverage report
        uses: ncruces/go-coverage-report@v0.3.2
        with:
          coverage-file: coverage.nocmd.out
          report: true
          chart: true
          amend: true
        if: github.event_name == 'push'
        continue-on-error: true
