From d1796596fa337369fdbb6d12f7715fd28ef403bf Mon Sep 17 00:00:00 2001 From: harmj0y Date: Sat, 21 Jun 2025 11:42:07 +0100 Subject: [PATCH] simplified cache cleanup simplified cache cleanup --- .github/workflows/docker-build-noseyparker.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-build-noseyparker.yml b/.github/workflows/docker-build-noseyparker.yml index a621d41..42723cb 100644 --- a/.github/workflows/docker-build-noseyparker.yml +++ b/.github/workflows/docker-build-noseyparker.yml @@ -35,6 +35,7 @@ jobs: permissions: contents: read packages: write + actions: write # Added for cache cleanup steps: - name: Checkout repository @@ -48,6 +49,13 @@ jobs: image=moby/buildkit:latest network=host + # Create cargo directories to avoid cache warnings + - name: Create Cargo directories + run: | + mkdir -p ~/.cargo/registry/index/ + mkdir -p ~/.cargo/registry/cache/ + mkdir -p ~/.cargo/git/db/ + # Pre-warm Rust registry cache (architecture-specific) - name: Cache Rust registry uses: actions/cache@v4 @@ -108,13 +116,13 @@ jobs: # Test that the image runs and shows version docker run --rm ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/noseyparker-scanner:${{ steps.meta.outputs.version }} --help || true - # Clean up cache on successful build to prevent cache bloat - - name: Cleanup old cache entries + # Simple cache cleanup - keep only the 2 most recent caches + - name: Simple cache cleanup if: success() run: | - # Clean up old GitHub Actions cache entries for this scope gh extension install actions/gh-actions-cache || true - gh actions-cache delete "noseyparker-scanner-${{ matrix.arch }}-${{ github.ref_name }}-*" --confirm || true + # Keep only the 2 most recent caches for this scope + gh actions-cache list --key "noseyparker-scanner-${{ matrix.arch }}-${{ github.ref_name }}" --sort created-at --order desc | tail -n +3 | cut -f1 | xargs -I {} gh actions-cache delete {} --confirm || true env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} continue-on-error: true