From 4d3d7a0b5c7c5b509b37a7379af94bd3e0cf4487 Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Sun, 25 Oct 2026 20:00:14 +0100 Subject: [PATCH 1/4] Propose cancelling the runs of merged pull requests Generated-by: Claude Opus 5 --- content/pages/github-actions-optimization.md | 51 ++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/content/pages/github-actions-optimization.md b/content/pages/github-actions-optimization.md index 9be21b5e9..daf721f2e 100644 --- a/content/pages/github-actions-optimization.md +++ b/content/pages/github-actions-optimization.md @@ -18,6 +18,7 @@ Some of these techniques are experiments that Airflow is exploring. Treat them a | [Cap open pull requests per contributor](#pr-cap) | In production | 210 PRs from 21 contributors closed in the first pass | | [Run external contributors' CI in their forks](#fork-ci) | **Experimental** | Expected to cut shared-runner use by about 40% | | [Self-hosted runners with RunsOn](#runs-on) | **Experimental** | Expected to move at least 40% of the heaviest jobs off shared runners | +| [Cancel the runs of merged pull requests](#cancel-merged) | **Proposed** | Stops runs that keep going after their pull request has merged |

Start with the basics

@@ -189,6 +190,56 @@ RunsOn offers two modes. Fleet adds a GitHub runner group restricted to selected Airflow references: AIP-118: Self-hosted runners for Apache Airflow CI and its appendix with evidence and implementation details, the AIP-119 discussion on cost guardrails, the implementation and its security review in apache/airflow#74889, and the earlier full-CI experiment in apache/airflow#74714. See also RunsOn's own documentation on security for public repositories. +

Cancel the runs of merged pull requests (proposed)

+ +**Status: proposed.** Airflow is adding this to a scheduled job that already runs every 15 minutes. Results will be added here once it has run for a while. + +Merging a pull request does not stop its `pull_request` runs. A maintainer often merges as soon as the checks they need are green, while slower jobs of the same run are still queued or running. Those jobs keep holding runners for a result nobody reads, because the change is already on its target branch. A concurrency group does not help: the merge does not start a new run in the pull request's group. + +A scheduled workflow can cancel them. Every few minutes it lists the repository's unfinished `pull_request` runs and cancels the ones whose pull request has merged. Things to get right: + +- **Match runs to pull requests by head.** The `pull_requests` field of a run is empty when the pull request comes from a fork, so match by head repository, branch and commit instead. +- **Only cancel runs created before the merge.** Workflows triggered by the merge itself, for example on the `closed` event, are meant to run. +- **Skip heads that an open pull request still uses.** A branch can be reused for a new pull request, and a common branch name such as `main` or `patch-1` has pull requests from many forks, so look at all of them, not only the latest. +- **Force-cancel what does not stop.** A job that ignores the cancellation keeps its runner. Use the force-cancel endpoint for a run that is still running some time after a normal cancel. + +A minimal version, which needs only `actions: write`: + +```yaml +name: Cancel the runs of merged pull requests +on: + schedule: + - cron: '7,22,37,52 * * * *' + workflow_dispatch: +permissions: + actions: write + pull-requests: read +jobs: + cancel: + runs-on: ubuntu-slim + timeout-minutes: 10 + steps: + - env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + run: | + for status in queued in_progress; do + gh api --paginate "repos/$REPO/actions/runs?event=pull_request&status=$status" \ + --jq '.workflow_runs[] | [.id, .head_repository.full_name, .head_branch, .head_sha, .created_at] | @tsv' + done | while IFS=$'\t' read -r id head_repo branch sha created; do + prs=$(gh pr list -R "$REPO" --state all --head "$branch" --limit 1000 \ + --json state,headRefOid,headRepositoryOwner,mergedAt \ + --jq "[.[] | select(.headRefOid == \"$sha\" and .headRepositoryOwner.login == \"${head_repo%%/*}\")]") + merged_at=$(jq -r '[.[] | select(.state == "MERGED")][0].mergedAt // empty' <<< "$prs") + open=$(jq '[.[] | select(.state == "OPEN")] | length' <<< "$prs") + if [[ -n "$merged_at" && "$open" == 0 && "$created" < "$merged_at" ]]; then + gh run cancel "$id" -R "$REPO" + fi + done +``` + +Airflow reference: apache/airflow#75619, which adds this to its fork CI monitor, together with the force-cancel of runs still going 30 minutes after the merge and a switch to turn it off. +

Audit your workflows with Apache Magpie

Apache Magpie is a set of skills for the AI agent a maintainer already uses, built at the ASF for the work of running a project. Its repo-health skills let a PMC audit its repositories without writing anything to them: each skill reads the repository, reports what it found, and proposes changes that the maintainers decide on. From 09abb96022bf4a30ec0a00039950ffb267409e8f Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Sun, 25 Oct 2026 20:12:11 +0100 Subject: [PATCH 2/4] Fix the heading spacing that fails markdownlint on master 61049f4 left the section headings of app-upgrade-policy.md without the blank line after them that MD022 requires, so the prek check fails for every pull request. Generated-by: Claude Opus 5 --- content/pages/app-upgrade-policy.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/content/pages/app-upgrade-policy.md b/content/pages/app-upgrade-policy.md index b5b01381c..c87f9c502 100644 --- a/content/pages/app-upgrade-policy.md +++ b/content/pages/app-upgrade-policy.md @@ -6,11 +6,13 @@ This policy encompasses Infra's approach to upgrades of Jenkins, Confluence and ## Jenkins ### Main Jenkins instance + _Upgrades once a quarter_ Infra follows the LTS line of releases, which the Jenkins Project releases on a 12-week cycle. Once every three months, on the last Saturday or Sunday of the month following the Jenkins LTS release, ASF Infra upgrades the main instance. ### Jenkins plugins + _Upgrade once a month_ We upgrade all plugins (there are more than 200!) before and after the main instance upgrade, as appropriate, and at the end of each month when there is no main instance upgrade to perform. @@ -18,11 +20,13 @@ We upgrade all plugins (there are more than 200!) before and after the main inst ## Jira ### Main Jira instance + _Upgrades every six months_ Jira gets a new release every two to six weeks, far too often (and unpredictable) for us to upgrade every release they make. Infra upgrades our Jira instance to whatever the latest release is every six months. ### Jira plugins + _Upgrade every two months_ We upgrade Jira plugins before or after each main instance upgrade, as appropriate, and once every two months between main instance upgrades. @@ -30,11 +34,13 @@ We upgrade Jira plugins before or after each main instance upgrade, as appropria ## Confluence ### Main Confluence instance + _Upgrades every six months_ Our goal is to upgrade Confluence to the latest version twice a year. ### Confluence plugins + _Upgrade every two months_ Every two months we perform upgrades to plugins that are compatible with the version of the main Confluence instance we are running. From 830e649b70d4e12e74f7f85f1ea13ffa4352c733 Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Sun, 25 Oct 2026 20:19:29 +0100 Subject: [PATCH 3/4] Reword the force-cancel tip and drop the Airflow citations Generated-by: Claude Opus 5 --- content/pages/github-actions-optimization.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/content/pages/github-actions-optimization.md b/content/pages/github-actions-optimization.md index daf721f2e..e6f293d1a 100644 --- a/content/pages/github-actions-optimization.md +++ b/content/pages/github-actions-optimization.md @@ -192,7 +192,7 @@ Airflow references: Cancel the runs of merged pull requests (proposed) -**Status: proposed.** Airflow is adding this to a scheduled job that already runs every 15 minutes. Results will be added here once it has run for a while. +**Status: proposed.** Results will be added here once it has been used in production for a while. Merging a pull request does not stop its `pull_request` runs. A maintainer often merges as soon as the checks they need are green, while slower jobs of the same run are still queued or running. Those jobs keep holding runners for a result nobody reads, because the change is already on its target branch. A concurrency group does not help: the merge does not start a new run in the pull request's group. @@ -201,7 +201,7 @@ A scheduled workflow can cancel them. Every few minutes it lists the repository' - **Match runs to pull requests by head.** The `pull_requests` field of a run is empty when the pull request comes from a fork, so match by head repository, branch and commit instead. - **Only cancel runs created before the merge.** Workflows triggered by the merge itself, for example on the `closed` event, are meant to run. - **Skip heads that an open pull request still uses.** A branch can be reused for a new pull request, and a common branch name such as `main` or `patch-1` has pull requests from many forks, so look at all of them, not only the latest. -- **Force-cancel what does not stop.** A job that ignores the cancellation keeps its runner. Use the force-cancel endpoint for a run that is still running some time after a normal cancel. +- **Force-cancel what does not stop.** A job that ignores the cancellation keeps its runner. Use the force-cancel endpoint to cancel a run that continues after a normal cancel. A minimal version, which needs only `actions: write`: @@ -238,8 +238,6 @@ jobs: done ``` -Airflow reference: apache/airflow#75619, which adds this to its fork CI monitor, together with the force-cancel of runs still going 30 minutes after the merge and a switch to turn it off. -

Audit your workflows with Apache Magpie

Apache Magpie is a set of skills for the AI agent a maintainer already uses, built at the ASF for the work of running a project. Its repo-health skills let a PMC audit its repositories without writing anything to them: each skill reads the repository, reports what it found, and proposes changes that the maintainers decide on. From 1adbf43731c54475a6a9832cede46e418724d16f Mon Sep 17 00:00:00 2001 From: Jarek Potiuk Date: Mon, 26 Oct 2026 18:18:11 +0100 Subject: [PATCH 4/4] Trigger the merged-PR cancel on push instead of a schedule Running on push handles only the pull request that was just merged, right after the merge, instead of scanning every unfinished run on a schedule. Suggested in review. Generated-by: Claude Opus 5 --- content/pages/github-actions-optimization.md | 39 ++++++++++---------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/content/pages/github-actions-optimization.md b/content/pages/github-actions-optimization.md index e6f293d1a..038bcf7fa 100644 --- a/content/pages/github-actions-optimization.md +++ b/content/pages/github-actions-optimization.md @@ -196,45 +196,46 @@ Airflow references: force-cancel endpoint to cancel a run that continues after a normal cancel. -A minimal version, which needs only `actions: write`: +A minimal version, which needs write access only to `actions`. List the branches that your pull requests merge into under `branches`: ```yaml name: Cancel the runs of merged pull requests on: - schedule: - - cron: '7,22,37,52 * * * *' - workflow_dispatch: + push: + branches: [main] permissions: actions: write + contents: read pull-requests: read jobs: cancel: runs-on: ubuntu-slim - timeout-minutes: 10 + timeout-minutes: 5 steps: - env: GH_TOKEN: ${{ github.token }} REPO: ${{ github.repository }} + SHA: ${{ github.sha }} run: | - for status in queued in_progress; do - gh api --paginate "repos/$REPO/actions/runs?event=pull_request&status=$status" \ - --jq '.workflow_runs[] | [.id, .head_repository.full_name, .head_branch, .head_sha, .created_at] | @tsv' - done | while IFS=$'\t' read -r id head_repo branch sha created; do - prs=$(gh pr list -R "$REPO" --state all --head "$branch" --limit 1000 \ - --json state,headRefOid,headRepositoryOwner,mergedAt \ - --jq "[.[] | select(.headRefOid == \"$sha\" and .headRepositoryOwner.login == \"${head_repo%%/*}\")]") - merged_at=$(jq -r '[.[] | select(.state == "MERGED")][0].mergedAt // empty' <<< "$prs") - open=$(jq '[.[] | select(.state == "OPEN")] | length' <<< "$prs") - if [[ -n "$merged_at" && "$open" == 0 && "$created" < "$merged_at" ]]; then + gh api "repos/$REPO/commits/$SHA/pulls" \ + --jq '.[] | select(.merged_at != null) | [.head.repo.full_name, .head.sha, .merged_at] | @tsv' | + while IFS=$'\t' read -r head_repo head_sha merged_at; do + open=$(gh pr list -R "$REPO" --state open --search "$head_sha" --json headRefOid \ + --jq "[.[] | select(.headRefOid == \"$head_sha\")] | length") + [[ "$open" == 0 ]] || continue + for status in queued in_progress; do + gh api --paginate "repos/$REPO/actions/runs?event=pull_request&head_sha=$head_sha&status=$status" \ + --jq ".workflow_runs[] | select(.head_repository.full_name == \"$head_repo\" and .created_at < \"$merged_at\") | .id" + done | while read -r id; do gh run cancel "$id" -R "$REPO" - fi + done done ```