From 7d39edce2a7fca8c26776b381d94c4e9613c3f2b Mon Sep 17 00:00:00 2001 From: Mario-SO Date: Mon, 30 Dec 2024 11:37:02 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20commented=20undesired=20workflow?= =?UTF-8?q?s=20for=20now?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/clean_caches.yml | 62 +++++++++++++++++++----------- .github/workflows/playwright.yml | 12 +++--- .github/workflows/prettier.yml | 10 ++--- 3 files changed, 51 insertions(+), 33 deletions(-) diff --git a/.github/workflows/clean_caches.yml b/.github/workflows/clean_caches.yml index c41b81774..41508acb7 100644 --- a/.github/workflows/clean_caches.yml +++ b/.github/workflows/clean_caches.yml @@ -1,32 +1,50 @@ -name: cleanup caches +name: Cleanup Caches + on: - workflow_dispatch: # Adding manual trigger option + workflow_dispatch: # Keep manual trigger + workflow_run: + workflows: ['Build server', 'Playwright Tests', 'Prettier'] # Add workflows that generate caches + types: + - completed jobs: cleanup: runs-on: ubuntu-latest steps: - - name: Cleanup all caches + - name: Cleanup old caches run: | - if [ "${{ github.event_name }}" == "pull_request" ]; then - # For pull request events, clean specific PR branch caches - BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge" - echo "Cleaning caches for PR branch: $BRANCH" - cacheKeysForPR=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id') - else - # For manual dispatch, clean all caches - echo "Cleaning all repository caches" - cacheKeysForPR=$(gh cache list --limit 100 --json id --jq '.[].id') - fi - - ## Setting this to not fail the workflow while deleting cache keys. - set +e - echo "Deleting caches..." - for cacheKey in $cacheKeysForPR - do - gh cache delete $cacheKey --confirm - done - echo "Done" + # Get the list of cache keys sorted by creation date + function cleanup_caches() { + local pattern=$1 + echo "Cleaning up caches matching pattern: $pattern" + + # Get all cache keys for the pattern, sorted by date (newest first) + cacheKeys=$(gh cache list --limit 100 --json key,createdAt --jq '.[] | select(.key | contains("'$pattern'")) | [.key, .createdAt] | @tsv' | sort -k2,2r) + + # Keep track of how many we've seen for each type + declare -A seen_count + + while IFS=$'\t' read -r key date; do + # Extract the base pattern (everything before the hash) + base_pattern=$(echo "$key" | sed -E 's/-[a-f0-9]{40}$//') + + # Increment the count for this pattern + seen_count[$base_pattern]=$((${seen_count[$base_pattern]:-0} + 1)) + + # If we've seen more than 2 caches of this type, delete it + if [ "${seen_count[$base_pattern]}" -gt 2 ]; then + echo "Deleting old cache: $key" + gh cache delete "$key" --confirm + else + echo "Keeping recent cache: $key" + fi + done <<< "$cacheKeys" + } + + # Clean up different types of caches + cleanup_caches "Linux-buildx" + cleanup_caches "playwright" + cleanup_caches "yarn" env: GH_TOKEN: ${{ secrets.TOKEN }} GH_REPO: ${{ github.repository }} diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index e06a33428..1ea58f852 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -1,10 +1,10 @@ name: Playwright Tests -on: - push: - branches: [develop, main] - pull_request: - branches: [develop, main] +# on: +# push: +# branches: [develop, main] +# pull_request: +# branches: [develop, main] # Prevent multiple runs of the same workflow on the same ref concurrency: @@ -40,7 +40,7 @@ jobs: run: yarn playwright install --with-deps - name: Build application - run: yarn build + run: yarn build:app env: NEXT_PUBLIC_SPACE_STORAGE_URL: ${{ secrets.NEXT_PUBLIC_SPACE_STORAGE_URL }} NEXT_PUBLIC_STUDIO_API_KEY: ${{ secrets.NEXT_PUBLIC_STUDIO_API_KEY }} diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml index ed9cc5a36..9b22ce9a5 100644 --- a/.github/workflows/prettier.yml +++ b/.github/workflows/prettier.yml @@ -1,10 +1,10 @@ name: Prettier -on: - pull_request: - branches: [main, develop] - push: - branches: [main, develop] +# on: +# pull_request: +# branches: [main, develop] +# push: +# branches: [main, develop] # Prevent multiple runs of the same workflow on the same ref concurrency: