diff --git a/.github/workflows/cleanup_cache.yml b/.github/workflows/cleanup_cache.yml new file mode 100644 index 00000000..620fb8ac --- /dev/null +++ b/.github/workflows/cleanup_cache.yml @@ -0,0 +1,29 @@ +name: cleanup caches by a branch +on: + pull_request: + # types: + # - closed + +jobs: + cleanup: + runs-on: intellabs-01 + steps: + - name: Cleanup + run: | + gh extension install actions/gh-actions-cache + + echo "Fetching list of cache key" + cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 ) + + ## Setting this to not fail the workflow while deleting cache keys. + 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 }} + REPO: ${{ github.repository }} + BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge \ No newline at end of file diff --git a/.github/workflows/test_build.yml b/.github/workflows/test_build.yml index 93aa238f..89ec530d 100644 --- a/.github/workflows/test_build.yml +++ b/.github/workflows/test_build.yml @@ -1,10 +1,6 @@ --- name: test-build on: - # Triggers the workflow on push or pull request events but - # only for the main branch - push: - branches: [main] pull_request: branches: [main] workflow_dispatch: @@ -39,25 +35,7 @@ jobs: key: ${{ runner.os }}-build-${{ github.run_number }} #${{ github.ref }} #-${{ hashFiles('.') }} - # restore-key: ${{ runner.os }}-build-${{ github.run_number }} - - name: Cleanup Cache - run: | - gh extension install actions/gh-actions-cache - - cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 ) - - for cacheKey in $cacheKeysForPR - do - echo $cacheKey - done - echo gh actions-cache delete $CACHE_ENTRY -R $REPO -B $BRANCH --confirm - gh actions-cache delete $CACHE_ENTRY -R $REPO -B $BRANCH --confirm - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - REPO: intellabs/scenario_execution - #${{ github.repository }} - CACHE_ENTRY: ${{ runner.os }}-build-${{ github.run_number }} - BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge + restore-keys: ${{ runner.os }}-build-${{ github.run_number }} run-tests: needs: [build-and-cache] runs-on: intellabs-01