rustyclip 0.1.2

🦀 RustyClip: A simple clipboard history manager for macOS/Linux
name: Release

on:
  push:
    branches:
      - main

jobs:
  release:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        platform: [ubuntu-latest, macos-latest, windows-latest]

    steps:
    - name: Checkout source
      uses: actions/checkout@v4
      with:
        fetch-depth: 0  # Needed to create and push tags

    - name: Install Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        override: true
        components: rustfmt, clippy

    - name: Cache cargo
      uses: actions/cache@v4
      with:
        path: |
          ~/.cargo/registry
          ~/.cargo/git
          target
        key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
        restore-keys: |
          ${{ runner.os }}-cargo-

    - name: Get version from Cargo.toml
      id: version
      run: |
        VERSION=$(grep '^version =' Cargo.toml | head -n1 | sed 's/version = "\(.*\)"/\1/')
        echo "version=$VERSION" >> $GITHUB_OUTPUT

    - name: Create tag if not exists
      if: github.ref == 'refs/heads/main'
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        git config user.name "github-actions[bot]"
        git config user.email "github-actions[bot]@users.noreply.github.com"
        if ! git ls-remote --exit-code --tags origin "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
          git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
          git push origin "v${{ steps.version.outputs.version }}"
        fi

    - name: Build release binary
      run: cargo build --release

    - name: Package binaries
      if: runner.os == 'Windows'
      run: powershell Compress-Archive -Path target\release\rustyclip.exe -DestinationPath target\release\rustyclip-windows.zip
    - name: Package binaries (Linux/macOS)
      if: runner.os != 'Windows'
      run: tar -czf target/release/rustyclip-${{ runner.os }}.tar.gz -C target/release rustyclip

    - name: Run Clippy (linting)
      run: cargo clippy -- -D warnings

    - name: Check formatting
      run: cargo fmt -- --check

    - name: Run tests
      run: cargo test --verbose

    - name: Publish to crates.io
      if: matrix.platform == 'ubuntu-latest'
      env:
        CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
      run: cargo publish --verbose

    - name: Create GitHub Release
      if: matrix.platform == 'ubuntu-latest'
      uses: softprops/action-gh-release@v2
      with:
        generate_release_notes: true
        files: |
          target/release/rustyclip-linux.tar.gz
          target/release/rustyclip-macos.tar.gz
          target/release/rustyclip-windows.zip
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}