name: Release

on:
  push:
    tags: ['v*']

permissions:
  contents: write

jobs:
  release:
    runs-on: ubuntu-latest
    environment: release

    steps:
      - name: Checkout
        uses: actions/checkout@v6

      # Download 32-bit artifacts
      - name: Download Windows Build Artifact
        uses: dawidd6/action-download-artifact@v12
        with:
          name: Windows Build
          workflow: rust.yml
          branch: main
          path: ./artifacts/windows

      - name: Download Linux Build Artifact
        uses: dawidd6/action-download-artifact@v12
        with:
          name: Linux Build
          workflow: rust.yml
          branch: main
          path: ./artifacts/linux

      # Download 64-bit artifacts
      - name: Download Windows x64 Build Artifact
        uses: dawidd6/action-download-artifact@v12
        with:
          name: Windows Build x64
          workflow: rust.yml
          branch: main
          path: ./artifacts/windows-x64

      - name: Download Linux x64 Build Artifact
        uses: dawidd6/action-download-artifact@v12
        with:
          name: Linux Build x64
          workflow: rust.yml
          branch: main
          path: ./artifacts/linux-x64

      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          name: ${{ github.ref_name }}
          draft: true
          generate_release_notes: true
          files: |
            ./artifacts/windows/iconforge.dll
            ./artifacts/windows/iconforge.pdb
            ./artifacts/windows-x64/iconforge64.dll
            ./artifacts/windows-x64/iconforge64.pdb
            ./artifacts/linux/libiconforge.so
            ./artifacts/linux-x64/libiconforge_64.so
            ./artifacts/windows/iconforge.dm
            ./artifacts/windows-x64/iconforge_cli.exe
            ./artifacts/linux-x64/iconforge_cli
  publish:
    runs-on: ubuntu-latest
    environment: release
    permissions:
      id-token: write
    steps:
    - uses: actions/checkout@v6
    - uses: rust-lang/crates-io-auth-action@v1
      id: auth
    - run: cargo publish
      env:
        CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
