name: Release

on:
    workflow_call:

env:
  tag_name: "v3.13.1"

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: Clear artifacts
        uses: geekyeggo/delete-artifact@v5
        with:
          name: build-artifacts-*

      - 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/*
          draft: true
          prerelease: true
          tag_name: ${{ env.tag_name }}
