name: Release
on:
  release:
    types: [published]

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version: '1.21'

      - name: Install dependencies
        run: go mod download

      - name: Build
        run: go build -v ./...

      - name: Test
        run: go test -v ./...

      - name: Build release binary
        run: |
          mkdir -p release
          GOOS=linux GOARCH=amd64 go build -o release/learning-linux-amd64 .
          GOOS=windows GOARCH=amd64 go build -o release/learning-windows-amd64.exe .
          GOOS=darwin GOARCH=amd64 go build -o release/learning-darwin-amd64 .
          GOOS=darwin GOARCH=arm64 go build -o release/learning-darwin-arm64 .

      - name: Upload release assets
        uses: actions/upload-artifact@v4
        with:
          name: release-binaries
          path: release/
