rustlens 0.2.1

Blazing-fast Rust Code Inspector for the Terminal
Documentation
name: Release

on:
  workflow_dispatch:
    inputs:
      release_tag:
        description: 'Release tag (e.g. v0.1.0). Leave empty to only build artifacts (no release).'
        required: false
        type: string
      toolchain:
        description: 'Rust toolchain'
        required: true
        default: stable
        type: choice
        options:
          - stable
  push:
    tags:
      - 'v*'

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always

jobs:
  build-release:
    name: Build Release (${{ matrix.target }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            name: rustlens-linux-x86_64
          - target: x86_64-apple-darwin
            os: macos-latest
            name: rustlens-macos-x86_64
          - target: aarch64-apple-darwin
            os: macos-latest
            name: rustlens-macos-aarch64
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            name: rustlens-windows-x86_64

    steps:
      - uses: actions/checkout@v4
      
      - uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ github.event.inputs.toolchain || 'stable' }}
          targets: ${{ matrix.target }}
      
      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}
      
      - name: Build
        run: cargo build --release --target ${{ matrix.target }}
      
      - name: Prepare artifact (Unix)
        if: matrix.os != 'windows-latest'
        run: |
          cd target/${{ matrix.target }}/release
          strip rustlens || true
          tar -czvf ../../../${{ matrix.name }}.tar.gz rustlens
      
      - name: Prepare artifact (Windows)
        if: matrix.os == 'windows-latest'
        run: |
          cd target/${{ matrix.target }}/release
          Compress-Archive -Path rustlens.exe -DestinationPath ../../../${{ matrix.name }}.zip -Force
      
      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.name }}
          path: |
            ${{ matrix.name }}.tar.gz
            ${{ matrix.name }}.zip
          if-no-files-found: ignore

  release:
    name: Create Release
    needs: build-release
    runs-on: ubuntu-latest
    # Create release on tag push (v*) or when Run workflow is used with release_tag input
    if: startsWith(github.ref, 'refs/tags/') || (github.event_name == 'workflow_dispatch' && github.event.inputs.release_tag != '')
    steps:
      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts
          merge-multiple: true

      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ github.event.inputs.release_tag || github.ref_name }}
          name: Rustlens ${{ github.event.inputs.release_tag || github.ref_name }}
          draft: false
          prerelease: ${{ contains(github.event.inputs.release_tag || github.ref_name, '-') }}
          generate_release_notes: true
          files: artifacts/*

  publish-crates-io:
    name: Publish to crates.io
    needs: release
    runs-on: ubuntu-latest
    if: ${{ !cancelled() }}
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: ${{ github.event.inputs.toolchain || 'stable' }}
      - name: Publish to crates.io
        run: |
          if [ -z "${CARGO_REGISTRY_TOKEN:-}" ]; then
            echo "CARGO_REGISTRY_TOKEN not set - skipping publish. Add it in repo secrets to publish from CI."
            exit 0
          fi
          if output=$(cargo publish --token "$CARGO_REGISTRY_TOKEN" 2>&1); then
            echo "$output"
            echo "Published successfully."
          else
            echo "$output"
            if echo "$output" | grep -q "already exists"; then
              echo "This version is already on crates.io - skipping (bump version in Cargo.toml for new releases)."
              exit 0
            fi
            exit 1
          fi
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}