name: Release
permissions:
  contents: write
on:
  push:
    tags:
      - v*
jobs:
  i686-linux---release:
    name: Build release artifacts for i686-linux
    runs-on:
      - ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: cachix/install-nix-action@v30
      - uses: cachix/cachix-action@v15
        with:
          name: rosenpass
          authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
      - name: Build release
        run: nix build .#release-package --print-build-logs
      - name: Release
        uses: softprops/action-gh-release@v2
        with:
          draft: ${{ contains(github.ref_name, 'rc') }}
          prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') }}
          files: result/*
  x86_64-darwin---release:
    name: Build release artifacts for x86_64-darwin
    runs-on:
      - macos-13
    steps:
      - uses: actions/checkout@v5
      - uses: cachix/install-nix-action@v30
      - uses: cachix/cachix-action@v15
        with:
          name: rosenpass
          authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
      - name: Build release
        run: nix build .#release-package --print-build-logs
      - name: Release
        uses: softprops/action-gh-release@v2
        with:
          draft: ${{ contains(github.ref_name, 'rc') }}
          prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') }}
          files: result/*
  x86_64-linux---release:
    name: Build release artifacts for x86_64-linux
    runs-on:
      - ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: cachix/install-nix-action@v30
        with:
          nix_path: nixpkgs=channel:nixos-unstable
      - uses: cachix/cachix-action@v15
        with:
          name: rosenpass
          authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
      - name: Build release
        run: nix build .#release-package --print-build-logs
      - name: Release
        uses: softprops/action-gh-release@v2
        with:
          draft: ${{ contains(github.ref_name, 'rc') }}
          prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') }}
          files: result/*
  linux-packages:
    name: Build and upload DEB and RPM packages
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: cachix/install-nix-action@v30
      - uses: cachix/cachix-action@v15
        with:
          name: rosenpass
          authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
      - name: Build DEB & RPM package
        run: |
          mkdir packages
          for f in $(nix build .#package-deb .#package-rpm --print-out-paths); do cp "$f" "packages/${f#*-}"; done
      - name: Release
        uses: softprops/action-gh-release@v2
        with:
          draft: ${{ contains(github.ref_name, 'rc') }}
          prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') }}
          files: |
            packages/*
