diff --git a/.github/workflows/nightly-ubuntu-22.04.yml b/.github/workflows/nightly-ubuntu-22.04.yml index 1eae25901a..e5b69d915c 100644 --- a/.github/workflows/nightly-ubuntu-22.04.yml +++ b/.github/workflows/nightly-ubuntu-22.04.yml @@ -36,3 +36,42 @@ jobs: - name: Bazel Test All (opt) run: | "${GITHUB_WORKSPACE}/bin/bazel" test -c opt -- //xls/... -//xls/contrib/xlscc/... + cleanup: + name: Bazel Cache Cleanup + needs: build + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: read + actions: write + steps: + - uses: actions/checkout@v3 + - name: Cleanup older Bazel Caches + # Per https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy + run: | + gh extension install actions/gh-actions-cache + + REPO=${{ github.repository }} + BRANCH=${{ github.ref }} + + echo "Fetching list of cache key" + gh actions-cache list -R $REPO -B $BRANCH + + # Do not fail if unable to clean up (i.e. no cache were found). + set +e + caches_for_22_04=($(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 | grep "bazel-cache-22_04")) + + # Delete all except for the latest cache. + older_caches_for_22_04=${caches_for_22_04[@]:1} + + echo "Deleting caches..." + for key in ${older_caches_for_22_04[@]}; do + echo " ... deleting $key for $REPO and $BRANCH" + gh actions-cache delete $key -R $REPO -B $BRANCH --confirm + done + + echo "Done" + + set -e + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/one-bazel-test-ubuntu-22.04.yml b/.github/workflows/one-bazel-test-ubuntu-22.04.yml index 93b7b94a0b..05cf1ef750 100644 --- a/.github/workflows/one-bazel-test-ubuntu-22.04.yml +++ b/.github/workflows/one-bazel-test-ubuntu-22.04.yml @@ -46,3 +46,42 @@ jobs: - name: Bazel Test Target (opt) run: | "${GITHUB_WORKSPACE}/bin/bazel" test -c opt --test_output=all --runs_per_test=$BAZEL_RUNS_PER_TEST -- $BAZEL_TARGET + cleanup: + name: Bazel Cache Cleanup + needs: build + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: read + actions: write + steps: + - uses: actions/checkout@v3 + - name: Cleanup older Bazel Caches + # Per https://github.com/actions/cache/blob/main/tips-and-workarounds.md#force-deletion-of-caches-overriding-default-cache-eviction-policy + run: | + gh extension install actions/gh-actions-cache + + REPO=${{ github.repository }} + BRANCH=${{ github.ref }} + + echo "Fetching list of cache key" + gh actions-cache list -R $REPO -B $BRANCH + + # Do not fail if unable to clean up (i.e. no cache were found). + set +e + caches_for_22_04=($(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 | grep "bazel-cache-22_04")) + + # Delete all except for the latest cache. + older_caches_for_22_04=${caches_for_22_04[@]:1} + + echo "Deleting caches..." + for key in ${older_caches_for_22_04[@]}; do + echo " ... deleting $key for $REPO and $BRANCH" + gh actions-cache delete $key -R $REPO -B $BRANCH --confirm + done + + echo "Done" + + set -e + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}