# Build a windows release from the node repo

name: build-win-release

on:
  workflow_dispatch:
  workflow_call:
    inputs:
      tag:
        description: 'Tag to include in artifact name'
        required: false
        type: string
  push:
    tags:
      - "*"

jobs:
  build-win:
    runs-on: windows-2022
    steps:
      - uses: actions/checkout@v4

      - uses: ./.github/actions/setup-go-for-project

      - run: go version

      - name: Set tag version
        id: set_tag
        run: |
          # Check for workflow_call input first, then workflow_dispatch input, then git tag
          if [ -n "${{ inputs.tag }}" ]; then
            echo "TAG=${{ inputs.tag }}" >> "$GITHUB_ENV"
          elif [ -n "${GITHUB_REF##refs/tags/}" ] && [ "${GITHUB_REF}" != "${GITHUB_REF##refs/tags/}" ]; then
            echo "TAG=${GITHUB_REF##refs/tags/}" >> "$GITHUB_ENV"
          else
            echo "TAG=dev" >> "$GITHUB_ENV"
          fi
        shell: bash

      - name: Build the node binary
        run: CGO_ENABLED=0 ./scripts/build.sh
        shell: bash

      - name: Create zip
        run: |
          mv .\build\luxd .\build\luxd.exe
          Compress-Archive -Path .\build\luxd.exe -DestinationPath .\build\node-win-${{ env.TAG }}-experimental.zip

      - name: Save as Github artifact
        uses: actions/upload-artifact@v7
        with:
          name: windows
          path: .\build\node-win-${{ env.TAG }}-experimental.zip
