mirror of
https://github.com/actions/cache.git
synced 2026-01-13 17:13:06 +08:00
Compare commits
4 Commits
e7e9bdd0a0
...
f872791b07
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f872791b07 | ||
|
|
36f1e144e1 | ||
|
|
53aa38c736 | ||
|
|
fa6c089775 |
11
README.md
11
README.md
@ -335,6 +335,17 @@ There are a number of community practices/workarounds to fulfill specific requir
|
|||||||
|
|
||||||
Please note that Windows environment variables (like `%LocalAppData%`) will NOT be expanded by this action. Instead, prefer using `~` in your paths which will expand to the HOME directory. For example, instead of `%LocalAppData%`, use `~\AppData\Local`. For a list of supported default environment variables, see the [Learn GitHub Actions: Variables](https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables) page.
|
Please note that Windows environment variables (like `%LocalAppData%`) will NOT be expanded by this action. Instead, prefer using `~` in your paths which will expand to the HOME directory. For example, instead of `%LocalAppData%`, use `~\AppData\Local`. For a list of supported default environment variables, see the [Learn GitHub Actions: Variables](https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables) page.
|
||||||
|
|
||||||
|
## Main functionalities
|
||||||
|
|
||||||
|
The `cache` action in this repository provides several main functionalities:
|
||||||
|
|
||||||
|
* **Caching dependencies and build outputs**: The primary function of the `cache` action is to cache dependencies and build outputs to improve workflow execution time. This is specified in the `description` field of the `action.yml` file (`action.yml`). 🗃️
|
||||||
|
* **Restoring cache**: The `cache` action can restore cached files, directories, and wildcard patterns specified in the `path` input. This is done using the `restoreCache` function from the `@actions/cache` package (`src/restoreImpl.ts`). 🔄
|
||||||
|
* **Saving cache**: The `cache` action can save files, directories, and wildcard patterns specified in the `path` input to the cache. This is done using the `saveCache` function from the `@actions/cache` package (`src/saveImpl.ts`). 💾
|
||||||
|
* **Cross-OS caching**: The `cache` action supports cross-OS caching, allowing Windows runners to save or restore caches that can be restored or saved respectively on other platforms. This is controlled by the `enableCrossOsArchive` input (`action.yml`). 🌐
|
||||||
|
* **Failing on cache miss**: The `cache` action can be configured to fail the workflow if a cache entry is not found. This is controlled by the `fail-on-cache-miss` input (`action.yml`). ❌
|
||||||
|
* **Lookup-only mode**: The `cache` action can check if a cache entry exists for the given inputs without downloading the cache. This is controlled by the `lookup-only` input (`action.yml`). 🔍
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
We would love for you to contribute to `actions/cache`. Pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
|
We would love for you to contribute to `actions/cache`. Pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information.
|
||||||
|
|||||||
10
action.yml
10
action.yml
@ -45,3 +45,13 @@ runs:
|
|||||||
branding:
|
branding:
|
||||||
icon: 'archive'
|
icon: 'archive'
|
||||||
color: 'gray-dark'
|
color: 'gray-dark'
|
||||||
|
|
||||||
|
main functionalities:
|
||||||
|
description: 'The main functionalities provided by the `cache` action are:'
|
||||||
|
details:
|
||||||
|
- 'Caching dependencies and build outputs: The primary function of the `cache` action is to cache dependencies and build outputs to improve workflow execution time. This is specified in the `description` field of the `action.yml` file (`action.yml`). 🗃️'
|
||||||
|
- 'Restoring cache: The `cache` action can restore cached files, directories, and wildcard patterns specified in the `path` input. This is done using the `restoreCache` function from the `@actions/cache` package (`src/restoreImpl.ts`). 🔄'
|
||||||
|
- 'Saving cache: The `cache` action can save files, directories, and wildcard patterns specified in the `path` input to the cache. This is done using the `saveCache` function from the `@actions/cache` package (`src/saveImpl.ts`). 💾'
|
||||||
|
- 'Cross-OS caching: The `cache` action supports cross-OS caching, allowing Windows runners to save or restore caches that can be restored or saved respectively on other platforms. This is controlled by the `enableCrossOsArchive` input (`action.yml`). 🌐'
|
||||||
|
- 'Failing on cache miss: The `cache` action can be configured to fail the workflow if a cache entry is not found. This is controlled by the `fail-on-cache-miss` input (`action.yml`). ❌'
|
||||||
|
- 'Lookup-only mode: The `cache` action can check if a cache entry exists for the given inputs without downloading the cache. This is controlled by the `lookup-only` input (`action.yml`). 🔍'
|
||||||
|
|||||||
@ -102,7 +102,7 @@ The [GitHub Context](https://docs.github.com/en/actions/learn-github-actions/con
|
|||||||
|
|
||||||
While setting paths for caching dependencies it is important to give correct path depending on the hosted runner you are using or whether the action is running in a container job. Assigning different `path` for save and restore will result in cache miss.
|
While setting paths for caching dependencies it is important to give correct path depending on the hosted runner you are using or whether the action is running in a container job. Assigning different `path` for save and restore will result in cache miss.
|
||||||
|
|
||||||
Below are GiHub hosted runner specific paths one should take care of when writing a workflow which saves/restores caches across OS.
|
Below are GitHub hosted runner specific paths one should take care of when writing a workflow which saves/restores caches across OS.
|
||||||
|
|
||||||
#### Ubuntu Paths
|
#### Ubuntu Paths
|
||||||
|
|
||||||
|
|||||||
@ -79,8 +79,10 @@ To avoid saving a cache that already exists, the `cache-hit` output from a resto
|
|||||||
The `cache-primary-key` output from the restore step should also be used to ensure
|
The `cache-primary-key` output from the restore step should also be used to ensure
|
||||||
the cache key does not change during the build if it's calculated based on file contents.
|
the cache key does not change during the build if it's calculated based on file contents.
|
||||||
|
|
||||||
|
Here's an example where we imagine we're calculating a lot of prime numbers and want to cache them:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
name: Always Caching Primes
|
name: Always Caching Prime Numbers
|
||||||
|
|
||||||
on: push
|
on: push
|
||||||
|
|
||||||
@ -91,23 +93,23 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Restore cached Primes
|
- name: Restore cached Prime Numbers
|
||||||
id: cache-primes-restore
|
id: cache-prime-numbers-restore
|
||||||
uses: actions/cache/restore@v4
|
uses: actions/cache/restore@v4
|
||||||
with:
|
with:
|
||||||
key: ${{ runner.os }}-primes
|
key: ${{ runner.os }}-prime-numbers
|
||||||
path: |
|
path: |
|
||||||
path/to/dependencies
|
path/to/dependencies
|
||||||
some/other/dependencies
|
some/other/dependencies
|
||||||
|
|
||||||
# Intermediate workflow steps
|
# Intermediate workflow steps
|
||||||
|
|
||||||
- name: Always Save Primes
|
- name: Always Save Prime Numbers
|
||||||
id: cache-primes-save
|
id: cache-prime-numbers-save
|
||||||
if: always() && steps.cache-primes-restore.outputs.cache-hit != 'true'
|
if: always() && steps.cache-prime-numbers-restore.outputs.cache-hit != 'true'
|
||||||
uses: actions/cache/save@v4
|
uses: actions/cache/save@v4
|
||||||
with:
|
with:
|
||||||
key: ${{ steps.cache-primes-restore.outputs.cache-primary-key }}
|
key: ${{ steps.cache-prime-numbers-restore.outputs.cache-primary-key }}
|
||||||
path: |
|
path: |
|
||||||
path/to/dependencies
|
path/to/dependencies
|
||||||
some/other/dependencies
|
some/other/dependencies
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user