name: Release Go binaries
on:
  push:
    tags: ['v*']
  pull_request:
    paths:
      - '**.go'
      - 'go.mod'
      - 'go.sum'

permissions:
  contents: write

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with: { go-version: '1.25' }
      - name: Tidy
        run: go mod tidy && git diff --exit-code go.sum
      - name: Vet
        run: go vet ./cmd/molecule/... ./internal/client/... ./internal/cmd/...
      - name: Test
        run: go test ./cmd/molecule/...

  release:
    runs-on: ubuntu-latest
    needs: [test]
    strategy:
      matrix:
        include:
          - goos: linux
            goarch: amd64
          - goos: linux
            goarch: arm64
          - goos: darwin
            goarch: amd64
          - goos: darwin
            goarch: arm64
          - goos: windows
            goarch: amd64
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with: { go-version: '1.25' }
      - name: Build
        run: |
          GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \
            go build -o molecule-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goos == 'windows' && '.exe' || '' }} \
            ./cmd/molecule
      - uses: softprops/action-gh-release@v2
        with:
          files: molecule-*
    if: startsWith(github.ref, 'refs/tags/v')
