diff --git a/.github/workflows/cleanup-cache-postpr.yml b/.github/workflows/cleanup-cache-postpr.yml deleted file mode 100644 index d352d47a9..000000000 --- a/.github/workflows/cleanup-cache-postpr.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: CleanUpCachePostPR - -on: - workflow_run: - workflows: [PostPR] - types: - - completed - -jobs: - CleanUpCcacheCachePostPR: - name: Clean Up Ccahe Cache Post PR - runs-on: ubuntu-latest - permissions: - actions: write - contents: read - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - uses: actions/checkout@v4 - - name: Clean up ccahe - run: | - gh extension install actions/gh-actions-cache - - REPO=${{ github.repository }} - - gh run download ${{ github.event.workflow_run.id }} -n pr_number - pr_number=`cat pr_number.txt` - BRANCH=refs/pull/${pr_number}/merge - - # Setting this to not fail the workflow while deleting cache keys. - set +e - - keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH | cut -f 1) - for k in $keys - do - gh actions-cache delete $k -R $REPO -B $BRANCH --confirm - done diff --git a/.github/workflows/cleanup-cache.yml b/.github/workflows/cleanup-cache.yml index 3448d88bc..42746c93f 100644 --- a/.github/workflows/cleanup-cache.yml +++ b/.github/workflows/cleanup-cache.yml @@ -8,7 +8,7 @@ on: jobs: CleanUpCcacheCache: - name: Clean Up Ccahe Cache for ${{ github.event.workflow_run.name }} + name: Clean Up Ccache Cache for ${{ github.event.workflow_run.name }} runs-on: ubuntu-latest permissions: actions: write @@ -17,7 +17,7 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - uses: actions/checkout@v4 - - name: Clean up ccahe + - name: Clean up ccache run: | gh extension install actions/gh-actions-cache @@ -27,11 +27,11 @@ jobs: EVENT=${{ github.event.workflow_run.event }} # Triggering workflow run name (e.g., LinuxClang) - WORKFLOW_NAME=${{ github.event.workflow_run.name }} + WORKFLOW_NAME="${{ github.event.workflow_run.name }}" if [[ $EVENT == "pull_request" ]]; then - gh run download ${{ github.event.workflow_run.id }} -n pr_number - pr_number=`cat pr_number.txt` + pr_number=$(jq --raw-output .workflow_run.pull_requests[0].number < ${GITHUB_EVENT_PATH}) + echo "Clean up cache for PR ${pr_number}." BRANCH=refs/pull/${pr_number}/merge else BRANCH=refs/heads/${{ github.event.workflow_run.head_branch }} @@ -45,16 +45,20 @@ jobs: # The goal is to keep the last used key of each job and delete all others. # something like ccache-LinuxClang- - keyprefix=ccache-${WORKFLOW_NAME}- + keyprefix="ccache-${WORKFLOW_NAME}-" - cached_jobs=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key $keyprefix | awk -F '-git-' '{print $1}' | sort | uniq) + cached_jobs=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key "$keyprefix" | awk -F '-git-' '{print $1}' | sort | uniq) # cached_jobs is something like "ccache-LinuxClang-configure-1d ccache-LinuxClang-configure-2d". + # It might also contain spaces. Thus we set IFS to \n. + IFS=$'\n' for j in $cached_jobs do - old_keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key ${j}-git- --sort last-used | cut -f 1 | tail -n +2) + # Delete all entries except the last used one + old_keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key "${j}-git-" --sort last-used | cut -f 1 | tail -n +2) for k in $old_keys do - gh actions-cache delete $k -R $REPO -B $BRANCH --confirm + gh actions-cache delete "$k" -R $REPO -B $BRANCH --confirm done done + unset IFS diff --git a/.github/workflows/cuda.yml b/.github/workflows/cuda.yml index 8689de021..a4f952c2d 100644 --- a/.github/workflows/cuda.yml +++ b/.github/workflows/cuda.yml @@ -159,18 +159,3 @@ jobs: ccache -s du -hs ~/.cache/ccache - - save_pr_number: - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - steps: - - name: Save PR number - env: - PR_NUMBER: ${{ github.event.number }} - run: | - echo $PR_NUMBER > pr_number.txt - - uses: actions/upload-artifact@v4 - with: - name: pr_number - path: pr_number.txt - retention-days: 1 diff --git a/.github/workflows/gcc.yml b/.github/workflows/gcc.yml index a22700439..614c615e5 100644 --- a/.github/workflows/gcc.yml +++ b/.github/workflows/gcc.yml @@ -153,18 +153,3 @@ jobs: ccache -s du -hs ~/.cache/ccache - - save_pr_number: - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - steps: - - name: Save PR number - env: - PR_NUMBER: ${{ github.event.number }} - run: | - echo $PR_NUMBER > pr_number.txt - - uses: actions/upload-artifact@v4 - with: - name: pr_number - path: pr_number.txt - retention-days: 1 diff --git a/.github/workflows/hip.yml b/.github/workflows/hip.yml index b59dd8ef6..b9a1b04b0 100644 --- a/.github/workflows/hip.yml +++ b/.github/workflows/hip.yml @@ -92,18 +92,3 @@ jobs: ccache -s du -hs ~/.cache/ccache - - save_pr_number: - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - steps: - - name: Save PR number - env: - PR_NUMBER: ${{ github.event.number }} - run: | - echo $PR_NUMBER > pr_number.txt - - uses: actions/upload-artifact@v4 - with: - name: pr_number - path: pr_number.txt - retention-days: 1 diff --git a/.github/workflows/post-pr.yml b/.github/workflows/post-pr.yml index 2768ef376..4155b6c52 100644 --- a/.github/workflows/post-pr.yml +++ b/.github/workflows/post-pr.yml @@ -5,16 +5,35 @@ on: - closed jobs: - cleanup: + cleanup_cache: + name: Clean Up Ccache Cache Post PR runs-on: ubuntu-latest + permissions: + actions: write + contents: read + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - name: Save PR number - env: - PR_NUMBER: ${{ github.event.number }} + - uses: actions/checkout@v4 + - name: Clean up ccache run: | - echo $PR_NUMBER > pr_number.txt - - uses: actions/upload-artifact@v4 - with: - name: pr_number - path: pr_number.txt - retention-days: 1 + gh extension install actions/gh-actions-cache + + REPO=${{ github.repository }} + + pr_number=${{ github.event.number }} + echo "Clean up cache for PR ${pr_number}." + BRANCH=refs/pull/${pr_number}/merge + + # Setting this to not fail the workflow while deleting cache keys. + set +e + + # Delete all entries associated with this PR. + keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH | cut -f 1) + # $keys might contain spaces. Thus we set IFS to \n. + IFS=$'\n' + for k in $keys + do + gh actions-cache delete "$k" -R $REPO -B $BRANCH --confirm + done + unset IFS diff --git a/.github/workflows/sycl.yml b/.github/workflows/sycl.yml index 1b0b9e71b..c8b9682fe 100644 --- a/.github/workflows/sycl.yml +++ b/.github/workflows/sycl.yml @@ -87,18 +87,3 @@ jobs: ccache -s du -hs ~/.cache/ccache - - save_pr_number: - if: github.event_name == 'pull_request' - runs-on: ubuntu-latest - steps: - - name: Save PR number - env: - PR_NUMBER: ${{ github.event.number }} - run: | - echo $PR_NUMBER > pr_number.txt - - uses: actions/upload-artifact@v4 - with: - name: pr_number - path: pr_number.txt - retention-days: 1