folder-declutter 0.4.14

Folder Declutter is a command-line and library utility written in Rust that helps you free up disk space by automatically deleting files that haven't been modified in a specified number of days.
Documentation
name: Build and Release
permissions:
  contents: write

on:
  push:
    paths:
      - 'Cargo.toml'
      - 'src/**'
    branches:
      - main

jobs:
  check-version:
    runs-on: ubuntu-latest
    outputs:
      current_version: ${{ steps.get_version.outputs.current }}
    steps:
      - uses: actions/checkout@v4
      - name: Get current version from Cargo.toml
        id: get_version
        run: |
          current_version=$(grep '^version =' Cargo.toml | head -1 | cut -d'"' -f2)
          echo "Current version: $current_version"
          echo "::set-output name=current::$current_version"
      - name: Ensure version bump
        run: |
          tag="v$(echo "${{ steps.get_version.outputs.current }}")"
          if git rev-parse "$tag" >/dev/null 2>&1; then
            echo "Tag $tag already exists. Please bump version."
            exit 1
          else
            echo "No tag $tag found, version bump confirmed."
          fi

  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
    needs: check-version
    outputs:
      artifact_name: ${{ steps.upload_artifact.outputs.artifact_name }}
    steps:
      - uses: actions/checkout@v4

      - name: Set up Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable

      - name: Run tests
        run: cargo test

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

      - name: Upload build artifact
        id: upload_artifact
        uses: actions/upload-artifact@v4
        with:
          name: build-${{ matrix.os }}
          path: target/release/folder-declutter  # adjust binary name if needed

  release:
    runs-on: ubuntu-latest
    needs: [check-version, build]
    outputs:
      current_version: ${{ needs.check-version.outputs.current_version }}
    steps:
      - uses: actions/checkout@v4
      - name: Get current version from Cargo.toml
        id: get_version
        run: |
          current_version=$(grep '^version =' Cargo.toml | head -1 | cut -d'"' -f2)
          echo "::set-output name=current::$current_version"
      - name: Download Linux Artifact
        uses: actions/download-artifact@v4
        with:
          name: build-ubuntu-latest
          path: artifact-linux
      - name: Download macOS Artifact
        uses: actions/download-artifact@v4
        with:
          name: build-macos-latest
          path: artifact-macos

      - name: Rename binaries
        run: |
          mv artifact-linux/folder-declutter artifact-linux/folder-declutter-linux-${{ steps.get_version.outputs.current }}
          mv artifact-macos/folder-declutter artifact-macos/folder-declutter-macos-${{ steps.get_version.outputs.current }}

      - name: Create Release and attach artifacts
        id: create_release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: v${{ steps.get_version.outputs.current }}
          name: "Release v${{ steps.get_version.outputs.current }}"
          generate_release_notes: true
          draft: false
          prerelease: false
          make_latest: true
          files: |
            artifact-linux/folder-declutter-linux-${{ steps.get_version.outputs.current }}
            artifact-macos/folder-declutter-macos-${{ steps.get_version.outputs.current }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  publish:
    needs: [release]
    uses: ./.github/workflows/publish.yml
    secrets: inherit
    with:
      current_version: ${{ needs.release.outputs.current_version }}