name: Release

on:
    workflow_call:
      inputs:
        NIGHTLY:
          default: false
          type: boolean

env:
  tag_name: ${{ inputs.NIGHTLY == true && 'nightly' || 'continuous' }}

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - name: Delete existing tag and release
        uses: dev-drprasad/delete-tag-and-release@v1.1
        with:
          delete_release: true
          github_token: ${{ secrets.GITHUB_TOKEN }}
          tag_name: ${{ env.tag_name }}

      - run: mkdir target

      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          path: target

      - name: Remove unsigned Windows build
        run: rm -rfv target/*unsigned*

      - run: find target -type f -exec mv -v {} target \;

      - name: Unarchive Windows's build artifacts
        run: for f in target/*.zip; do unzip -d target/ "$f"; done

      - name: Remove archived Windows's build artifacts
        run: rm -v target/build-artifacts-*.zip

      - name: Release
        uses: softprops/action-gh-release@v2
        with:
          files: target/*
          prerelease: true
          tag_name: ${{ env.tag_name }}

      # For reference: Uploading nightly builds to the nightly server is processed on the nightly server side.
