-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add cache warm and cache evict workflows #2944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
032f133
Add cache warm and cache evict workflows
cprecioso c422c26
Add concurrency groups
cprecioso 25c0660
Merge branch 'main' into cprecioso/2919-ensure-warm-cache-for-ci
cprecioso 16793f4
WIP
cprecioso e1bba2a
Remove dry-run
cprecioso 71b190f
Remove existing schedule
cprecioso 78aedab
Comments
cprecioso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: Evict caches for merged PRs | ||
|
||
# Caches for merged PRs stay around until we bump against our cache limit. | ||
# They are also not shareable between branches. Therefore, once a PR is | ||
# merged, the cache for that branch is immediately not needed anymore, and we | ||
# can remove it. If we remove these caches, we can save space and be more sure | ||
# that the remaining caches are actually useful, and not at danger of being | ||
# evicted. | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
|
||
concurrency: | ||
group: "cache-evict" | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
evict-cache: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Evict caches | ||
shell: bash | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
|
||
# This script lists all caches for the repository, lists all remote refs | ||
# for the repository, and then finds the caches that are not present in | ||
# the remote refs. It then deletes those caches. | ||
# | ||
# For that, it uses the `gh` CLI to list and delete caches, and `git` to | ||
# list remote refs. It also uses `jq` to manipulate the data as JSON. | ||
# (It's surprisingly difficult to find a shell command to check if a | ||
# string is inside a given array, that's why we use `jq`.) | ||
run: | | ||
( | ||
# Input 0: List all caches for the repository | ||
gh cache list --limit 100 --json key,ref | ||
# Input 1: List all remote refs for the repository, do some string | ||
# manipulation to get the ref names (second column) as a JSON array | ||
git ls-remote "https://github.com/$GITHUB_REPOSITORY.git" | | ||
awk '{print $2}' | | ||
jq --raw-input --compact-output '.' | | ||
jq --slurp '.' | ||
) | | ||
# Find cache refs not present in the remote refs, and extract their keys | ||
infomiho marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
jq --slurp --raw-output \ | ||
'.[0] as $caches | .[1] as $remote_refs | $caches.[] | select([.ref] | inside($remote_refs) | not) | .key' | | ||
while read -r key; do | ||
# Delete those cache keys | ||
gh cache delete "$key" || | ||
echo "::warning::Failed to delete cache key $key" | ||
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Keeps build cache warm | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
# GitHub evicts unused caches after 7 days, so we run this every 6 days | ||
- cron: "0 0 */6 * *" | ||
|
||
concurrency: | ||
group: "cache-warm" | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
warm-cache-build: | ||
uses: ./.github/workflows/waspc-build.yaml | ||
|
||
warm-cache-ci: | ||
uses: ./.github/workflows/waspc-ci.yaml | ||
infomiho marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.