# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
  release:
    types: [published]
  workflow_dispatch:

jobs:
  build-ubuntu:
    permissions:
      contents: write
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v4
    - name: Set up Go
      uses: actions/setup-go@v4
      with:
        go-version: '1.24.4'
    - name: Setup NodeJS
      uses: actions/setup-node@v1
      with:
        node-version: '24.2.0'
    - name: Build web
      working-directory: ./apps/web
      run: |
        npm ci
        npm run build
        mv dist/* ../api/web
    - name: Build server for linux
      working-directory: ./apps/api
      run: |
        GOOS=linux go build -v -o ./yabl-linux-x86_64 .
        GOOS=darwin go build -v -o ./yabl-darwin-x86_64 .
        GOOS=windows go build -v -o ./yabl-windows-x86_64.exe .
    - name: upload linux artifact
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ github.token }}
      with:
        upload_url: ${{ github.event.release.upload_url }}
        asset_path: ./yabl-linux-x86_64
        asset_name: server-linux
        asset_content_type: application/octet-stream
    - name: upload darwin artifact
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ github.token }}
      with:
        upload_url: ${{ github.event.release.upload_url }}
        asset_path: ./yabl-darwin-x86_64
        asset_name: yabl-darwin-x86_64
        asset_content_type: application/octet-stream
    - name: upload windows artifact
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ github.token }}
      with:
        upload_url: ${{ github.event.release.upload_url }}
        asset_path: ./yabl-windows-x86_64.exe
        asset_name: yabl-windows-x86_64.exe
        asset_content_type: application/octet-stream
