From 543bcff756039a572e880e3d06d3ced569662d05 Mon Sep 17 00:00:00 2001 From: Mario-SO Date: Thu, 19 Dec 2024 14:05:57 +0100 Subject: [PATCH] cleanup image caches --- .github/workflows/clean_caches.yml | 35 ++++++++++++++++++++++++++++++ docker-compose.staging.yml | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/clean_caches.yml diff --git a/.github/workflows/clean_caches.yml b/.github/workflows/clean_caches.yml new file mode 100644 index 000000000..336bbff43 --- /dev/null +++ b/.github/workflows/clean_caches.yml @@ -0,0 +1,35 @@ +name: cleanup caches +on: + pull_request: + types: + - closed + workflow_dispatch: # Adding manual trigger option + +jobs: + cleanup: + runs-on: ubuntu-latest + steps: + - name: Cleanup all 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" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} diff --git a/docker-compose.staging.yml b/docker-compose.staging.yml index de072f510..23e3a755b 100644 --- a/docker-compose.staging.yml +++ b/docker-compose.staging.yml @@ -196,8 +196,8 @@ services: volumes: - mongodb_data:/data/db environment: - MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_DATABASE: streameth-staging + MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD_FILE: /run/secrets/db-password healthcheck: test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/test --quiet