Skip to content

feat(scripts): containerised cargo-sweep recipe to prune stale target/ artifacts - #276

Open
elasticdotventures wants to merge 3 commits into
mainfrom
feat/275-cargo-sweep
Open

elasticdotventures wants to merge 3 commits into
mainfrom
feat/275-cargo-sweep

Conversation

@elasticdotventures

@elasticdotventures elasticdotventures commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Closes #275

What

Adds a containerised cargo-sweep wrapper so stale target/ artifacts can be pruned without installing anything on the host.

  • scripts/cargo-sweep/Containerfile - pins cargo-sweep 0.8.0 on rust:1-slim-bookworm. The image build context is that directory only, so building never sends the repo (or its target/) to the container engine.
  • scripts/cargo-sweep/sweep.sh - podman or docker; dry run by default with the repo mounted read-only; --apply mounts read-write and deletes; --days N (default 14) or --maxsize SIZE; --root DIR.
  • just sweep [days] [--apply] - thin recipe over the script (appended to the end of the Justfile).
  • scripts/cargo-sweep/README.md.

Age is taken from file access/modification times, so it also works on target/ directories built by another OS or toolchain. --installed is deliberately not exposed: inside the container it would compare against the container's toolchain, not the host's.

Verification (all tooling run in containers)

  • shellcheck -x scripts/cargo-sweep/sweep.sh: clean. bash -n: OK. Bad arguments are rejected with a message.
  • just --list shows the recipe; just --dry-run sweep, sweep 30, sweep 14 --apply expand to the expected bash scripts/cargo-sweep/sweep.sh calls.
  • A --time 14 dry run against a real 258 GB target/ (built on Windows, swept from a Linux container via Podman) reported Would clean: 216.63 GiB; it took about 5 minutes over the Windows filesystem and deleted nothing.
  • --apply on a real crate built in the container, with its whole target/ backdated 90 days: the dry run left all 20 files untouched; --apply --days 30 printed Cleaned 8.63 KiB and the file count went 20 -> 13.
  • An unresolvable workspace (cargo-sweep itself silently skips workspaces cargo metadata cannot resolve, e.g. an uninitialised git submodule) now prints an explanatory note instead of an empty result; a normal repo still reports sizes and exit code 0.
  • File modes: only sweep.sh is executable.

Not covered

  • Not run under Docker (only Podman). The script takes CONTAINER_ENGINE and uses only image inspect, build and run.
  • --apply was exercised on a throwaway crate, not on a real checkout's target/.
  • Process note: this repo's CLAUDE.md asks for changes to go through a GSD workflow; that tooling was not available in the session that prepared this PR, so the change was made directly in a fresh clone at the owner's explicit request.

🤖 Generated with Claude Code

elasticdotventures and others added 3 commits October 25, 2026 11:35
…/ artifacts

Adds scripts/cargo-sweep/{Containerfile,sweep.sh,README.md} and a thin
`just sweep [days] [--apply]` recipe. cargo-sweep 0.8.0 runs in a container
(podman or docker) so nothing is installed on the host. Dry run by default with
the repo mounted read-only; --apply deletes; --maxsize trims oldest-first.

Verified: shellcheck clean; dry run leaves every file untouched; --apply on a
real, backdated crate build removed the stale artifacts (20 -> 13 files).
A --time 14 dry run against a real 258 GB checkout target/ (built on Windows,
swept from a Linux container) reported 216.63 GiB reclaimable.

Closes #275

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
cargo-sweep silently skips a workspace that `cargo metadata` cannot resolve
(for example an uninitialised git submodule or missing path dependency), which
left an empty, unexplained result. sweep.sh now keeps the tool's output and
prints a note pointing at the likely cause when no "Would clean"/"Cleaned" line
appears; the exit code of the container run is preserved. README documents it.

Verified: shellcheck clean; a normal repo still reports sizes with exit code 0;
an unresolvable workspace prints the note; a bad --root still exits non-zero.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The intro quoted size figures measured in a different repository, which reads
as a claim about this one. Replace with a neutral statement; the measured
figures for this repo are in the linked issue and PR.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: containerised cargo-sweep recipe to prune stale target/ artifacts

1 participant