Skip to content

Add description for CreateRole/CreateUser #32

Add description for CreateRole/CreateUser

Add description for CreateRole/CreateUser #32

name: Cleanup PR caches
on:
pull_request_target:
types: [closed]
permissions:
actions: write
contents: read
pull-requests: read
jobs:
# When a PR is closed, cancel any still-running pull_request workflow runs for
# that PR and delete all GitHub Actions caches associated with the PR's merge
# ref (refs/pull/PR_NUMBER/merge).
cleanup:
name: Cleanup PR actions state
runs-on: ubuntu-latest
steps:
- name: Cancel PR workflow runs
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
RUN_ID: ${{ github.run_id }}
run: |
set -euo pipefail
run_ids=$(gh pr view "$PR_NUMBER" --repo "$GH_REPO" --json statusCheckRollup --jq '.statusCheckRollup[] | select(.__typename == "CheckRun" and (.status == "IN_PROGRESS" or .status == "QUEUED") and (.detailsUrl | contains("/actions/runs/"))) | (.detailsUrl | capture("/actions/runs/(?<run_id>[0-9]+)").run_id)' | sed '/^$/d' | sort -u)
run_ids=$(printf '%s\n' "$run_ids" | grep -vx "$RUN_ID" || true)
if [ -z "$run_ids" ]; then
echo "No queued or in-progress pull_request runs found for PR #$PR_NUMBER"
else
while read -r run_id; do
if ! gh api --method POST "repos/$GH_REPO/actions/runs/$run_id/cancel"; then
echo "Run $run_id could not be cancelled; it may have already finished"
fi
done <<< "$run_ids"
fi
- name: Delete PR caches
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
PR_REF: refs/pull/${{ github.event.pull_request.number }}/merge
run: |
set -euo pipefail
cache_ids=$(gh api --paginate "repos/$GH_REPO/actions/caches?ref=$PR_REF&per_page=100" --jq '.actions_caches[].id')
if [ -z "$cache_ids" ]; then
echo "No caches found for $PR_REF"
exit 0
fi
while read -r cache_id; do
gh api --method DELETE "repos/$GH_REPO/actions/caches/$cache_id"
done <<< "$cache_ids"