# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push
name: "Release: Tag Push"

on:
  push:
    tags:
      - 'v*.*.*'

permissions:
  contents: write

jobs:
  build:
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            platform: linux/amd64
          - os: ubuntu-latest
            platform: linux/arm64
          - os: macos-latest
            platform: darwin/universal
          - os: windows-latest
            platform: windows/amd64
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v6

      - name: Build
        uses: host-uk/build@v3
        with:
          build-name: core
          build-platform: ${{ matrix.platform }}
          build: true
          package: true
          sign: false

  release:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - name: Download artifacts
        uses: actions/download-artifact@v7
        with:
          path: dist
          merge-multiple: true

      - name: Prepare release files
        run: |
          mkdir -p release
          cp dist/* release/ 2>/dev/null || true
          ls -la release/

      - name: Create release
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          TAG_NAME: ${{ github.ref_name }}
        run: |
          gh release create "$TAG_NAME" \
            --title "Release $TAG_NAME" \
            --generate-notes \
            release/*
