name: Release

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

env:
  CARGO_TERM_COLOR: always
  GITHUB_REPOSITORY: raphamorim/rio
  RUST_BACKTRACE: full
  RUSTFLAGS: '-C link-arg=-s'

jobs:
  release-macos:
    runs-on: macos-latest
    permissions:
      contents: write
      discussions: write

    steps:
      - uses: actions/checkout@v4
      - uses: Swatinem/rust-cache@v2
      - run: rustup toolchain install stable --profile minimal
      - run: rustup target add x86_64-apple-darwin aarch64-apple-darwin
      - run: make release-macos
      - name: Release version
        uses: softprops/action-gh-release@v2
        with:
          append_body: true
          token: ${{ secrets.GITHUB_TOKEN }}
          files: |
            release/macos-unsigned.zip
            LICENSE

  release-deb:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      discussions: write

    steps:
      - uses: actions/checkout@v4
      - name: rust cache
        uses: Swatinem/rust-cache@v2
        with:
          cache-all-crates: true

      - run: sudo apt install rename
      - run: rustup toolchain install stable --profile minimal
      - run: cargo install cargo-deb
      - run: mkdir -p release
      - run: make release-debian-x11
      - run: make release-debian-wayland
      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          append_body: true
          token: ${{ secrets.GITHUB_TOKEN }}
          files: |
            release/debian/x11/*
            release/debian/wayland/*

  release-windows:
    runs-on: windows-latest
    defaults:
      run:
        shell: bash
    permissions:
      contents: write
      discussions: write

    steps:
      - uses: actions/checkout@v4
      - uses: Swatinem/rust-cache@v2
      - name: Install WiX
        run: dotnet tool install --global wix --version 4.0.5
      - run: wix --version
      - run: wix extension add WixToolset.UI.wixext/4.0.5 WixToolset.Util.wixext/4.0.5
      - run: rustup toolchain install stable --profile minimal
      - run: cargo build --release
      - name: Crate msi installer
        run: |
          wix build -arch "x64" -ext WixToolset.UI.wixext -ext WixToolset.Util.wixext \
          -out "./Rio-installer.msi" "misc/windows/rio.wxs"
      - run: cp ./target/release/rio.exe ./Rio-portable.exe
      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          append_body: true
          token: ${{ secrets.GITHUB_TOKEN }}
          files: |
            ./Rio-portable.exe
            ./Rio-installer.msi
