name: Build and Release Electron App

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

jobs:
  build:
    uses: ./.github/workflows/build.yml
    with:
      upload_artifacts: true
    secrets: inherit

  release:
    needs: [build]
    runs-on: ubuntu-latest
    steps:
      - name: Check out Git repository
        uses: actions/checkout@v4

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

      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          generate_release_notes: true
          files: |
            dist/*.exe
            dist/*.zip
            dist/*.dmg
            dist/*.AppImage
            dist/*.snap
            dist/*.deb
            dist/*.rpm
            dist/*.tar.gz
            dist/*.yml
            dist/*.blockmap
        env:
          GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}

      - name: Notify Cloudflare Pages
        env:
          CLOUDFLARE_WEBHOOK_URL: ${{ secrets.CLOUDFLARE_WEBHOOK_URL }}
        run: |
          curl -X POST "$CLOUDFLARE_WEBHOOK_URL"
