Skip to content

Commit

Permalink
Added bazel cache cleanup to xls's github 22.04 actions.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 492602269
  • Loading branch information
hongted authored and copybara-github committed Dec 3, 2022
1 parent 05cb18f commit 34f94f6
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/nightly-ubuntu-22.04.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
39 changes: 39 additions & 0 deletions .github/workflows/one-bazel-test-ubuntu-22.04.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

0 comments on commit 34f94f6

Please sign in to comment.