romm-cli 0.22.0

Rust-based CLI and TUI for the ROMM API
Documentation
name: Release Please

on:
  push:
    branches:
      - main
      - master

permissions:
  contents: write
  pull-requests: write

jobs:
  release-please:
    runs-on: ubuntu-latest
    outputs:
      release_created: ${{ steps.release.outputs.release_created }}
      tag_name: ${{ steps.release.outputs.tag_name }}
    steps:
      - uses: googleapis/release-please-action@v4
        id: release
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          config-file: release-please-config.json
          manifest-file: .release-please-manifest.json

  build:
    needs: release-please
    if: ${{ needs.release-please.outputs.release_created }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            artifact_name: romm-cli-linux-x86_64
            archive: tar.gz
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            artifact_name: romm-cli-linux-aarch64
            archive: tar.gz
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            artifact_name: romm-cli-windows-x86_64
            archive: zip
          - os: macos-latest
            target: x86_64-apple-darwin
            artifact_name: romm-cli-macos-x86_64
            archive: tar.gz
          - os: macos-latest
            target: aarch64-apple-darwin
            artifact_name: romm-cli-macos-aarch64
            archive: tar.gz

    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Cache cargo registry and target
        uses: Swatinem/rust-cache@v2
        with:
          key: release-${{ matrix.target }}

      - name: Install cross-compiler (Linux aarch64)
        if: ${{ matrix.target == 'aarch64-unknown-linux-gnu' }}
        run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu

      - name: Build
        run: cargo build --release --target ${{ matrix.target }} --bins

      - name: Prepare artifact directory
        run: |
          mkdir -p artifact
          TGT="target/${{ matrix.target }}/release"
          if [ "${{ matrix.os }}" = "windows-latest" ]; then
            cp "$TGT/romm-cli.exe" artifact/
            cp "$TGT/romm-tui.exe" artifact/
          else
            cp "$TGT/romm-cli" artifact/
            cp "$TGT/romm-tui" artifact/
          fi
        shell: bash

      - name: Fix permissions (Unix)
        if: ${{ matrix.os != 'windows-latest' }}
        run: chmod +x artifact/romm-cli artifact/romm-tui

      - name: Create archive (Unix)
        if: ${{ matrix.os != 'windows-latest' }}
        run: |
          cd artifact && tar czvf ../${{ matrix.artifact_name }}.${{ matrix.archive }} * && cd ..
        shell: bash

      - name: Create archive (Windows)
        if: ${{ matrix.os == 'windows-latest' }}
        run: Compress-Archive -Path artifact\* -DestinationPath ${{ matrix.artifact_name }}.${{ matrix.archive }}
        shell: pwsh

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.artifact_name }}
          path: ${{ matrix.artifact_name }}.${{ matrix.archive }}

  upload-assets:
    needs: [release-please, build]
    if: ${{ needs.release-please.outputs.release_created }}
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts
          merge-multiple: false

      - name: Prepare release assets
        run: |
          mkdir -p release-assets
          cp artifacts/*/* release-assets/

      - name: Generate checksums
        run: |
          cd release-assets
          sha256sum * > checksums.txt
          cat checksums.txt

      - name: Upload assets to Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ needs.release-please.outputs.tag_name }}
          files: release-assets/*
          fail_on_unmatched_files: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  publish-crates-io:
    needs: release-please
    if: ${{ needs.release-please.outputs.release_created }}
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
      - name: Publish to crates.io
        run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}