Skip to content

Commit

Permalink
Replace input table (#39)
Browse files Browse the repository at this point in the history
* refactor: replace input table with commented yaml

This also updates the descriptions in `action.yml` to be consistent.

* fix: `cache-hit` output and update outputs documentation
  • Loading branch information
BD103 authored Oct 31, 2024
1 parent 5b068d2 commit a0709d8
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 36 deletions.
66 changes: 51 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,60 @@ jobs:
## Inputs
| Name | Description | Type | Default |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ------------------------------------------------------------------------------ |
| `cache-group` | The group of the cache, defaults to a unique identifier for the workflow job. If you want two jobs to share the same cache, give them the same group name. | `string` | `${{ hashFiles(env.workflow_path)-${{ github.job }}-${{ strategy.job-index }}` |
| `cargo-home` | The location of the Cargo cache files. If you specify the `CARGO_HOME` env variable for your commands, you need to set it here too. This must NOT end with the trailing slash of the directory. | `string` | `~/.cargo` |
| `cargo-target-dir` | Location of where to place all generated artifacts, relative to the current working directory. If you specify the `CARGO_TARGET_DIR` env variable for your commands, you need to set it here too. This must NOT end with the trailing slash of the directory. | `string` | `target` |
|`manifest-path`|The path to `Cargo.toml`. This is used to determine where `Cargo.lock` is, which is used in the cache key.|`string`|`Cargo.toml`|
| `save-if` | A condition which determines whether the cache should be saved. Otherwise, it's only restored | `boolean` | `true` |
| `save-always` | This input has been deprecated and will be removed in v3.0.0. It has no effect. This used to specify the `save-always` input for `actions/cache`, but has been deprecated due to its unintended behavior. If you still require this input, you will need to manually use `actions/cache`. For more information, please see <https://github.com/actions/cache/tree/v4/save#always-save-cache>. | `boolean` ||
|`sweep-cache`|Use `cargo-sweep` to automatically delete files in the target folder that are not used between when this action is called and the end of the workflow. This can prevent the size of caches steadily increasing, since new caches are generated from fallback caches that may include stale artifacts.|`boolean`|`false`|
|`cache-cargo-sweep`|This input has been deprecated and will be removed in v3.0.0. It has no effect.|`boolean`||

[`cargo-sweep`]: https://crates.io/crates/cargo-sweep
```yaml
- uses: Leafwing-Studios/cargo-cache@v2
with:
# The group of the cache, defaulting to a unique identifier for the workflow job.
#
# If you want two jobs to share the same cache, give them the same group name.
cache-group: ${{ hashFiles(env.workflow_path)-${{ github.job }}-${{ strategy.job-index }}`

# The location of the Cargo home directory.
#
# If you specify the `CARGO_HOME` env variable for your commands, you need to set it here too.
# This must *not* end with the trailing slash of the directory.
cargo-home: ~/.cargo

# The location where Cargo places all generated artifacts, relative to the current working
# directory.
#
# If you specify the `CARGO_TARGET_DIR` environmental variable or `--target-dir` for your
# commands, you need to set it here as well. This must *not* end with the trailing slash of the directory.
cargo-target-dir: target

# The path to `Cargo.toml`.
#
# This is used to determine where `Cargo.lock` and is, which is used in the cache key.
manifest-path: Cargo.toml

# This input has been deprecated and will be removed in v3.0.0. It has no effect.
#
# This input used to specify the `save-always` input for `actions/cache`, but has been
# deprecated due to its unintended behavior. If you still require this input, you will need
# to manually use `actions/cache`. For more information, please see
# <https://github.com/actions/cache/tree/v4/save#always-save-cache>.
save-always: ''

# Determines if the cache should be saved, or only loaded.
#
# Setting this to `false` will prevent new caches from being created.
save-if: true

# Automatically delete files in the target folder that are not used between when this action is
# called and the end of the job.
#
# This can prevent the size of caches snowballing. Since old caches are used to create new
# caches, unused files can slowly pile up over time, causing larger caches are longer runtimes.
sweep-cache: false

# This input has been deprecated and will be removed in v3.0.0. It has no effect.
cache-cargo-sweep: ''
```
## Outputs
| Name | Description | Type | Note |
| ----------- | -------------------------------------------------------------------- | --------- | ----------------------------------------------- |
| `cache-hit` | A boolean value to indicate if an exact match was found for the key. | `boolean` | Passed through from the `actions/cache` action. |
- `cache-hit`: A string value that indicates if an exact match was found for the key.
- This is passed from `actions/cache`, so please see [its output documentation](https://github.com/actions/cache/tree/v4#outputs) for more information.

## How It Works

Expand Down
48 changes: 27 additions & 21 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,35 @@ description: Cache cargo build files and the registry
inputs:
cache-group:
description: |
The group of the cache, defaults to a unique identifier for the workflow job.
The group of the cache, defaulting to a unique identifier for the workflow job.
If you want two jobs to share the same cache, give them the same group name.
required: false
cargo-home:
description: |
The location of the Cargo cache files.
The location of the Cargo home directory.
If you specify the `CARGO_HOME` env variable for your commands, you need to set it here too.
This must NOT end with the trailing slash of the directory.
Defaults to `~/.cargo`.
This must *not* end with the trailing slash of the directory.
required: false
default: ~/.cargo
cargo-target-dir:
description: |
Location of where to place all generated artifacts, relative to the current working directory.
If you specify the `CARGO_TARGET_DIR` env variable for your commands, you need to set it here too.
This must NOT end with the trailing slash of the directory.
Defaults to `target`.
The location where Cargo places all generated artifacts, relative to the current working
directory.
If you specify the `CARGO_TARGET_DIR` environmental variable or `--target-dir` for your
commands, you need to set it here as well. This must *not* end with the trailing slash of the
directory.
required: false
default: target
manifest-path:
description: |
The path to `Cargo.toml`. This is used to determine where `Cargo.lock` is, which is used in
the cache key.
Defaults to the `Cargo.toml` in the current working directory.
The path to `Cargo.toml`.
This is used to determine where `Cargo.lock` and is, which is used in the cache key.
required: false
default: "Cargo.toml"
default: Cargo.toml
save-always:
description: |
This input has been deprecated and will be removed in v3.0.0. It has no effect.
Expand All @@ -40,16 +43,18 @@ inputs:
required: false
save-if:
description: |
A condition to determine whether the new cache should be saved.
If it evaluates to `false`, the cache is only loaded.
Determines if the cache should be saved, or only loaded.
Setting this to `false` will prevent new caches from being created.
required: false
default: "true"
sweep-cache:
description: |
Use `cargo-sweep` to automatically delete files in the target folder that are not used
between when this action is called and the end of the workflow. This can prevent the size of
caches steadily increasing, since new caches are generated from fallback caches that may
include stale artifacts.
Automatically delete files in the target folder that are not used between when this action is
called and the end of the job.
This can prevent the size of caches snowballing. Since old caches are used to create new
caches, unused files can slowly pile up over time, causing larger caches are longer runtimes.
required: false
default: "false"
cache-cargo-sweep:
Expand All @@ -59,9 +64,10 @@ inputs:
outputs:
cache-hit:
description: |
A boolean value to indicate if an exact match was found for the key.
Passed through from the `actions/cache` action.
value: ${{ steps.cache.outputs.random-number }}
A string value that indicates if an exact match was found for the key.
This is passed through from the `actions/cache` action.
value: ${{ steps.cache.outputs.cache-hit }}
runs:
using: composite
steps:
Expand Down

0 comments on commit a0709d8

Please sign in to comment.