From ae461042969122b57fe1dbafc5794408ed282362 Mon Sep 17 00:00:00 2001 From: Jeremy Walker Date: Sat, 7 Nov 2026 23:07:31 +0900 Subject: [PATCH 1/8] List the checks that must pass before a PR can merge exercism/maintainers-admin-tools reads .github/required-checks.yml and applies it to this repo's "Default branch" ruleset. The required-checks workflow fails a PR when a listed check didn't run on it, so a wrong name can't block every PR. The Ruby version matrix jobs aren't listed, because their names change when a version is bumped. Co-Authored-By: Claude Opus 5.5 --- .github/CODEOWNERS | 4 + .github/required-checks.yml | 19 ++++ .github/workflows/required-checks.yml | 135 ++++++++++++++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 .github/required-checks.yml create mode 100644 .github/workflows/required-checks.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b5b0dfcdd5..6fc6c558d8 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,6 +1,10 @@ # Code owners .github/CODEOWNERS @exercism/maintainers-admin +# The checks that must pass before a PR can merge, and the workflow that validates them +.github/required-checks.yml @exercism/maintainers-admin +.github/workflows/required-checks.yml @exercism/maintainers-admin + # The code sample shown in the code check when people sign up to Exercism docs/SIGN_UP_SNIPPET.txt @exercism/maintainers-admin diff --git a/.github/required-checks.yml b/.github/required-checks.yml new file mode 100644 index 0000000000..06a3e28248 --- /dev/null +++ b/.github/required-checks.yml @@ -0,0 +1,19 @@ +# The checks that must pass before a PR can merge into main. +# +# exercism/maintainers-admin-tools reads this file and applies it to this repo's +# "Default branch" ruleset, within a few minutes of a change reaching main. +# +# Each entry is a check's name exactly as it appears on a PR. A check that +# doesn't come from GitHub Actions also needs its app's id: +# +# - name: some-check +# app: 960 +# +# To remove or rename a check, first take it out of this file in its own PR and +# let that merge. Then remove or rename the job. If both happen in one PR, the PR +# waits forever for a check that no longer runs. +checks: + - configlet / configlet + - i18n / completeness + - Check Generator Templates + - Test Generator diff --git a/.github/workflows/required-checks.yml b/.github/workflows/required-checks.yml new file mode 100644 index 0000000000..133bb3f158 --- /dev/null +++ b/.github/workflows/required-checks.yml @@ -0,0 +1,135 @@ +# This workflow checks a PR that changes .github/required-checks.yml or a +# workflow. It fails if a check that the file lists didn't run on the PR. +# exercism/maintainers-admin-tools applies the file to this repo's ruleset, so +# a listed check that never runs would stop every PR from merging. +# +# It also catches a PR that removes or renames a job that main's copy of the +# file still requires. That PR can't merge, because GitHub waits for the old +# check, so the job's removal needs to wait for a PR that takes it out of the +# file first. + +name: Required checks + +on: + pull_request: + branches: [main] + paths: + - .github/required-checks.yml + - .github/workflows/** + +permissions: {} + +jobs: + validate: + name: Validate required checks + runs-on: ubuntu-24.04 + timeout-minutes: 45 + permissions: + checks: read + contents: read + steps: + - name: Check that every required check ran + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + OWN_CHECK_NAME: Validate required checks + shell: ruby {0} + run: | + require "json" + require "open3" + require "yaml" + + GITHUB_ACTIONS_APP_ID = 15368 + REPO = ENV.fetch("REPO") + HEAD_SHA = ENV.fetch("HEAD_SHA") + OWN_CHECK_NAME = ENV.fetch("OWN_CHECK_NAME") + + def gh(*args) + output, error, status = Open3.capture3("gh", "api", *args) + [output, error, status] + end + + # The file at a commit, or nil if the commit doesn't have it + def read_file(sha) + output, error, status = gh("repos/#{REPO}/contents/.github/required-checks.yml?ref=#{sha}", + "-H", "Accept: application/vnd.github.raw") + return nil if !status.success? && error.include?("HTTP 404") + abort "Reading .github/required-checks.yml at #{sha} failed: #{error}" unless status.success? + + output + end + + # The same rules as scripts/update-track-maintenance-status in exercism/maintainers-admin-tools + def parse(yaml, where) + data = YAML.safe_load(yaml) + abort "#{where}: the file must have a `checks` list" unless data.is_a?(Hash) && data["checks"].is_a?(Array) + + data["checks"].map do |check| + check = { "name" => check } if check.is_a?(String) + abort "#{where}: each check must be a name or have a `name`: #{check.inspect}" unless check.is_a?(Hash) + + name = check["name"] + app = check.fetch("app", GITHUB_ACTIONS_APP_ID) + unless name.is_a?(String) && name.strip == name && !name.empty? && name.length <= 255 && !name.match?(/[[:cntrl:]]/) + abort "#{where}: not a valid check name: #{name.inspect}" + end + abort "#{where}: `app` must be a GitHub App id: #{app.inspect}" unless app.is_a?(Integer) && app.positive? + + [name, app] + end.uniq + rescue Psych::Exception => e + abort "#{where}: the file isn't valid YAML: #{e.message}" + end + + head_yaml = read_file(HEAD_SHA) + base_yaml = read_file(ENV.fetch("BASE_SHA")) + wanted = head_yaml ? parse(head_yaml, "This PR's .github/required-checks.yml") : [] + on_main = base_yaml ? parse(base_yaml, "main's .github/required-checks.yml") : [] + + if wanted.empty? && on_main.empty? + puts "Neither this PR nor main lists any required checks." + exit + end + + # Wait until every other check on the PR has finished. Checks can start a + # little after this one, so the wait lasts at least a minute, and only + # ends after two polls in a row find nothing still running. + started = Time.now + quiet_polls = 0 + runs = [] + loop do + output, error, status = gh("--paginate", "--slurp", "repos/#{REPO}/commits/#{HEAD_SHA}/check-runs?per_page=100") + abort "Reading this PR's checks failed: #{error}" unless status.success? + + runs = JSON.parse(output).flat_map { |page| page["check_runs"] }.reject { |run| run["name"] == OWN_CHECK_NAME } + running = runs.reject { |run| run["status"] == "completed" } + quiet_polls = running.empty? ? quiet_polls + 1 : 0 + break if quiet_polls >= 2 && Time.now - started >= 60 + + puts "Waiting for: #{running.map { |run| run["name"] }.uniq.join(', ')}" unless running.empty? + sleep 20 + end + + ran = runs.map { |run| [run["name"], run.dig("app", "id")] }.uniq + problems = [] + + (wanted | on_main).each do |name, app| + next if ran.include?([name, app]) + + if on_main.include?([name, app]) + problems << "`#{name}` is required by main's .github/required-checks.yml, but it didn't run on this PR. " \ + "Take it out of the file in a PR of its own and merge that first, then remove or rename the job." + else + problems << "`#{name}` is listed in .github/required-checks.yml, but it didn't run on this PR. " \ + "Check the name matches the check exactly, and that its workflow runs on every PR to main." + end + end + + if problems.any? + problems.each { |problem| puts "::error::#{problem}" } + exit 1 + end + + puts "All #{wanted.size} required checks ran on this PR." From b6e3fa9907ad2ccc2590d2745cdd5af3aaf90658 Mon Sep 17 00:00:00 2001 From: Jeremy Walker Date: Sat, 7 Nov 2026 15:33:45 +0100 Subject: [PATCH 2/8] Update .github/required-checks.yml --- .github/required-checks.yml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/required-checks.yml b/.github/required-checks.yml index 06a3e28248..1bc8d9eb2d 100644 --- a/.github/required-checks.yml +++ b/.github/required-checks.yml @@ -1,17 +1,9 @@ -# The checks that must pass before a PR can merge into main. -# -# exercism/maintainers-admin-tools reads this file and applies it to this repo's -# "Default branch" ruleset, within a few minutes of a change reaching main. -# -# Each entry is a check's name exactly as it appears on a PR. A check that -# doesn't come from GitHub Actions also needs its app's id: -# -# - name: some-check -# app: 960 +# These checks must pass before a PR can merge into main. +# Changes here will be automatically synced to the repo's ruleset. # # To remove or rename a check, first take it out of this file in its own PR and # let that merge. Then remove or rename the job. If both happen in one PR, the PR -# waits forever for a check that no longer runs. +# will wait forever for a check that no longer runs. checks: - configlet / configlet - i18n / completeness From 70f2720369aca2784c9ed5e09119330a72ca6bb5 Mon Sep 17 00:00:00 2001 From: Jeremy Walker Date: Sat, 7 Nov 2026 23:35:37 +0900 Subject: [PATCH 3/8] Simplify the wording in the required-checks workflow Co-Authored-By: Claude Opus 5.5 --- .github/workflows/required-checks.yml | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/.github/workflows/required-checks.yml b/.github/workflows/required-checks.yml index 133bb3f158..01eddb63b5 100644 --- a/.github/workflows/required-checks.yml +++ b/.github/workflows/required-checks.yml @@ -1,12 +1,5 @@ -# This workflow checks a PR that changes .github/required-checks.yml or a -# workflow. It fails if a check that the file lists didn't run on the PR. -# exercism/maintainers-admin-tools applies the file to this repo's ruleset, so -# a listed check that never runs would stop every PR from merging. -# -# It also catches a PR that removes or renames a job that main's copy of the -# file still requires. That PR can't merge, because GitHub waits for the old -# check, so the job's removal needs to wait for a PR that takes it out of the -# file first. +# Checks that all the checks listed in .github/required-checks.yml exist. +# Also fails if a PR removes a job that's still listed in main's copy of the file. name: Required checks @@ -51,7 +44,7 @@ jobs: [output, error, status] end - # The file at a commit, or nil if the commit doesn't have it + # Returns the file at a commit, or nil if the commit doesn't have one def read_file(sha) output, error, status = gh("repos/#{REPO}/contents/.github/required-checks.yml?ref=#{sha}", "-H", "Accept: application/vnd.github.raw") @@ -61,7 +54,7 @@ jobs: output end - # The same rules as scripts/update-track-maintenance-status in exercism/maintainers-admin-tools + # Uses the same rules as scripts/sync-repo-settings in exercism/maintainers-admin-tools def parse(yaml, where) data = YAML.safe_load(yaml) abort "#{where}: the file must have a `checks` list" unless data.is_a?(Hash) && data["checks"].is_a?(Array) @@ -93,9 +86,9 @@ jobs: exit end - # Wait until every other check on the PR has finished. Checks can start a - # little after this one, so the wait lasts at least a minute, and only - # ends after two polls in a row find nothing still running. + # Wait for the PR's other checks to finish. Some checks start a little + # after this one, so wait at least a minute, and stop only when two + # polls in a row find nothing running. started = Time.now quiet_polls = 0 runs = [] @@ -119,11 +112,11 @@ jobs: next if ran.include?([name, app]) if on_main.include?([name, app]) - problems << "`#{name}` is required by main's .github/required-checks.yml, but it didn't run on this PR. " \ - "Take it out of the file in a PR of its own and merge that first, then remove or rename the job." + problems << "`#{name}` is still listed in main's .github/required-checks.yml, but it didn't run on this PR. " \ + "Remove it from the file in its own PR and merge that first. Then remove or rename the job." else problems << "`#{name}` is listed in .github/required-checks.yml, but it didn't run on this PR. " \ - "Check the name matches the check exactly, and that its workflow runs on every PR to main." + "Make sure the name matches the check exactly, and that its workflow runs on every PR to main." end end From 3ed6fbaefef1ef4d73f40afd5b1b7d26392f1d7b Mon Sep 17 00:00:00 2001 From: Jeremy Walker Date: Sun, 8 Nov 2026 13:37:45 +0900 Subject: [PATCH 4/8] Run the required-checks validation on every PR, and require it The workflow now runs on every PR and passes straight away when the PR changes neither required-checks.yml nor a workflow. That lets it be listed as a required check, so a PR that breaks the list can't be merged past a red X. Co-Authored-By: Claude Opus 5.5 --- .github/required-checks.yml | 1 + .github/workflows/required-checks.yml | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/required-checks.yml b/.github/required-checks.yml index 1bc8d9eb2d..367ecc6fe9 100644 --- a/.github/required-checks.yml +++ b/.github/required-checks.yml @@ -9,3 +9,4 @@ checks: - i18n / completeness - Check Generator Templates - Test Generator + - Validate required checks diff --git a/.github/workflows/required-checks.yml b/.github/workflows/required-checks.yml index 01eddb63b5..55aa28d4ff 100644 --- a/.github/workflows/required-checks.yml +++ b/.github/workflows/required-checks.yml @@ -1,14 +1,14 @@ # Checks that all the checks listed in .github/required-checks.yml exist. # Also fails if a PR removes a job that's still listed in main's copy of the file. +# +# It runs on every PR, so it can be listed as a required check itself. On a PR +# that changes neither the file nor a workflow, it passes straight away. name: Required checks on: pull_request: branches: [main] - paths: - - .github/required-checks.yml - - .github/workflows/** permissions: {} @@ -20,6 +20,7 @@ jobs: permissions: checks: read contents: read + pull-requests: read steps: - name: Check that every required check ran env: @@ -27,6 +28,7 @@ jobs: REPO: ${{ github.repository }} BASE_SHA: ${{ github.event.pull_request.base.sha }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} + PR_NUMBER: ${{ github.event.pull_request.number }} OWN_CHECK_NAME: Validate required checks shell: ruby {0} run: | @@ -76,6 +78,15 @@ jobs: abort "#{where}: the file isn't valid YAML: #{e.message}" end + output, error, status = gh("--paginate", "repos/#{REPO}/pulls/#{ENV.fetch('PR_NUMBER')}/files", "--jq", ".[].filename") + abort "Reading this PR's changed files failed: #{error}" unless status.success? + + changed_files = output.lines(chomp: true) + unless changed_files.any? { |file| file == ".github/required-checks.yml" || file.start_with?(".github/workflows/") } + puts "This PR doesn't change .github/required-checks.yml or a workflow, so there's nothing to check." + exit + end + head_yaml = read_file(HEAD_SHA) base_yaml = read_file(ENV.fetch("BASE_SHA")) wanted = head_yaml ? parse(head_yaml, "This PR's .github/required-checks.yml") : [] From 6c2443a1ea631ae15dd4253f799fd071a01e00bf Mon Sep 17 00:00:00 2001 From: Jeremy Walker Date: Sun, 8 Nov 2026 13:40:42 +0900 Subject: [PATCH 5/8] Name the validation check "Required checks", to match its workflow Co-Authored-By: Claude Opus 5.5 --- .github/required-checks.yml | 2 +- .github/workflows/required-checks.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/required-checks.yml b/.github/required-checks.yml index 367ecc6fe9..6d33d9cf7c 100644 --- a/.github/required-checks.yml +++ b/.github/required-checks.yml @@ -9,4 +9,4 @@ checks: - i18n / completeness - Check Generator Templates - Test Generator - - Validate required checks + - Required checks diff --git a/.github/workflows/required-checks.yml b/.github/workflows/required-checks.yml index 55aa28d4ff..2d841b4336 100644 --- a/.github/workflows/required-checks.yml +++ b/.github/workflows/required-checks.yml @@ -14,7 +14,7 @@ permissions: {} jobs: validate: - name: Validate required checks + name: Required checks runs-on: ubuntu-24.04 timeout-minutes: 45 permissions: @@ -29,7 +29,7 @@ jobs: BASE_SHA: ${{ github.event.pull_request.base.sha }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} PR_NUMBER: ${{ github.event.pull_request.number }} - OWN_CHECK_NAME: Validate required checks + OWN_CHECK_NAME: Required checks shell: ruby {0} run: | require "json" From bb477f10442cd8c01f6cb91e13f526b56f59ef15 Mon Sep 17 00:00:00 2001 From: Jeremy Walker Date: Sun, 8 Nov 2026 13:41:38 +0900 Subject: [PATCH 6/8] Go back to naming the validation check "Validate required checks" This reverts commit 6c2443a1. Co-Authored-By: Claude Opus 5.5 --- .github/required-checks.yml | 2 +- .github/workflows/required-checks.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/required-checks.yml b/.github/required-checks.yml index 6d33d9cf7c..367ecc6fe9 100644 --- a/.github/required-checks.yml +++ b/.github/required-checks.yml @@ -9,4 +9,4 @@ checks: - i18n / completeness - Check Generator Templates - Test Generator - - Required checks + - Validate required checks diff --git a/.github/workflows/required-checks.yml b/.github/workflows/required-checks.yml index 2d841b4336..55aa28d4ff 100644 --- a/.github/workflows/required-checks.yml +++ b/.github/workflows/required-checks.yml @@ -14,7 +14,7 @@ permissions: {} jobs: validate: - name: Required checks + name: Validate required checks runs-on: ubuntu-24.04 timeout-minutes: 45 permissions: @@ -29,7 +29,7 @@ jobs: BASE_SHA: ${{ github.event.pull_request.base.sha }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} PR_NUMBER: ${{ github.event.pull_request.number }} - OWN_CHECK_NAME: Required checks + OWN_CHECK_NAME: Validate required checks shell: ruby {0} run: | require "json" From 63ba165e154cb025e0b54b2d311e485998703703 Mon Sep 17 00:00:00 2001 From: Jeremy Walker Date: Sun, 8 Nov 2026 13:43:59 +0900 Subject: [PATCH 7/8] Don't look for the validation check among the checks it waits for It lists itself in required-checks.yml, but it leaves itself out of the checks it waits for, so it reported its own name as missing. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/required-checks.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/required-checks.yml b/.github/workflows/required-checks.yml index 55aa28d4ff..ac2907c112 100644 --- a/.github/workflows/required-checks.yml +++ b/.github/workflows/required-checks.yml @@ -120,6 +120,8 @@ jobs: problems = [] (wanted | on_main).each do |name, app| + # This check is running now, so it doesn't need to be found among the others + next if name == OWN_CHECK_NAME next if ran.include?([name, app]) if on_main.include?([name, app]) From 2457f25e5a2729bb3c32c82d13ee85f6799275b2 Mon Sep 17 00:00:00 2001 From: Jeremy Walker Date: Sun, 8 Nov 2026 13:46:11 +0900 Subject: [PATCH 8/8] Wait at least 30 seconds, then check every 5 seconds Co-Authored-By: Claude Opus 5.5 --- .github/workflows/required-checks.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/required-checks.yml b/.github/workflows/required-checks.yml index ac2907c112..e6db2f8519 100644 --- a/.github/workflows/required-checks.yml +++ b/.github/workflows/required-checks.yml @@ -98,8 +98,8 @@ jobs: end # Wait for the PR's other checks to finish. Some checks start a little - # after this one, so wait at least a minute, and stop only when two - # polls in a row find nothing running. + # after this one, so wait at least 30 seconds, then check every 5 seconds. + # Stop only when two checks in a row find nothing running. started = Time.now quiet_polls = 0 runs = [] @@ -110,10 +110,10 @@ jobs: runs = JSON.parse(output).flat_map { |page| page["check_runs"] }.reject { |run| run["name"] == OWN_CHECK_NAME } running = runs.reject { |run| run["status"] == "completed" } quiet_polls = running.empty? ? quiet_polls + 1 : 0 - break if quiet_polls >= 2 && Time.now - started >= 60 + break if quiet_polls >= 2 && Time.now - started >= 30 puts "Waiting for: #{running.map { |run| run["name"] }.uniq.join(', ')}" unless running.empty? - sleep 20 + sleep 5 end ran = runs.map { |run| [run["name"], run.dig("app", "id")] }.uniq