name: Build and Release
run-name: ${{ gitea.actor }} build 🚀

on:
  push:
    branches:
      - master
jobs:
  release:
    runs-on: ubuntu-latest
    container:
      image: azenkain/go-node:latest

    steps:
      - uses: actions/checkout@v4

      - name: Download Go dependencies
        run: go mod download

      - name: Build for Windows
        run: GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" .

      - name: Build for macOS Intel
        run: |
          GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 \
          go build -trimpath -ldflags="-s -w" \
          -o firefly-go-proxy-macos-amd64 .

      - name: Build for macOS Apple Silicon
        run: |
          GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 \
          go build -trimpath -ldflags="-s -w" \
          -o firefly-go-proxy-macos-arm64 .

      - name: Grant execute permissions
        run: |
          chmod +x ./script/release-uploader

      - name: Upload release
        env:
          REPO_TOKEN: ${{ secrets.REPO_TOKEN }}
        run: |
          script/release-uploader \
            -token="$REPO_TOKEN" \
            -release-url="https://git.kain.io.vn/api/v1/repos/Firefly-Shelter/FireflyGo_Proxy/releases" \
            -files="firefly-go-proxy.exe,firefly-go-proxy-macos-amd64,firefly-go-proxy-macos-arm64"
