Remove stale build artifacts from your Cargo caches in Github Actions!
  • TypeScript 100%
Find a file
2025-02-04 17:15:59 -05:00
.github/workflows Verify ncc output in CI (#12) 2024-11-01 13:12:41 -04:00
dist fix: exit early if target does not exist 2025-02-04 17:15:59 -05:00
src fix: exit early if target does not exist 2025-02-04 17:15:59 -05:00
.gitignore feat: create initial action 2024-08-07 11:33:43 -04:00
action.yml chore: small cleanup 2024-11-01 12:36:41 -04:00
LICENSE chore: license under mit 2024-08-14 14:42:53 -04:00
package.json chore: bump dependencies 2025-02-04 17:05:21 -05:00
pnpm-lock.yaml chore: bump dependencies 2025-02-04 17:05:21 -05:00
README.md feat: add inputs section and note that rust must be installed in README.md 2024-10-30 16:37:15 -04:00
tsconfig.json queued operations and ts (#9) 2024-10-31 08:00:17 -04:00

cargo-sweep action

This action cleans up stale build files from the target directory of Rust projects. It can be used to delete files that are never accessed between when this action runs and the end of the job.

Note

This action originally leveraged cargo-sweep to implement its logic, but has since transitioned to a faster, pure-Javascript approach. The name has been kept for historical reasons, but cargo-sweep is no longer installed when running this action.

When would you use this?

This is most useful if you cache the target directory and use restore-keys to fallback on old caches. In these specific examples, old artifacts tend to pile up over time, causing caches to grow to gigabytes in size. You can use cargo-sweep to prune these old artifacts while keeping the current ones.

Quickstart

# Rust (and Cargo) must be installed in order to use `cargo-sweep`.
- name: Install Rust
  uses: dtolnay/rust-toolchain@stable

# Make sure to restore your cache before calling `cargo-sweep`.
- name: Cache build files
  uses: actions/cache@v4
  with:
    # You probably want to cache more files and use a more-detailed key. This is kept short for
    # brevity's sake.
    path: target
    key: my-job-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
    # `cargo-sweep` is only useful if you use restore keys.
    restore-keys: my-job-${{ runner.os }}-

- name: Sweep cache for stale files
  uses: BD103/cargo-sweep@v2

# Any artifacts used between `cargo-sweep` and the end of the job will be kept, the rest will be
# discarded.
- run: cargo build

Tip

For an all-in-one caching and sweeping solution, I highly recommend Leafwing-Studios/cargo-cache, which integrates with this action directly!

Inputs

- name: Sweep cache for stale files
  uses: BD103/cargo-sweep@v2
  with:
    # The path to `Cargo.toml`, used to discover the Cargo workspace and `target` directory. By
    # default this is the `Cargo.toml` in the current working directory.
    manifest-path: Cargo.toml