name: Build and Cross-Compile

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

env:
  GIT_TERMINAL_PROMPT: 1
  GOPRIVATE: git.liteyuki.icu
  GONOSUMDB: git.liteyuki.icu

jobs:
  build:
    name: Build and Cross-Compile
    runs-on: ubuntu-latest

    strategy:
      matrix:
        go-version: [1.22]
        os: [ubuntu-latest, windows-latest]
        arch: [amd64, arm64, arm, 386]

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

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

      - name: Auth For Private Repo
        run: git config --global url."https://${{ secrets.GITEA_TOKEN }}@git.liteyuki.icu".insteadOf "https://git.liteyuki.icu"

      - name: Install dependencies
        run: go mod tidy

      - name: Build
        run: |
          GOOS=${{ matrix.os == 'ubuntu-latest' && 'linux' || matrix.os == 'windows-latest' && 'windows'}}
          GOARCH=${{ matrix.arch }}
          go build -o build/${{ matrix.os }}-${{ matrix.arch }}/server-status-server main.go

      - name: Upload binaries
        uses: actions/upload-artifact@v3
        with:
          name: server-status-server-${{ matrix.os }}-${{ matrix.arch }}
          path: build/${{ matrix.os }}-${{ matrix.arch }}/server-status-server
          if-no-files-found: warn