{"id":18952233,"url":"https://github.com/step-security/rust-cache","last_synced_at":"2026-03-29T03:30:18.015Z","repository":{"id":247346372,"uuid":"822636713","full_name":"step-security/rust-cache","owner":"step-security","description":"A GitHub Action that implements smart caching for rust/cargo projects","archived":false,"fork":false,"pushed_at":"2025-02-11T10:02:19.000Z","size":1809,"stargazers_count":0,"open_issues_count":15,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-02-11T11:22:40.928Z","etag":null,"topics":["step-security-maintained-actions"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/step-security.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-01T14:13:48.000Z","updated_at":"2025-02-11T10:02:24.000Z","dependencies_parsed_at":"2024-08-08T08:18:14.875Z","dependency_job_id":"82566f47-8e52-462e-b9c2-7dddb77e836e","html_url":"https://github.com/step-security/rust-cache","commit_stats":null,"previous_names":["step-security/rust-cache"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/step-security%2Frust-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/step-security%2Frust-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/step-security%2Frust-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/step-security%2Frust-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/step-security","download_url":"https://codeload.github.com/step-security/rust-cache/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239951607,"owners_count":19723909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["step-security-maintained-actions"],"created_at":"2024-11-08T13:31:57.286Z","updated_at":"2026-03-29T03:30:17.949Z","avatar_url":"https://github.com/step-security.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rust Cache Action\n\nA GitHub Action that implements smart caching for rust/cargo projects with\nsensible defaults.\n\n## Example usage\n\n```yaml\n- uses: actions/checkout@v4\n\n# selecting a toolchain either by action or manual `rustup` calls should happen\n# before the plugin, as the cache uses the current rustc version as its cache key\n- run: rustup toolchain install stable --profile minimal\n\n- uses: step-security/rust-cache@v2\n  with:\n    # The prefix cache key, this can be changed to start a new cache manually.\n    # default: \"v0-rust\"\n    prefix-key: \"\"\n\n    # A cache key that is used instead of the automatic `job`-based key,\n    # and is stable over multiple jobs.\n    # default: empty\n    shared-key: \"\"\n\n    # An additional cache key that is added alongside the automatic `job`-based\n    # cache key and can be used to further differentiate jobs.\n    # default: empty\n    key: \"\"\n\n    # A whitespace separated list of env-var *prefixes* who's value contributes\n    # to the environment cache key.\n    # The env-vars are matched by *prefix*, so the default `RUST` var will\n    # match all of `RUSTC`, `RUSTUP_*`, `RUSTFLAGS`, `RUSTDOC_*`, etc.\n    # default: \"CARGO CC CFLAGS CXX CMAKE RUST\"\n    env-vars: \"\"\n\n    # The cargo workspaces and target directory configuration.\n    # These entries are separated by newlines and have the form\n    # `$workspace -\u003e $target`. The `$target` part is treated as a directory\n    # relative to the `$workspace` and defaults to \"target\" if not explicitly given.\n    # default: \". -\u003e target\"\n    workspaces: \"\"\n\n    # Additional non workspace directories to be cached, separated by newlines.\n    cache-directories: \"\"\n\n    # Determines whether workspace `target` directories are cached.\n    # If `false`, only the cargo registry will be cached.\n    # default: \"true\"\n    cache-targets: \"\"\n\n    # Determines if the cache should be saved even when the workflow has failed.\n    # default: \"false\"\n    cache-on-failure: \"\"\n\n    # Determines which crates are cached.\n    # If `true` all crates will be cached, otherwise only dependent crates will be cached.\n    # Useful if additional crates are used for CI tooling.\n    # default: \"false\"\n    cache-all-crates: \"\"\n\n    # Determiners whether the cache should be saved.\n    # If `false`, the cache is only restored.\n    # Useful for jobs where the matrix is additive e.g. additional Cargo features,\n    # or when only runs from `main` should be saved to the cache.\n    # default: \"true\"\n    save-if: \"\"\n    # To only cache runs from `main`:\n    save-if: ${{ github.ref == 'refs/heads/main' }}\n\n    # Specifies what to use as the backend providing cache\n    # Can be set to either \"github\" or \"buildjet\"\n    # default: \"github\"\n    cache-provider: \"\"\n```\n\nFurther examples are available in the [.github/workflows](./.github/workflows/) directory.\n\n## Outputs\n\n**`cache-hit`**\n\nThis is a boolean flag that will be set to `true` when there was an exact cache hit.\n\n## Cache Effectiveness\n\nThis action only caches the _dependencies_ of a crate, so is more effective if\nthe dependency / own code ratio is higher.\n\nIt is also most effective for repositories with a `Cargo.lock` file. Library\nrepositories with only a `Cargo.toml` file have limited benefits, as cargo will\n_always_ use the most up-to-date dependency versions, which may not be cached.\n\nUsage with Stable Rust is most effective, as a cache is tied to the Rust version.\nUsing it with Nightly Rust is less effective as it will throw away the cache every day,\nunless a specific nightly build is being pinned.\n\n## Cache Details\n\nThis action currently caches the following files/directories:\n\n- `~/.cargo` (installed binaries, the cargo registry, cache, and git dependencies)\n- `./target` (build artifacts of dependencies)\n\nThis cache is automatically keyed by:\n\n- the github [`job_id`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_id),\n- the rustc release / host / hash,\n- the value of some compiler-specific environment variables (eg. RUSTFLAGS, etc), and\n- a hash of all `Cargo.lock` / `Cargo.toml` files found anywhere in the repository (if present).\n- a hash of all `rust-toolchain` / `rust-toolchain.toml` files in the root of the repository (if present).\n- a hash of all `.cargo/config.toml` files in the root of the repository (if present).\n\nAn additional input `key` can be provided if the builtin keys are not sufficient.\n\nBefore being persisted, the cache is cleaned of:\n\n- Any files in `~/.cargo/bin` that were present before the action ran (for example `rustc`).\n- Dependencies that are no longer used.\n- Anything that is not a dependency.\n- Incremental build artifacts.\n- Any build artifacts with an `mtime` older than one week.\n\nIn particular, the workspace crates themselves are not cached since doing so is\n[generally not effective](https://github.com/step-security/rust-cache/issues/37#issuecomment-944697938).\nFor this reason, this action automatically sets `CARGO_INCREMENTAL=0` to disable\nincremental compilation, so that the Rust compiler doesn't waste time creating\nthe additional artifacts required for incremental builds.\n\nThe `~/.cargo/registry/src` directory is not cached since it is quicker for Cargo\nto recreate it from the compressed crate archives in `~/.cargo/registry/cache`.\n\nThe action will try to restore from a previous `Cargo.lock` version as well, so\nlockfile updates should only re-build changed dependencies.\n\nThe action invokes `cargo metadata` to determine the current set of dependencies.\n\nAdditionally, the action automatically works around\n[cargo#8603](https://github.com/rust-lang/cargo/issues/8603) /\n[actions/cache#403](https://github.com/actions/cache/issues/403) which would\notherwise corrupt the cache on macOS builds.\n\n## Cache Limits and Control\n\nThis specialized cache action is built on top of the upstream cache action\nmaintained by GitHub. The same restrictions and limits apply, which are\ndocumented here:\n[Caching dependencies to speed up workflows](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows)\n\nIn particular, caches are currently limited to 10 GB in total and exceeding that\nlimit will cause eviction of older caches.\n\nCaches from base branches are available to PRs, but not across unrelated\nbranches.\n\nThe caches can be controlled using the [Cache API](https://docs.github.com/en/rest/actions/cache)\nwhich allows listing existing caches and manually removing entries.\n\n## Debugging\n\nThe action prints detailed information about which information it considers\nfor its cache key, and it outputs more debug-only information about which\ncleanup steps it performs before persisting the cache.\n\nYou can read up on how to [enable debug logging](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging)\nto see those details as well as further details related to caching operations.\n\n## Known issues\n\n- The cache cleaning process currently removes all the files from `~/.cargo/bin`\n  that were present before the action ran (for example `rustc`).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstep-security%2Frust-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstep-security%2Frust-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstep-security%2Frust-cache/lists"}