name: Release Monaco 

on:
  push:
    tags:
      - 'v*' # Triggers on version tags like v1.0.0, v1.1.0-beta, etc.

jobs:
  build-and-release:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        go-version: [1.22.3] # Adjust to your Go version
        os: [linux, darwin, windows]
        arch: [amd64, arm64]
        exclude:
          - os: darwin
            arch: arm64

    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Set up Go
      uses: actions/setup-go@v5
      with:
        go-version: ${{ matrix.go-version }}

    - name: Build binary
      env:
        GOOS: ${{ matrix.os }}
        GOARCH: ${{ matrix.arch }}
      run: |
        cd backend
        go mod tidy
        GOOS=$GOOS GOARCH=$GOARCH go build -o monaco-${{ matrix.os }}-${{ matrix.arch }} .

    - name: Create Release
      uses: softprops/action-gh-release@v2
      if: startsWith(github.ref, 'refs/tags/')
      with:
        files: |
          backend/monaco-${{ matrix.os }}-${{ matrix.arch }}
        draft: false
        prerelease: false
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
