sdoppia 0.7.0

A CLI tool to scan directories, hash files, and find duplicate files
name: Pipeline

on:
  push:
    branches:
      - "*"
    tags:
      - "v*"
  pull_request:
    branches:
      - main
      - develop
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always
  APP_NAME: sdoppia

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v7

      - name: Restore cache
        id: restore-cache
        continue-on-error: true
        uses: actions/cache/restore@v6
        with:
          path: |
            ~/.cargo
            target
          key: ${{ runner.os }}-cargo-${{ github.repository }}-${{ github.ref_name }}
          restore-keys: |
            ${{ runner.os }}-cargo-${{ github.repository }}-

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

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

      - name: Run clippy
        run: cargo clippy --all-targets -- -D warnings

      - name: Store cache
        id: store-cache
        if: success() || failure()
        uses: actions/cache/save@v6
        with:
          path: |
            ~/.cargo
            target
          key: ${{ runner.os }}-cargo-${{ github.repository }}-${{ github.ref_name }}

  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v7

      - name: Restore cache
        id: restore-cache
        continue-on-error: true
        uses: actions/cache/restore@v6
        with:
          path: |
            ~/.cargo
            target
          key: ${{ runner.os }}-cargo-${{ github.repository }}-${{ github.ref_name }}
          restore-keys: |
            ${{ runner.os }}-cargo-${{ github.repository }}-

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable

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

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

      - name: Check documentation
        run: cargo doc --no-deps --document-private-items

      - name: Store cache
        id: store-cache
        if: success() || failure()
        uses: actions/cache/save@v6
        with:
          path: |
            ~/.cargo
            target
          key: ${{ runner.os }}-cargo-${{ github.repository }}-${{ github.ref_name }}

  publish-crates-io:
    runs-on: ubuntu-latest
    if: github.ref_type == 'tag'
    steps:
      - name: Checkout code
        uses: actions/checkout@v7

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Publish to crates.io
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish

  release:
    runs-on: ubuntu-latest
    needs: test
    if: github.ref_type == 'tag'
    permissions:
      contents: write
    steps:
      - name: Checkout code
        uses: actions/checkout@v7

      - name: Restore cache
        id: restore-cache
        continue-on-error: true
        uses: actions/cache/restore@v6
        with:
          path: |
            ~/.cargo
            target
          key: ${{ runner.os }}-cargo-${{ github.repository }}-${{ github.ref_name }}
          restore-keys: |
            ${{ runner.os }}-cargo-${{ github.repository }}-

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Extract version from tag
        id: get_version
        run: |
          VERSION=${GITHUB_REF#refs/tags/v}
          echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
          echo "Releasing version: $VERSION"

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

      - name: Store cache
        id: store-cache
        if: success() || failure()
        uses: actions/cache/save@v6
        with:
          path: |
            ~/.cargo
            target
          key: ${{ runner.os }}-cargo-${{ github.repository }}-${{ github.ref_name }}

      - name: Create GitHub release
        uses: softprops/action-gh-release@v3
        with:
          tag_name: v${{ steps.get_version.outputs.VERSION }}
          name: sdoppia ${{ steps.get_version.outputs.VERSION }}
          body: |
            ## Changes in ${{ steps.get_version.outputs.VERSION }}

            ### Binary

            Download the prebuilt `sdoppia` binary attached to this release.

            ### Install from crates.io

            ```sh
            cargo install sdoppia
            ```

            ### Usage

            See [README.md](https://github.com/facorazza/sdoppia) for usage instructions.
          files: target/release/sdoppia
          prerelease: ${{ contains(steps.get_version.outputs.VERSION, 'alpha') || contains(steps.get_version.outputs.VERSION, 'beta') || contains(steps.get_version.outputs.VERSION, 'rc') }}