# 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: created
  workflow_dispatch:

jobs:
  build-ubuntu:
    permissions:
      contents: write
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Checkout web repo
      uses: actions/checkout@v4
      with:
        repository: yetanotherbooklibrary/web
        path: ./web
        ssh-key: ${{ secrets.WEB_SSH_KEY }}
    - name: Set up Go
      uses: actions/setup-go@v4
      with:
        go-version: '1.21.6'
    - name: Setup NodeJS 21.6.2
      uses: actions/setup-node@v1
      with:
        node-version: '21.6.2'
    - name: Build web
      working-directory: ./web
      run: |
        npm ci
        npm run build
    - name: Build server for linux
      run: GOOS=linux go build -v -o ./server-linux .
    - name: Build server for darwin
      run: GOOS=darwin go build -v -o ./server-darwin .
    - name: Build server for windows
      run: GOOS=windows go build -v -o ./server-windows.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: ./server-linux
        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: ./server-darwin
        asset_name: server-darwin
        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: ./server-windows.exe
        asset_name: server-windows.exe
        asset_content_type: application/octet-stream
