Skip to content

Commit

Permalink
[DOP-14025] Cleanup unused cache after merging PR
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfinus committed Apr 22, 2024
1 parent 034fc86 commit 876a8fa
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/cache-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Cleanup caches after merge
on:
pull_request:
types:
- closed
workflow_dispatch:

jobs:
cleanup:
runs-on: ubuntu-latest
permissions:
# `actions:write` permission is required to delete caches
# See also: https://docs.github.com/en/rest/actions/cache?apiVersion=2022-11-28#delete-a-github-actions-cache-for-a-repository-using-a-cache-id
actions: write
contents: read

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Cleanup cache
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 --limit 100 --sort size | 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 }}
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ jobs:
HADOOP_VERSION=${{ matrix.hadoop-version }}
pull: true
push: true
cache-to: type=gha,mode=max
cache-from: type=gha
cache-to: type=inline
cache-from: mtsrus/hadoop:hadoop${{ matrix.hadoop-version }}-hdfs
platforms: |
linux/amd64
linux/arm64/v8
Expand All @@ -69,8 +69,8 @@ jobs:
BASE_IMAGE=mtsrus/hadoop:${{ github.ref_name }}-hadoop${{ matrix.hadoop-version }}-hdfs
pull: true
push: true
cache-to: type=gha,mode=max
cache-from: type=gha
cache-to: type=inline
cache-from: mtsrus/hadoop:hadoop${{ matrix.hadoop-version }}-yarn
platforms: |
linux/amd64
linux/arm64/v8
Expand All @@ -89,8 +89,8 @@ jobs:
BASE_IMAGE=mtsrus/hadoop:${{ github.ref_name }}-hadoop${{ matrix.hadoop-version }}-yarn
pull: true
push: true
cache-to: type=gha,mode=max
cache-from: type=gha
cache-to: type=inline
cache-from: mtsrus/hadoop:hadoop${{ matrix.hadoop-version }}-hive${{ matrix.hive-version }}
platforms: |
linux/amd64
linux/arm64/v8
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
HADOOP_VERSION=${{ matrix.hadoop-version }}
pull: true
push: false
cache-from: mtsrus/hadoop:hadoop${{ matrix.hadoop-version }}-hdfs

- name: Test HDFS
run: |
Expand Down Expand Up @@ -77,6 +78,7 @@ jobs:
build-args: |
BASE_IMAGE=mtsrus/hadoop:${{ github.run_id }}-hadoop${{ matrix.hadoop-major-version }}-hdfs
push: false
cache-from: mtsrus/hadoop:hadoop${{ matrix.hadoop-version }}-yarn

- name: Test Yarn
run: |
Expand All @@ -101,12 +103,13 @@ jobs:
- name: Build Hive
uses: docker/build-push-action@v5
with:
tags: mtsrus/hadoop:${{ github.run_id }}-hadoop${{ matrix.hadoop-major-version }}-hive
tags: mtsrus/hadoop:${{ github.run_id }}-hadoop${{ matrix.hadoop-major-version }}-hive${{ matrix.hive-version }}
context: ./hive
build-args: |
HIVE_VERSION=${{ matrix.hive-version }}
BASE_IMAGE=mtsrus/hadoop:${{ github.run_id }}-hadoop${{ matrix.hadoop-major-version }}-yarn
push: false
cache-from: mtsrus/hadoop:hadoop${{ matrix.hadoop-version }}-hive${{ matrix.hive-version }}

- name: Test Hive
run: |
Expand All @@ -118,7 +121,7 @@ jobs:
env:
COMPOSE_FILE: hive/docker-compose.yml
COMPOSE_PROJECT_NAME: ${{ github.run_id }}-hadoop${{ matrix.hadoop-major-version }}-hive
HIVE_IMAGE: mtsrus/hadoop:${{ github.run_id }}-hadoop${{ matrix.hadoop-major-version }}-hive
HIVE_IMAGE: mtsrus/hadoop:${{ github.run_id }}-hadoop${{ matrix.hadoop-major-version }}-hive${{ matrix.hive-version }}

- name: Shutdown Hive
if: always()
Expand Down

0 comments on commit 876a8fa

Please sign in to comment.