Skip to content

Image CI Cache Cleaner #95

Image CI Cache Cleaner

Image CI Cache Cleaner #95

name: Image CI Cache Cleaner
# Any change in triggers needs to be reflected in the concurrency group.
on:
workflow_dispatch:
schedule:
# Run the GC every Monday at 6am
- cron: "0 6 * * 1"
permissions: read-all
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.after }}
cancel-in-progress: true
jobs:
cache-cleaner:
name: Clean Image Cache
runs-on: ubuntu-latest
permissions:
# `actions:write` permission is required to delete caches
# See also: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-a-github-actions-cache-for-a-repository-using-a-cache-id
actions: write
contents: read
strategy:
matrix:
include:
- name: cilium
- name: operator-aws
- name: operator-azure
- name: operator-alibabacloud
- name: operator-generic
- name: hubble-relay
- name: clustermesh-apiserver
- name: kvstoremesh
- name: docker-plugin
steps:
# Fetch the source code so that we can get the right cache key
- name: Checkout Source Code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
persist-credentials: false
# Load Golang cache build from GitHub
- name: Load ${{ matrix.name }} Golang cache build from GitHub
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
id: cache
with:
path: /tmp/.cache/${{ matrix.name }}
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ matrix.name }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ matrix.name }}-
${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-
${{ runner.os }}-go-
- name: Create ${{ matrix.name }} cache directory
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
shell: bash
run: |
mkdir -p /tmp/.cache/${{ matrix.name }}
- name: Clean ${{ matrix.name }} Golang cache from GitHub
shell: bash
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
set +e
gh actions-cache delete ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ matrix.name }}-${{ github.sha }} -R $REPO -B main --confirm || true
gh actions-cache delete ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ matrix.name }}- -R $REPO -B main --confirm || true
gh actions-cache delete ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}- -R $REPO -B main --confirm || true
gh actions-cache delete ${{ runner.os }}-go- -R $REPO -B main --confirm || true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}