Skip to content

Commit

Permalink
Merge pull request #5467 from twz123/actions-cache-optimizations
Browse files Browse the repository at this point in the history
GitHub Actions cache optimizations
  • Loading branch information
twz123 authored Feb 6, 2025
2 parents 8741719 + e374cbb commit 17781c6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go.mod text eol=lf
go.sum text eol=lf
6 changes: 3 additions & 3 deletions .github/workflows/build-k0s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ jobs:
- name: "Cache :: GOMODCACHE"
uses: actions/cache@v4
with:
key: build-k0s-${{ inputs.target-os }}-${{ inputs.target-arch }}-gomodcache-${{ hashFiles('go.sum') }}
path: |
build/cache/go/mod
key: build-k0s-gomodcache-${{ hashFiles('go.sum') }}
path: build/cache/go/mod
enableCrossOsArchive: true

- name: "Build :: k0s"
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ jobs:
uses: actions/cache@v4
with:
key: unittests-k0s-gomodcache-${{ hashFiles('go.sum') }}
path: |
build/cache/go/mod
path: build/cache/go/mod
enableCrossOsArchive: true

- name: Run unit tests
run: make check-unit $UNITTEST_EXTRA_ARGS
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/pr-closed.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Pull request closed
on:
pull_request:
types:
- closed

jobs:
# Based on https://github.com/actions/cache/blob/v4.2.0/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy
cleanup-actions-caches:
name: Cleanup GitHub Actions caches
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

steps:
- name: Cleanup
env:
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
GH_REPO: "${{ github.repository }}"
BRANCH: "refs/pull/${{ github.event.pull_request.number }}/merge"
run: |
set -euo pipefail
gh api -X GET /repos/{owner}/{repo}/actions/caches -f ref="$BRANCH" --paginate -q '.actions_caches[] | "\(.id) \(.key)"' | {
fail=0
while read -r id key; do
echo Deleting cache with ID $id: $key
gh api -X DELETE /repos/{owner}/{repo}/actions/caches/"$id" || fail=1
done
[ $fail -eq 0 ]
}

0 comments on commit 17781c6

Please sign in to comment.