name: E2E Tests

on:
  pull_request:
    branches: [ "main" ]

permissions: read-all

jobs:
  build-and-test:
    name: "Build & Test"
    runs-on: ${{ matrix.runner }}
    strategy:
      matrix:
        include:
          - os: linux
            arch: amd64
            runner: ubuntu-latest
          - os: darwin
            arch: amd64
            runner: macos-15
          - os: windows
            arch: amd64
            runner: windows-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Set up Go
        uses: actions/setup-go@v6
        with:
          go-version: '1.25'

      - name: Build ${{ matrix.os }}/${{ matrix.arch }}
        shell: bash
        run: |
          GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o witr-${{ matrix.os }}-${{ matrix.arch }} ./cmd/witr
          chmod +x witr-${{ matrix.os }}-${{ matrix.arch }}

      - name: Verify Version
        shell: bash
        run: ./witr-${{ matrix.os }}-${{ matrix.arch }} --version

      - name: Verify Help
        shell: bash
        run: ./witr-${{ matrix.os }}-${{ matrix.arch }} --help

  test-freebsd:
    name: "Test: FreeBSD"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - name: Run on FreeBSD
        uses: vmactions/freebsd-vm@v1
        with:
          usesh: true
          prepare: pkg install -y go
          run: |
            go build -o witr-freebsd-amd64 ./cmd/witr
            chmod +x witr-freebsd-amd64
            ./witr-freebsd-amd64 --version
            ./witr-freebsd-amd64 --help
