mirror of
https://github.com/X11Libre/xserver.git
synced 2026-11-14 05:14:45 +00:00
ci: fix purge script — preserve PR runs for open PRs (including forks)
The purge script was deleting workflow runs for PRs from forks because it only checked branch existence in the main repo (X11Libre/xserver). Fork PR branches don't exist there, so their runs were deleted immediately. Fix: fetch the 'pull_requests' field from the workflow run API and skip deletion if any associated PR is still open. Also fetch head_repository for logging. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
a6710636a1
commit
dd3082b1ae
1 changed files with 11 additions and 2 deletions
|
|
@ -77,22 +77,31 @@ log_info "Found $(echo "$existing_branches" | wc -l) branches."
|
|||
log_info "Fetching workflow runs..."
|
||||
gh api -H "Accept: application/vnd.github+json" \
|
||||
"/repos/${REPO}/actions/runs?per_page=100" --paginate \
|
||||
| jq -c '.workflow_runs[] | {id: .id, branch: .head_branch, workflow: .name}' \
|
||||
| jq -c '.workflow_runs[] | {id: .id, branch: .head_branch, workflow: .name, pull_requests: .pull_requests, head_repository: .head_repository}' \
|
||||
| while read -r run; do
|
||||
run_id=$(echo "$run" | jq -r '.id')
|
||||
run_branch=$(echo "$run" | jq -r '.branch')
|
||||
workflow_name=$(echo "$run" | jq -r '.workflow')
|
||||
pull_requests=$(echo "$run" | jq -c '.pull_requests')
|
||||
head_repo=$(echo "$run" | jq -r '.head_repository.full_name // empty')
|
||||
|
||||
if [[ -z "$run_branch" ]]; then
|
||||
log_warn "Run $run_id has no branch (skipping)."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Skip if branch exists
|
||||
# Skip if branch exists in main repo
|
||||
if echo "$existing_branches" | grep -qx "$run_branch"; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Skip if run is associated with an OPEN pull request
|
||||
# (pull_requests array contains PR objects with .state field)
|
||||
if echo "$pull_requests" | jq -e 'any(.state == "open")' >/dev/null 2>&1; then
|
||||
log_info "Skipping run $run_id (branch: $run_branch) — associated with open PR"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Skip if workflow filter is set and does not match
|
||||
if [[ -n "$WORKFLOW_FILTER" && "$workflow_name" != "$WORKFLOW_FILTER" ]]; then
|
||||
continue
|
||||
|
|
|
|||
Loading…
Reference in a new issue