name: Make release and binaries

on:
  push:
    tags:
      - "v*"

permissions:
  contents: write

jobs:
  goreleaser:
    runs-on: ubuntu-latest
    timeout-minutes: 45
    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - name: Set up bun
        uses: oven-sh/setup-bun@v2

      - name: Install dependencies
        run: bun install --frozen-lockfile --cwd ./internal/site

      - name: Build site
        run: bun run --cwd ./internal/site build

      - name: Set up Go
        uses: actions/setup-go@v6
        with:
          go-version-file: go.mod
          cache-dependency-path: go.sum

      - name: Set up .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: "9.0.x"

      - name: Build .NET LHM executable for Windows sensors
        run: |
          dotnet build -c Release ./agent/lhm/beszel_lhm.csproj
        shell: bash

      - name: GoReleaser beszel
        uses: goreleaser/goreleaser-action@v6
        with:
          workdir: ./
          distribution: goreleaser
          version: latest
          args: release --clean
        env:
          GITHUB_TOKEN: ${{ secrets.TOKEN || secrets.GITHUB_TOKEN }}
          WINGET_TOKEN: ${{ secrets.WINGET_TOKEN }}
          IS_FORK: ${{ github.repository_owner != 'henrygd' }}
