Skip to content

Commit 9ed8cf5

Browse files
committed
Add support for adding to cache key
When using this action in multiple jobs in the same workflow, the generated cache key is the same for all of them. This means that all apart from the first job are unable to save the cache, and subsequent runs might restore the wrong cache. The `Swatinem/rust-cache` action which we use for caching has a `key` input which it puts in its cache key. (It doesn't override the key, just adds to it.) Providing this as an input here will allow us to generate a unique cache key for each job.
1 parent 1fbea72 commit 9ed8cf5

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Caching for Rust tools and build artifacts is enabled.
66
Environment variables are set to optimize the cache hits.
77
[Problem Matchers] are provided for build messages (cargo, clippy) and formatting (rustfmt).
88

9-
The action is heavily inspired by *dtolnay*'s <https://github.com/dtolnay/rust-toolchain> and extends it with further features.
9+
The action is heavily inspired by _dtolnay_'s <https://github.com/dtolnay/rust-toolchain> and extends it with further features.
1010

1111
## Example workflow
1212

@@ -49,13 +49,14 @@ First, all items specified in the toolchain file are installed.
4949
Afterward, the `components` and `target` specified via inputs are installed in addition to the items from the toolchain file.
5050

5151
| Name | Description | Default |
52-
|--------------------|----------------------------------------------------------------------------------------|---------------|
52+
| ------------------ | -------------------------------------------------------------------------------------- | ------------- |
5353
| `toolchain` | Rustup toolchain specifier e.g. `stable`, `nightly`, `1.42.0`. | stable |
5454
| `target` | Additional target support to install e.g. `wasm32-unknown-unknown` | |
5555
| `components` | Comma-separated string of additional components to install e.g. `clippy, rustfmt` | |
5656
| `cache` | Automatically configure Rust cache (using [`Swatinem/rust-cache`]) | true |
5757
| `cache-workspaces` | Propagates the value to [`Swatinem/rust-cache`] | |
5858
| `cache-on-failure` | Propagates the value to [`Swatinem/rust-cache`] | true |
59+
| `key` | Propagates the value to [`Swatinem/rust-cache`] | |
5960
| `matcher` | Enable problem matcher to surface build messages and formatting issues | true |
6061
| `rustflags` | Set the value of `RUSTFLAGS` (set to empty string to avoid overwriting existing flags) | "-D warnings" |
6162

@@ -66,10 +67,10 @@ Afterward, the `components` and `target` specified via inputs are installed in a
6667
By default, this action sets the `RUSTFLAGS` environment variable to `-D warnings`.
6768
However, rustflags sources are mutually exclusive, so setting this environment variable omits any configuration through `target.*.rustflags` or `build.rustflags`.
6869

69-
* If `RUSTFLAGS` is already set, no modifications of the variable are made and the original value remains.
70-
* If `RUSTFLAGS` is unset and the `rustflags` input is empty (i.e., the empty string), then it will remain unset.
71-
Use this, if you want to prevent the value from being set because you make use of `target.*.rustflags` or `build.rustflags`.
72-
* Otherwise, the environment variable `RUSTFLAGS` is set to the content of `rustflags`.
70+
- If `RUSTFLAGS` is already set, no modifications of the variable are made and the original value remains.
71+
- If `RUSTFLAGS` is unset and the `rustflags` input is empty (i.e., the empty string), then it will remain unset.
72+
Use this, if you want to prevent the value from being set because you make use of `target.*.rustflags` or `build.rustflags`.
73+
- Otherwise, the environment variable `RUSTFLAGS` is set to the content of `rustflags`.
7374

7475
To prevent this from happening, set the `rustflags` input to an empty string, which will
7576
prevent the action from setting `RUSTFLAGS` at all, keeping any existing preferences.

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ inputs:
3232
description: "Also cache on workflow failures"
3333
default: "true"
3434
required: false
35+
key:
36+
description: "An additional cache key that is added alongside the automatic `job`-based cache key and can be used to further differentiate jobs."
37+
required: false
3538
matcher:
3639
description: "Enable the Rust problem matcher"
3740
required: false
@@ -181,3 +184,4 @@ runs:
181184
with:
182185
workspaces: ${{inputs.cache-workspaces}}
183186
cache-on-failure: ${{inputs.cache-on-failure}}
187+
key: ${{inputs.key}}

0 commit comments

Comments
 (0)