Compare commits

...

7 Commits

Author SHA1 Message Date
Deepak Dahiya
a90fbffdad minor 2022-11-14 05:55:57 +00:00
Deepak Dahiya
b65f98495c minor 2022-11-13 21:44:53 +00:00
Deepak Dahiya
e1165c0dec Readmee update for deleting caches 2022-11-13 21:40:58 +00:00
Vipul
db8d946d18 Merge pull request #979 from asaf400/patch-2
Update hashFiles documentation reference
2022-11-13 13:54:22 +05:30
Asaf Levy
0e93819da5 Update hashFiles documentation reference
Update hashFiles documentation reference Link to the valid doc
https://docs.github.com/en/actions/learn-github-actions/expressions#hashfiles
2022-11-09 21:38:02 +02:00
Bishal Prasad
9a6a4f6079 Add more details to version section in readme (#971)
* Add more details to version section in readme

* Update README.md

Co-authored-by: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com>

* Use ubuntu/squid instead of datadog/squid

Co-authored-by: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com>
2022-11-07 15:42:42 +05:30
Bishal Prasad
d0af8a3ecc Change datadog/squid to Ubuntu/squid in CI check (#976) 2022-11-07 13:22:00 +05:30
2 changed files with 48 additions and 6 deletions

View File

@@ -99,7 +99,7 @@ jobs:
options: --dns 127.0.0.1
services:
squid-proxy:
image: datadog/squid:latest
image: ubuntu/squid:latest
ports:
- 3128:3128
env:
@@ -122,7 +122,7 @@ jobs:
options: --dns 127.0.0.1
services:
squid-proxy:
image: datadog/squid:latest
image: ubuntu/squid:latest
ports:
- 3128:3128
env:

View File

@@ -48,7 +48,7 @@ If you are using this inside a container, a POSIX-compliant `tar` needs to be in
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.
@@ -118,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
@@ -175,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:
@@ -224,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.