-
-
Notifications
You must be signed in to change notification settings - Fork 629
Require hosted CI for generator PRs #4149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||
| #!/usr/bin/env bash | ||||||||||||
| # Fails the required PR gate when generator-sensitive changes have not requested | ||||||||||||
| # hosted CI. Keep this small: ci-required must stay fast and deterministic. | ||||||||||||
|
|
||||||||||||
| set -euo pipefail | ||||||||||||
|
|
||||||||||||
| event_name="${GITHUB_EVENT_NAME:-}" | ||||||||||||
| run_generators="${RUN_GENERATORS:-false}" | ||||||||||||
| should_run_hosted_ci="${SHOULD_RUN_HOSTED_CI:-false}" | ||||||||||||
|
|
||||||||||||
| if [ "$event_name" = "pull_request" ] && | ||||||||||||
| [ "$run_generators" = "true" ] && | ||||||||||||
| [ "$should_run_hosted_ci" != "true" ]; then | ||||||||||||
| cat >&2 <<'MSG' | ||||||||||||
| Generator changes require hosted CI before merge. | ||||||||||||
|
|
||||||||||||
| This PR changes generator-sensitive paths, but hosted CI has not been requested. | ||||||||||||
| Comment +ci-run-hosted on the PR, or add the ready-for-hosted-ci label with a maintainer/user token. | ||||||||||||
| Then wait for the hosted generator checks before merging. | ||||||||||||
| MSG | ||||||||||||
| exit 1 | ||||||||||||
| fi | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file ends without an explicit
Suggested change
|
||||||||||||
|
|
||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant with
Suggested change
|
||||||||||||
| exit 0 | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant —
Suggested change
|
||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,113 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||||||||||||||||||
| # Test harness for script/ci-required-hosted-gate. | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| set -uo pipefail | ||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||||||||||||||||||||||||||||||||||||||||||||
| GATE="$SCRIPT_DIR/ci-required-hosted-gate" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| TESTS_RUN=0 | ||||||||||||||||||||||||||||||||||||||||||||
| TESTS_FAILED=0 | ||||||||||||||||||||||||||||||||||||||||||||
| FAILURES=() | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| fail() { | ||||||||||||||||||||||||||||||||||||||||||||
| local message="$1" | ||||||||||||||||||||||||||||||||||||||||||||
| TESTS_FAILED=$((TESTS_FAILED + 1)) | ||||||||||||||||||||||||||||||||||||||||||||
| FAILURES+=("$message") | ||||||||||||||||||||||||||||||||||||||||||||
| echo " FAIL: $message" >&2 | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| assert_contains() { | ||||||||||||||||||||||||||||||||||||||||||||
| local haystack="$1" | ||||||||||||||||||||||||||||||||||||||||||||
| local needle="$2" | ||||||||||||||||||||||||||||||||||||||||||||
| local label="$3" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| case "$haystack" in | ||||||||||||||||||||||||||||||||||||||||||||
| *"$needle"*) ;; | ||||||||||||||||||||||||||||||||||||||||||||
| *) fail "$label: expected '$needle' in '$haystack'" ;; | ||||||||||||||||||||||||||||||||||||||||||||
| esac | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| run_case() { | ||||||||||||||||||||||||||||||||||||||||||||
| local name="$1" | ||||||||||||||||||||||||||||||||||||||||||||
| local expected_rc="$2" | ||||||||||||||||||||||||||||||||||||||||||||
| local event_name="$3" | ||||||||||||||||||||||||||||||||||||||||||||
| local run_generators="$4" | ||||||||||||||||||||||||||||||||||||||||||||
| local should_run_hosted_ci="$5" | ||||||||||||||||||||||||||||||||||||||||||||
| local expected_output="${6:-}" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| TESTS_RUN=$((TESTS_RUN + 1)) | ||||||||||||||||||||||||||||||||||||||||||||
| echo "-> $name" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| local output rc | ||||||||||||||||||||||||||||||||||||||||||||
| set +e | ||||||||||||||||||||||||||||||||||||||||||||
| output="$( | ||||||||||||||||||||||||||||||||||||||||||||
| GITHUB_EVENT_NAME="$event_name" \ | ||||||||||||||||||||||||||||||||||||||||||||
| RUN_GENERATORS="$run_generators" \ | ||||||||||||||||||||||||||||||||||||||||||||
| SHOULD_RUN_HOSTED_CI="$should_run_hosted_ci" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "$GATE" 2>&1 | ||||||||||||||||||||||||||||||||||||||||||||
| )" | ||||||||||||||||||||||||||||||||||||||||||||
| rc=$? | ||||||||||||||||||||||||||||||||||||||||||||
| set -e | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if [ "$rc" -ne "$expected_rc" ]; then | ||||||||||||||||||||||||||||||||||||||||||||
| fail "$name: expected exit $expected_rc, got $rc; output: $output" | ||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if [ -n "$expected_output" ]; then | ||||||||||||||||||||||||||||||||||||||||||||
| assert_contains "$output" "$expected_output" "$name" | ||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| run_case \ | ||||||||||||||||||||||||||||||||||||||||||||
| "blocks generator pull requests without hosted CI" \ | ||||||||||||||||||||||||||||||||||||||||||||
| 1 \ | ||||||||||||||||||||||||||||||||||||||||||||
| "pull_request" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "true" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "false" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "Generator changes require hosted CI before merge." | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| run_case \ | ||||||||||||||||||||||||||||||||||||||||||||
| "allows generator pull requests once hosted CI is requested" \ | ||||||||||||||||||||||||||||||||||||||||||||
| 0 \ | ||||||||||||||||||||||||||||||||||||||||||||
| "pull_request" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "true" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "true" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| run_case \ | ||||||||||||||||||||||||||||||||||||||||||||
| "allows ordinary pull requests without hosted CI" \ | ||||||||||||||||||||||||||||||||||||||||||||
| 0 \ | ||||||||||||||||||||||||||||||||||||||||||||
| "pull_request" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "false" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "false" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| run_case \ | ||||||||||||||||||||||||||||||||||||||||||||
| "allows merge queue generator checks" \ | ||||||||||||||||||||||||||||||||||||||||||||
| 0 \ | ||||||||||||||||||||||||||||||||||||||||||||
| "merge_group" \ | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+80
to
+87
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The merge queue test passes Consider adding a companion case that makes the real invariant explicit:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
| "true" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "true" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| run_case \ | ||||||||||||||||||||||||||||||||||||||||||||
| "allows merge queue generator checks even without hosted PR state" \ | ||||||||||||||||||||||||||||||||||||||||||||
| 0 \ | ||||||||||||||||||||||||||||||||||||||||||||
| "merge_group" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "true" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "false" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| run_case \ | ||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This combination ( |
||||||||||||||||||||||||||||||||||||||||||||
| "allows non pull request events with unset event name" \ | ||||||||||||||||||||||||||||||||||||||||||||
| 0 \ | ||||||||||||||||||||||||||||||||||||||||||||
| "" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "true" \ | ||||||||||||||||||||||||||||||||||||||||||||
| "false" | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if [ "$TESTS_FAILED" -ne 0 ]; then | ||||||||||||||||||||||||||||||||||||||||||||
| echo | ||||||||||||||||||||||||||||||||||||||||||||
| echo "$TESTS_FAILED of $TESTS_RUN tests failed" | ||||||||||||||||||||||||||||||||||||||||||||
| printf ' - %s\n' "${FAILURES[@]}" | ||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| echo | ||||||||||||||||||||||||||||||||||||||||||||
| echo "$TESTS_RUN tests passed" | ||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no test for an empty or unrecognised run_case \
"allows unrecognised event names (e.g. workflow_dispatch)" \
0 \
"workflow_dispatch" \
"true" \
"false"would pin this and catch any future edit that widens the outer
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR description's Validation section says "4 tests passed", but there are 6 |
||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For generator PRs that use the documented
+ci-run-hostedpath, this instruction does not actually unblock the failed required check: the comment workflow addsready-for-hosted-ciwithGITHUB_TOKEN, and the repo docs note that such label writes do not start newpull_requestworkflow runs, whiletriggerHostedCidispatches only the hosted workflows, notci-required.yml. In that scenario the lastci-required / required-pr-gaterun remains failed until someone pushes, manually reruns/dispatches the gate, or adds the label with a user token, so the primary requested workflow leaves branch protection blocked.Useful? React with 👍 / 👎.