|
|
|
@@ -19,7 +19,7 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac
|
|
|
|
|
* Fixed cache not working with github workspace directory or current directory.
|
|
|
|
|
* Fixed the download stuck problem by introducing a timeout of 1 hour for cache downloads.
|
|
|
|
|
* Fix zstd not working for windows on gnu tar in issues.
|
|
|
|
|
* Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable `SEGMENT_DOWNLOAD_TIMEOUT_MIN`. Default is 60 minutes.
|
|
|
|
|
* Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable `SEGMENT_DOWNLOAD_TIMEOUT_MINS`. Default is 60 minutes.
|
|
|
|
|
|
|
|
|
|
Refer [here](https://github.com/actions/cache/blob/v2/README.md) for previous versions
|
|
|
|
|
|
|
|
|
@@ -34,20 +34,21 @@ If you are using this inside a container, a POSIX-compliant `tar` needs to be in
|
|
|
|
|
|
|
|
|
|
* `path` - A list of files, directories, and wildcard patterns to cache and restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob) for supported patterns.
|
|
|
|
|
* `key` - An explicit key for restoring and saving the cache
|
|
|
|
|
* `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key. Note
|
|
|
|
|
`cache-hit` returns false in this case.
|
|
|
|
|
* `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key.
|
|
|
|
|
|
|
|
|
|
#### Environment Variables
|
|
|
|
|
* `SEGMENT_DOWNLOAD_TIMEOUT_MIN` - Segment download timeout (in minutes, default `60`) to abort download of the segment if not completed in the defined number of minutes. [Read more](#cache-segment-restore-timeout)
|
|
|
|
|
* `SEGMENT_DOWNLOAD_TIMEOUT_MINS` - Segment download timeout (in minutes, default `60`) to abort download of the segment if not completed in the defined number of minutes. [Read more](#cache-segment-restore-timeout)
|
|
|
|
|
|
|
|
|
|
### Outputs
|
|
|
|
|
|
|
|
|
|
* `cache-hit` - A boolean value to indicate an exact match was found for the key
|
|
|
|
|
* `cache-hit` - A boolean value to indicate an exact match was found for the key.
|
|
|
|
|
|
|
|
|
|
> See [Skipping steps based on cache-hit](#Skipping-steps-based-on-cache-hit) for info on using this output
|
|
|
|
|
> Note: `cache-hit` will be set to `true` only when cache hit occurs for the exact `key` match. For a partial key match via `restore-keys` or a cache miss, it will be set to `false`.
|
|
|
|
|
|
|
|
|
|
See [Skipping steps based on cache-hit](#skipping-steps-based-on-cache-hit) for info on using this output
|
|
|
|
|
|
|
|
|
|
### Cache scopes
|
|
|
|
|
The cache is scoped to the key and branch. The default branch cache is available to other branches.
|
|
|
|
|
The cache is scoped to the key, [version](#cache-version) and branch. The default branch cache is available to other branches.
|
|
|
|
|
|
|
|
|
|
See [Matching a cache key](https://help.github.com/en/actions/configuring-and-managing-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key) for more info.
|
|
|
|
|
|
|
|
|
@@ -117,7 +118,7 @@ See [Examples](examples.md) for a list of `actions/cache` implementations for us
|
|
|
|
|
|
|
|
|
|
A cache key can include any of the contexts, functions, literals, and operators supported by GitHub Actions.
|
|
|
|
|
|
|
|
|
|
For example, using the [`hashFiles`](https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#hashfiles) function allows you to create a new cache when dependencies change.
|
|
|
|
|
For example, using the [`hashFiles`](https://docs.github.com/en/actions/learn-github-actions/expressions#hashfiles) function allows you to create a new cache when dependencies change.
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
- uses: actions/cache@v3
|
|
|
|
@@ -152,7 +153,7 @@ A repository can have up to 10GB of caches. Once the 10GB limit is reached, olde
|
|
|
|
|
|
|
|
|
|
## Skipping steps based on cache-hit
|
|
|
|
|
|
|
|
|
|
Using the `cache-hit` output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key.
|
|
|
|
|
Using the `cache-hit` output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key. It is recommended to install the missing/updated dependencies in case of a partial key match when the key is dependent on the `hash` of the package file.
|
|
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
```yaml
|
|
|
|
@@ -174,9 +175,13 @@ steps:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Cache Version
|
|
|
|
|
Cache version is unique for a combination of compression tool used for compression of cache (Gzip, Zstd, etc based on runner OS) and the path of directories being cached. If two caches have different versions, they are identified as unique cache entries. This also means that a cache created on `windows-latest` runner can't be restored on `ubuntu-latest` as cache `Version`s are different.
|
|
|
|
|
Cache version is a hash [generated](https://github.com/actions/toolkit/blob/500d0b42fee2552ae9eeb5933091fe2fbf14e72d/packages/cache/src/internal/cacheHttpClient.ts#L73-L90) for a combination of compression tool used (Gzip, Zstd, etc. based on the runner OS) and the `path` of directories being cached. If two caches have different versions, they are identified as unique caches while matching. This for example, means that a cache created on `windows-latest` runner can't be restored on `ubuntu-latest` as cache `Version`s are different.
|
|
|
|
|
|
|
|
|
|
Example: Below example will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different.
|
|
|
|
|
> Pro tip: [List caches](https://docs.github.com/en/rest/actions/cache#list-github-actions-caches-for-a-repository) API can be used to get the version of a cache. This can be helpful to troubleshoot cache miss due to version.
|
|
|
|
|
|
|
|
|
|
<details>
|
|
|
|
|
<summary>Example</summary>
|
|
|
|
|
The workflow will create 3 unique caches with same keys. Ubuntu and windows runners will use different compression technique and hence create two different caches. And `build-linux` will create two different caches as the `paths` are different.
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
jobs:
|
|
|
|
@@ -223,6 +228,44 @@ jobs:
|
|
|
|
|
if: steps.cache-primes.outputs.cache-hit != 'true'
|
|
|
|
|
run: ./generate-primes -d prime-numbers
|
|
|
|
|
```
|
|
|
|
|
</details>
|
|
|
|
|
|
|
|
|
|
## Deleting caches
|
|
|
|
|
We can not re-use caches from pull request branches in other branches like main, such caches can eat up the storage quota and hence causing thrashing on more useful branches like main. In order to resolve this issue, we can use [gh-actions-cache cli](https://github.com/actions/gh-actions-cache/) to delete caches. This workflow uses `gh-actions-cache` to delete all the caches created by all the pull requests.
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
name: cleanup-caches
|
|
|
|
|
on:
|
|
|
|
|
workflow_dispatch
|
|
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
|
release:
|
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
steps:
|
|
|
|
|
- name: Check out code
|
|
|
|
|
uses: actions/checkout@v3
|
|
|
|
|
|
|
|
|
|
- name: Cleanup
|
|
|
|
|
run: |
|
|
|
|
|
gh extension install actions/gh-actions-cache
|
|
|
|
|
|
|
|
|
|
REPO=${{ github.repository }}
|
|
|
|
|
|
|
|
|
|
echo "Fetching list of cache key"
|
|
|
|
|
## This will extract out all the cache keys for pull requests
|
|
|
|
|
cacheKeysForPR=$(gh actions-cache list -R $REPO | grep "refs/pull" | cut -d $'\t' -f 1 )
|
|
|
|
|
|
|
|
|
|
## Setting this to not fail the workflow while deleting duplicate cache keys. We can have same cache key for multiple branches based on the cache key generation.
|
|
|
|
|
set +e
|
|
|
|
|
echo "Deleting caches..."
|
|
|
|
|
for cacheKey in $cacheKeysForPR
|
|
|
|
|
do
|
|
|
|
|
gh actions-cache delete $cacheKey -R $REPO --confirm
|
|
|
|
|
done
|
|
|
|
|
echo "Done"
|
|
|
|
|
env:
|
|
|
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Known practices and workarounds
|
|
|
|
|
Following are some of the known practices/workarounds which community has used to fulfill specific requirements. You may choose to use them if suits your use case. Note these are not necessarily the only or the recommended solution.
|
|
|
|
|