Skip to content
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

cache clean workflow #598

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Changes from 34 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c28dc1a
Add cache clean w/f outline
alan-forbes-cp Nov 21, 2024
932a4e7
add pull request
alan-forbes-cp Nov 21, 2024
866db0e
first gh cache command
alan-forbes-cp Nov 21, 2024
3f26260
add action install
alan-forbes-cp Nov 21, 2024
7a2bd82
Add GH token
alan-forbes-cp Nov 21, 2024
0445626
add subcommand help output
alan-forbes-cp Nov 21, 2024
26a26fe
add grep to find latest caches
alan-forbes-cp Nov 21, 2024
323bab1
restore checkout
alan-forbes-cp Nov 21, 2024
adf476f
update logic to identify cache for deletion
alan-forbes-cp Nov 22, 2024
ce02898
Add echo for cache deletions
alan-forbes-cp Nov 22, 2024
b1f0b78
Fix delete list
alan-forbes-cp Nov 22, 2024
19f0722
Tidy delete list
alan-forbes-cp Nov 22, 2024
8539f05
Fix ordering
alan-forbes-cp Nov 22, 2024
84680ee
add before / after logging
alan-forbes-cp Nov 22, 2024
fcc3c2e
add dryrun
alan-forbes-cp Nov 22, 2024
65e19ce
add push
alan-forbes-cp Nov 22, 2024
a6494c9
remove push
alan-forbes-cp Nov 22, 2024
efe62eb
add input to pr run
alan-forbes-cp Nov 22, 2024
f4a1727
add execution on dryrun
alan-forbes-cp Nov 22, 2024
45f8ab2
fix dry run logging
alan-forbes-cp Nov 22, 2024
3accd0d
swap dryrun logic
alan-forbes-cp Nov 22, 2024
964af78
update logging and schedule
alan-forbes-cp Nov 22, 2024
bb68bf0
set perms explicitly
alan-forbes-cp Nov 22, 2024
99e8166
set job actions perms
alan-forbes-cp Nov 22, 2024
89782ad
add test deletion using perms
alan-forbes-cp Nov 22, 2024
b440c28
set perms to write
alan-forbes-cp Nov 22, 2024
99ca971
Update TODOS and add args VARS for gh commnds
alan-forbes-cp Nov 22, 2024
b6d02fa
align commants
alan-forbes-cp Nov 22, 2024
5ab5417
define cache prefix list
alan-forbes-cp Nov 22, 2024
3e46044
update comments remove checkout
alan-forbes-cp Nov 22, 2024
a488cec
add sparse checkout
alan-forbes-cp Nov 22, 2024
4db6fd3
change asc to desc - fix order
alan-forbes-cp Nov 22, 2024
2dc230a
set prefix list for main repo
alan-forbes-cp Nov 22, 2024
b9369b0
Tidy comments and formatting
alan-forbes-cp Nov 25, 2024
90f1f72
Review updates and explicitly disable caching for CodeQL
alan-forbes-cp Nov 26, 2024
d85dce6
Fix cron setting
alan-forbes-cp Nov 26, 2024
6063c58
Remove echo from deletion for "live"
alan-forbes-cp Nov 27, 2024
ca8d366
Add conditional for repo and schedule event
alan-forbes-cp Nov 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/cache_clean.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Cache clean workflow

name: Cache clean

on:
# TODO restore schedule
#schedule:
# # Run Mon-Sun at 11pm
# - cron: '00 23 * * 1-7'
alan-forbes-cp marked this conversation as resolved.
Show resolved Hide resolved
workflow_dispatch:
inputs:
dryrun:
required: true
type: boolean
default: true
# TODO delete pull_request
pull_request:
alan-forbes-cp marked this conversation as resolved.
Show resolved Hide resolved

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
clean_cache:
name: Cache clean
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Checkout repo
uses: actions/[email protected]
with:
sparse-checkout: .github
- name: Cache clean
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Define unique cache prefixes for deletion
CACHE_PREFIX_LIST: "codeql-trap- sccache-sccache-"
run: |
# Install gh cache manager extension
gh extension install actions/gh-actions-cache
# ... for usage, flags and examples: $ gh actions-cache [ --help | list --help | delete --help ]
# Define args for gh cache commands
GH_LIST_ARGS="-B main -L 100 --order desc --sort created-at"
GH_DELETE_ARGS="-B main --confirm"
alan-forbes-cp marked this conversation as resolved.
Show resolved Hide resolved
echo CACHE PREFIXES FOR CLEANING ... $CACHE_PREFIX_LIST
# Generate current cache list for main, newest first (note: 100 cache entries is gh maximum)
echo CACHE LIST BEFORE ...
gh actions-cache list $GH_LIST_ARGS | tee CACHE_LIST
# Generate corresponding list of cache keys for deletion - retain only the newest key for each prefix
DELETE_LIST=$(for CACHE_PREFIX in $CACHE_PREFIX_LIST ; do grep -E -o "^${CACHE_PREFIX}[^[:space:]]+" CACHE_LIST | sed '1d' ; done)
echo DELETIONS ...
# Delete caches via keys in DELETE_LIST if not dryrun
# TODO remove non-dryrun echo for live use
for KEY in $DELETE_LIST ; do [ "${{ inputs.dryrun }}" = "true" ] && echo \[DRY RUN\] DELETING $KEY || echo gh actions-cache delete $GH_DELETE_ARGS $KEY ; done
alan-forbes-cp marked this conversation as resolved.
Show resolved Hide resolved
# Generate post-clean list
echo CACHE LIST AFTER ...
gh actions-cache list $GH_LIST_ARGS