diff --git a/.github/workflows/cleanup-cache-at-pr-closing.yml b/.github/workflows/cleanup-cache-at-pr-closing.yml new file mode 100644 index 000000000..284702e76 --- /dev/null +++ b/.github/workflows/cleanup-cache-at-pr-closing.yml @@ -0,0 +1,42 @@ +############################################################################### +# A Github repo has max 10 GB of cache. +# https://github.blog/changelog/2021-11-23-github-actions-cache-size-is-now-increased-to-10gb-per-repository/ +# +# To avoid "cache thrashing" by their cache eviction policy it is recommended +# to apply a cache cleanup workflow at PR closing to dele cache leftovers of +# the current branch: +# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries +############################################################################### + +name: ocelot.social cache cleanup on pr closing + +on: + pull_request: + types: + - closed + +jobs: + clean-branch-cache: + name: Cleanup branch cache + runs-on: ubuntu-latest + continue-on-error: true + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Cleanup + run: | + gh extension install actions/gh-actions-cache + REPO=${{ github.repository }} + BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge" + echo "Fetching list of cache key" + cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 ) + set +e + echo "Deleting caches..." + for cacheKey in $cacheKeysForPR + do + gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm + done + echo "Done" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/test-backend.yml b/.github/workflows/test-backend.yml index af53e1fbc..03e517826 100644 --- a/.github/workflows/test-backend.yml +++ b/.github/workflows/test-backend.yml @@ -1,7 +1,7 @@ name: ocelot.social backend test CI -on: [push] +on: push jobs: files-changed: @@ -10,7 +10,6 @@ jobs: outputs: backend: ${{ steps.changes.outputs.backend }} docker: ${{ steps.changes.outputs.docker }} - pr-number: ${{ steps.pr.outputs.number }} steps: - uses: actions/checkout@v3.3.0 @@ -22,10 +21,6 @@ jobs: filters: .github/file-filters.yml list-files: shell - - name: Get pr number - id: pr - uses: 8BitJonny/gh-get-current-pr@2.2.0 - build_test_neo4j: name: Docker Build Test - Neo4J if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.docker == 'true' @@ -45,7 +40,7 @@ jobs: uses: actions/cache/save@v3.3.1 with: path: /tmp/neo4j.tar - key: backend-neo4j-cache-pr${{ needs.files-changed.outputs.pr-number }} + key: ${{ github.run_id }}-backend-neo4j-cache build_test_backend: name: Docker Build Test - Backend @@ -66,7 +61,7 @@ jobs: uses: actions/cache/save@v3.3.1 with: path: /tmp/backend.tar - key: backend-cache-pr${{ needs.files-changed.outputs.pr-number }} + key: ${{ github.run_id }}-backend-cache lint_backend: name: Lint Backend @@ -95,14 +90,14 @@ jobs: uses: actions/cache/restore@v3.3.1 with: path: /tmp/neo4j.tar - key: backend-neo4j-cache-pr${{ needs.files-changed.outputs.pr-number }} + key: ${{ github.run_id }}-backend-neo4j-cache fail-on-cache-miss: true - name: Restore Backend cache uses: actions/cache/restore@v3.3.1 with: path: /tmp/backend.tar - key: backend-cache-pr${{ needs.files-changed.outputs.pr-number }} + key: ${{ github.run_id }}-backend-cache fail-on-cache-miss: true - name: Load Docker Images @@ -129,17 +124,17 @@ jobs: cleanup: name: Cleanup - if: always() + if: ${{ needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.docker == 'true' }} needs: [files-changed, unit_test_backend] runs-on: ubuntu-latest + continue-on-error: true steps: - name: Delete cache env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh extension install actions/gh-actions-cache - set +e - KEY="backend-neo4j-cache-pr${{ needs.files-changed.outputs.pr-number }}" + KEY="${{ github.run_id }}-backend-neo4j-cache" gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm - KEY="backend-cache-pr${{ needs.files-changed.outputs.pr-number }}" + KEY="${{ github.run_id }}-backend-cache" gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index e37b9fed0..02d65ba9e 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -1,12 +1,11 @@ name: ocelot.social end-to-end test CI + on: push jobs: docker_preparation: name: Fullstack test preparation runs-on: ubuntu-latest - outputs: - pr-number: ${{ steps.pr.outputs.number }} steps: - name: Checkout code uses: actions/checkout@v3 @@ -34,10 +33,6 @@ jobs: yarn build cd .. yarn install - - - name: Get pr number - id: pr - uses: 8BitJonny/gh-get-current-pr@2.2.0 - name: Cache docker images id: cache @@ -48,7 +43,7 @@ jobs: /home/runner/.cache/Cypress /home/runner/work/Ocelot-Social/Ocelot-Social /tmp/images/ - key: e2e-preparation-cache-pr${{ steps.pr.outputs.number }} + key: ${{ github.run_id }}-e2e-preparation-cache fullstack_tests: name: Fullstack tests @@ -71,7 +66,7 @@ jobs: /home/runner/.cache/Cypress /home/runner/work/Ocelot-Social/Ocelot-Social /tmp/images/ - key: e2e-preparation-cache-pr${{ needs.docker_preparation.outputs.pr-number }} + key: ${{ github.run_id }}-e2e-preparation-cache fail-on-cache-miss: true - name: Boot up test system | docker-compose @@ -104,15 +99,14 @@ jobs: cleanup: name: Cleanup - if: always() needs: [docker_preparation, fullstack_tests] runs-on: ubuntu-latest + continue-on-error: true steps: - name: Delete cache env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh extension install actions/gh-actions-cache - set +e - KEY="e2e-preparation-cache-pr${{ needs.docker_preparation.outputs.pr-number }}" + KEY="${{ github.run_id }}-e2e-preparation-cache" gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm \ No newline at end of file diff --git a/.github/workflows/test-webapp.yml b/.github/workflows/test-webapp.yml index 421ce5187..2b1e144a5 100644 --- a/.github/workflows/test-webapp.yml +++ b/.github/workflows/test-webapp.yml @@ -1,7 +1,7 @@ name: ocelot.social webapp test CI -on: [push] +on: push jobs: files-changed: @@ -9,7 +9,6 @@ jobs: runs-on: ubuntu-latest outputs: docker: ${{ steps.changes.outputs.docker }} - pr-number: ${{ steps.pr.outputs.number }} webapp: ${{ steps.changes.outputs.webapp }} steps: - uses: actions/checkout@v3.3.0 @@ -22,10 +21,6 @@ jobs: filters: .github/file-filters.yml list-files: shell - - name: Get pr number - id: pr - uses: 8BitJonny/gh-get-current-pr@2.2.0 - prepare: name: Prepare if: needs.files-changed.outputs.webapp == 'true' @@ -58,7 +53,7 @@ jobs: uses: actions/cache/save@v3.3.1 with: path: /tmp/webapp.tar - key: webapp-cache-pr${{ needs.files-changed.outputs.pr-number }} + key: ${{ github.run_id }}-webapp-cache lint_webapp: name: Lint Webapp @@ -87,7 +82,7 @@ jobs: uses: actions/cache/restore@v3.3.1 with: path: /tmp/webapp.tar - key: webapp-cache-pr${{ needs.files-changed.outputs.pr-number }} + key: ${{ github.run_id }}-webapp-cache - name: Load Docker Image run: docker load < /tmp/webapp.tar @@ -105,16 +100,16 @@ jobs: cleanup: name: Cleanup - if: always() + if: ${{ needs.files-changed.outputs.docker == 'true' || needs.files-changed.outputs.webapp == 'true' }} needs: [files-changed, unit_test_webapp] runs-on: ubuntu-latest + continue-on-error: true steps: - name: Delete cache env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh extension install actions/gh-actions-cache - set +e - KEY="webapp-cache-pr${{ needs.files-changed.outputs.pr-number }}" + KEY="${{ github.run_id }}-webapp-cache" gh actions-cache delete $KEY -R Ocelot-Social-Community/Ocelot-Social --confirm