Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

ci: reduce buildx cache pressure and clean up PR caches (#1016)

Johannes Grumböck1bcf2c8adc12
diff --git a/.github/workflows/cache-cleanup-on-pr-close.yml b/.github/workflows/cache-cleanup-on-pr-close.yml
new file mode 100644
index 00000000..7f35dea1
--- /dev/null
+++ b/.github/workflows/cache-cleanup-on-pr-close.yml
@@ -0,0 +1,41 @@
+name: Cleanup PR caches
+
+on:
+ pull_request_target:
+ types: [closed]
+
+jobs:
+ cleanup:
+ runs-on: ubuntu-latest
+ permissions:
+ actions: write
+ contents: read
+
+ steps:
+ - name: Delete caches for closed PR
+ env:
+ GH_TOKEN: ${{ github.token }}
+ PR_NUMBER: ${{ github.event.pull_request.number }}
+ REPO: ${{ github.repository }}
+ run: |
+ set -euo pipefail
+
+ ref="refs/pull/${PR_NUMBER}/merge"
+
+ cache_ids=$(gh api \
+ -H "Accept: application/vnd.github+json" \
+ "/repos/${REPO}/actions/caches?per_page=100" \
+ --jq ".actions_caches[] | select(.ref == \"${ref}\") | .id")
+
+ if [ -z "${cache_ids}" ]; then
+ echo "No caches found for ${ref}"
+ exit 0
+ fi
+
+ for id in $cache_ids; do
+ echo "Deleting cache id ${id} for ${ref}"
+ gh api \
+ --method DELETE \
+ -H "Accept: application/vnd.github+json" \
+ "/repos/${REPO}/actions/caches/${id}"
+ done
\ No newline at end of file
diff --git a/.github/workflows/docker-publish-on-pr.yml b/.github/workflows/docker-publish-on-pr.yml
index bc10f37d..b5b89ce6 100644
--- a/.github/workflows/docker-publish-on-pr.yml
+++ b/.github/workflows/docker-publish-on-pr.yml
@@ -99,7 +99,7 @@ jobs:
build-args: |
MINISTACK_VERSION=pr-${{ github.event.pull_request.number }}-${{ steps.short_sha.outputs.short_sha }}
cache-from: type=gha,scope=regular-pr
- cache-to: type=gha,mode=max,scope=regular-pr
+ cache-to: type=gha,mode=min,scope=regular-pr
# ── Full (Debian/glibc) image — DuckDB-backed Athena, psycopg2, pymysql.
# Only built when the PR carries the `full-preview` label (opt-in to keep
@@ -130,7 +130,7 @@ jobs:
build-args: |
MINISTACK_VERSION=pr-${{ github.event.pull_request.number }}-${{ steps.short_sha.outputs.short_sha }}
cache-from: type=gha,scope=full-pr
- cache-to: type=gha,mode=max,scope=full-pr
+ cache-to: type=gha,mode=min,scope=full-pr
- name: Comment on PR with Docker image info
if: steps.guard.outputs.skip != 'true'