mirror of
https://github.com/actions/cache.git
synced 2026-01-14 09:33:07 +08:00
Compare commits
3 Commits
f872791b07
...
64f681547e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64f681547e | ||
|
|
9fa7e61ec7 | ||
|
|
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`). 🔍'
|
||||||
|
|||||||
@ -37,9 +37,8 @@ From `v3.2.3` cache is cross-os compatible when `enableCrossOsArchive` input is
|
|||||||
|
|
||||||
## Force deletion of caches overriding default cache eviction policy
|
## Force deletion of caches overriding default cache eviction policy
|
||||||
|
|
||||||
Caches have [branch scope restriction](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache) in place. This means that if caches for a specific branch are using a lot of storage quota, it may result into more frequently used caches from `default` branch getting thrashed. For example, if there are many pull requests happening on a repo and are creating caches, these cannot be used in default branch scope but will still occupy a lot of space till they get cleaned up by [eviction policy](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy). But sometime we want to clean them up on a faster cadence so as to ensure default branch is not thrashing. In order to achieve this, [gh-actions-cache cli](https://github.com/actions/gh-actions-cache/) can be used to delete caches for specific branches.
|
Caches have [branch scope restriction](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache) in place. This means that if caches for a specific branch are using a lot of storage quota, it may result into more frequently used caches from `default` branch getting thrashed. For example, if there are many pull requests happening on a repo and are creating caches, these cannot be used in default branch scope but will still occupy a lot of space till they get cleaned up by [eviction policy](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy). But sometime we want to clean them up on a faster cadence so as to ensure default branch is not thrashing.
|
||||||
|
|
||||||
This workflow uses `gh-actions-cache` to delete all the caches created by a branch.
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Example</summary>
|
<summary>Example</summary>
|
||||||
|
|
||||||
@ -60,29 +59,23 @@ jobs:
|
|||||||
actions: write
|
actions: write
|
||||||
contents: read
|
contents: read
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Cleanup
|
- name: Cleanup
|
||||||
run: |
|
run: |
|
||||||
gh extension install actions/gh-actions-cache
|
|
||||||
|
|
||||||
REPO=${{ github.repository }}
|
|
||||||
BRANCH=refs/pull/${{ github.event.pull_request.number }}/merge
|
|
||||||
|
|
||||||
echo "Fetching list of cache key"
|
echo "Fetching list of cache key"
|
||||||
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
|
cacheKeysForPR=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id')
|
||||||
|
|
||||||
## Setting this to not fail the workflow while deleting cache keys.
|
## Setting this to not fail the workflow while deleting cache keys.
|
||||||
set +e
|
set +e
|
||||||
echo "Deleting caches..."
|
echo "Deleting caches..."
|
||||||
for cacheKey in $cacheKeysForPR
|
for cacheKey in $cacheKeysForPR
|
||||||
do
|
do
|
||||||
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
|
gh cache delete $cacheKey
|
||||||
done
|
done
|
||||||
echo "Done"
|
echo "Done"
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
GH_REPO: ${{ github.repository }}
|
||||||
|
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user