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 x64
        run: GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o firefly-go-proxy-windows-amd64.exe .

      - name: Build for Windows ARM64
        run: GOOS=windows GOARCH=arm64 CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o firefly-go-proxy-windows-arm64.exe .

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

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

      - name: Build for Linux x64
        run: GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o firefly-go-proxy-linux-amd64 .

      - name: Build for Linux ARM64
        run: GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o firefly-go-proxy-linux-arm64 .

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

      - name: Publish components to API
        run: ./script/publish/publish-script
        env:
          ENV_ROBOT_TOKEN: ${{ secrets.ENV_ROBOT_TOKEN }}
          ENV_GAME_IDS: ${{ secrets.ENV_GAME_IDS }}
          ENV_COMPONENT_TYPE: PROXY
          ENV_FILES: "firefly-go-proxy-windows-amd64.exe,firefly-go-proxy-windows-arm64.exe,firefly-go-proxy-macos-amd64,firefly-go-proxy-macos-arm64,firefly-go-proxy-linux-amd64,firefly-go-proxy-linux-arm64"
