name: Nightly Release

on:
  push:
    branches:
      - master
    workflow_dispatch:

permissions:
  contents: write

jobs:
  nightly:
    runs-on: macos-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - name: Set up Go
        uses: actions/setup-go@v6
        with:
          go-version: "1.26.1"

      - name: Set up Zig
        uses: goto-bus-stop/setup-zig@v2

      - name: Delete existing nightly release and tag
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          gh release delete nightly --yes --cleanup-tag || true

      - name: Create nightly tag
        run: |
          git tag -f nightly
          git push -f origin nightly

      - name: Get macOS SDK path
        id: macos_sdk
        run: echo "path=$(xcrun --show-sdk-path)" >> $GITHUB_OUTPUT

      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v7
        with:
          version: latest
          args: release --clean --config .goreleaser.nightly.yml
        env:
          SDK_PATH: ${{ steps.macos_sdk.outputs.path }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
