From: David Galloway Date: Mon, 15 Jun 2026 20:57:34 +0000 (-0400) Subject: PR checks: Send status updates if manually triggered X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e8d9b7d195697c1b401b01f52aea1158ed1d8971;p=ceph-build.git PR checks: Send status updates if manually triggered Signed-off-by: David Galloway --- diff --git a/ceph-pr-api/build/build b/ceph-pr-api/build/build index 44b81dcd7..f20872743 100644 --- a/ceph-pr-api/build/build +++ b/ceph-pr-api/build/build @@ -4,6 +4,16 @@ if [[ "${ROOT_BUILD_CAUSE}" == "MANUALTRIGGER" ]]; then ghprbGhRepository="ceph/ceph" fi +# For manually-triggered jobs, report the final result back to GitHub as a +# commit status (webhook-triggered jobs get this from the PR Builder plugin). +# Installed as an EXIT trap so it fires no matter which stage (make check, dep +# install, or API tests) the job exits on, including the docs-only early exit +# below (which reports success). +trap 'report_github_pr_status $? "ceph API tests"' EXIT + +# Report that the job has started (manual triggers only). +update_github_pr_status "pending" "running API tests" "ceph API tests" + docs_pr_only container_pr_only gha_pr_only diff --git a/ceph-pr-api/config/definitions/ceph-pr-api.yml b/ceph-pr-api/config/definitions/ceph-pr-api.yml index dfca61988..45b978162 100644 --- a/ceph-pr-api/config/definitions/ceph-pr-api.yml +++ b/ceph-pr-api/config/definitions/ceph-pr-api.yml @@ -90,6 +90,10 @@ credential-id: github-readonly-token username: GITHUB_USER password: GITHUB_PASS + - username-password-separated: + credential-id: github-status-check-token + username: GITHUB_STATUS_USER + password: GITHUB_STATUS_TOKEN - project: name: ceph-api-project diff --git a/ceph-pull-requests-arm64/build/build b/ceph-pull-requests-arm64/build/build index e58675092..1c69f2f61 100644 --- a/ceph-pull-requests-arm64/build/build +++ b/ceph-pull-requests-arm64/build/build @@ -1,5 +1,14 @@ #!/bin/bash -ex +# For manually-triggered jobs, report the final result back to GitHub as a +# commit status (webhook-triggered jobs get this from the PR Builder plugin). +# Installed as an EXIT trap so it fires no matter where the job exits, including +# the docs-only early exit below (which reports success). +trap 'report_github_pr_status $? "make check (arm64)" "make check"' EXIT + +# Report that the job has started (manual triggers only). +update_github_pr_status "pending" "running make check" "make check (arm64)" + docs_pr_only container_pr_only gha_pr_only @@ -26,3 +35,14 @@ bwc 4 -e tests npm_cache_info sleep 5 ps -ef | grep -v jnlp | grep ceph || true + +# `bwc -e tests` exits 0 even when individual tests fail so that the CTest +# results are always published; the xUnit publisher is what fails the build (its +# threshold fails on any failed test). A non-test failure (e.g. compile) would +# have aborted above under `set -e`. Mirror xUnit here so the EXIT trap reports +# the matching GitHub status for manual triggers. +test_xml="$(find build/Testing -name Test.xml 2>/dev/null)" +if [ -n "$test_xml" ] && grep -q 'Status="failed"' $test_xml; then + echo "CTest reported one or more failed tests; marking the build as failed." + exit 1 +fi diff --git a/ceph-pull-requests-arm64/config/definitions/ceph-pull-requests-arm64.yml b/ceph-pull-requests-arm64/config/definitions/ceph-pull-requests-arm64.yml index 73d00ca96..34871a060 100644 --- a/ceph-pull-requests-arm64/config/definitions/ceph-pull-requests-arm64.yml +++ b/ceph-pull-requests-arm64/config/definitions/ceph-pull-requests-arm64.yml @@ -116,6 +116,10 @@ credential-id: github-readonly-token username: GITHUB_USER password: GITHUB_PASS + - username-password-separated: + credential-id: github-status-check-token + username: GITHUB_STATUS_USER + password: GITHUB_STATUS_TOKEN - username-password-separated: credential-id: dgalloway-docker-hub username: DOCKER_HUB_USERNAME diff --git a/ceph-pull-requests/build/build b/ceph-pull-requests/build/build index ec8cc8071..02bb2b036 100644 --- a/ceph-pull-requests/build/build +++ b/ceph-pull-requests/build/build @@ -1,5 +1,14 @@ #!/bin/bash -ex +# For manually-triggered jobs, report the final result back to GitHub as a +# commit status (webhook-triggered jobs get this from the PR Builder plugin). +# Installed as an EXIT trap so it fires no matter where the job exits, including +# the docs-only early exit below (which reports success). +trap 'report_github_pr_status $? "make check"' EXIT + +# Report that the job has started (manual triggers only). +update_github_pr_status "pending" "running make check" "make check" + docs_pr_only container_pr_only gha_pr_only @@ -25,3 +34,14 @@ bwc 4 -e tests npm_cache_info sleep 5 ps -ef | grep -v jnlp | grep ceph || true + +# `bwc -e tests` exits 0 even when individual tests fail so that the CTest +# results are always published; the xUnit publisher is what fails the build (its +# threshold fails on any failed test). A non-test failure (e.g. compile) would +# have aborted above under `set -e`. Mirror xUnit here so the EXIT trap reports +# the matching GitHub status for manual triggers. +test_xml="$(find build/Testing -name Test.xml 2>/dev/null)" +if [ -n "$test_xml" ] && grep -q 'Status="failed"' $test_xml; then + echo "CTest reported one or more failed tests; marking the build as failed." + exit 1 +fi diff --git a/ceph-pull-requests/config/definitions/ceph-pull-requests.yml b/ceph-pull-requests/config/definitions/ceph-pull-requests.yml index 9fc86f970..bd1904ec6 100644 --- a/ceph-pull-requests/config/definitions/ceph-pull-requests.yml +++ b/ceph-pull-requests/config/definitions/ceph-pull-requests.yml @@ -126,6 +126,10 @@ credential-id: github-readonly-token username: GITHUB_USER password: GITHUB_PASS + - username-password-separated: + credential-id: github-status-check-token + username: GITHUB_STATUS_USER + password: GITHUB_STATUS_TOKEN - username-password-separated: credential-id: dgalloway-docker-hub username: DOCKER_HUB_USERNAME diff --git a/ceph-windows-pull-requests/build/check_docs_pr_only b/ceph-windows-pull-requests/build/check_docs_pr_only index 82854b8b3..76166abea 100644 --- a/ceph-windows-pull-requests/build/check_docs_pr_only +++ b/ceph-windows-pull-requests/build/check_docs_pr_only @@ -2,6 +2,16 @@ set -o errexit set -o pipefail +# For manually-triggered jobs, report the final result back to GitHub as a +# commit status (webhook-triggered jobs get this from the PR Builder plugin). +# Installed as an EXIT trap so a failure anywhere in the setup stages (or the +# docs-only early exit below) is reported. Note: run_tests installs its own +# EXIT trap later in the chain which supersedes this one and also reports. +trap 'report_github_pr_status $? "ceph windows tests"' EXIT + +# Report that the job has started (manual triggers only). +update_github_pr_status "pending" "running ceph windows tests" "ceph windows tests" + docs_pr_only container_pr_only gha_pr_only diff --git a/ceph-windows-pull-requests/config/definitions/ceph-windows-pull-requests.yml b/ceph-windows-pull-requests/config/definitions/ceph-windows-pull-requests.yml index 184852291..233625475 100644 --- a/ceph-windows-pull-requests/config/definitions/ceph-windows-pull-requests.yml +++ b/ceph-windows-pull-requests/config/definitions/ceph-windows-pull-requests.yml @@ -109,3 +109,7 @@ credential-id: github-readonly-token username: GITHUB_USER password: GITHUB_PASS + - username-password-separated: + credential-id: github-status-check-token + username: GITHUB_STATUS_USER + password: GITHUB_STATUS_TOKEN diff --git a/scripts/build_utils.sh b/scripts/build_utils.sh index 907dc6ab8..b8d173698 100755 --- a/scripts/build_utils.sh +++ b/scripts/build_utils.sh @@ -1250,6 +1250,76 @@ github_status_setup() { } +# Report a Pull Request job's result back to GitHub as a commit status (check). +# The GitHub Pull Request Builder plugin does this automatically when a webhook +# triggers the job, but manually-triggered jobs don't get that, so post the +# status directly via the GitHub API. +# $1 - state: one of pending, success, failure, error +# $2 - description shown alongside the check (optional) +# $3 - status context/name (optional, defaults to "make check") +# $4 - target URL the check links to in the GitHub UI (optional, defaults to +# this Jenkins build's URL) +update_github_pr_status() { + local state=$1 + local description=$2 + local context=${3:-"make check"} + # Link the check back to this Jenkins build so clicking the context in the + # GitHub UI opens the job. + local target_url=${4:-$BUILD_URL} + + # Only post a status for manually-triggered jobs. Webhook-triggered jobs + # already have their status managed by the GitHub Pull Request Builder plugin, + # so posting here would just be a duplicate. Check ROOT_BUILD_CAUSE too so a + # job kicked off down an upstream chain from a manual trigger is still covered. + if [ "$BUILD_CAUSE" != "MANUALTRIGGER" ] && [ "$ROOT_BUILD_CAUSE" != "MANUALTRIGGER" ]; then + return 0 + fi + + # Manually-triggered jobs don't have the ghprb* variables set by the plugin. + # Assume ceph/ceph and look up the PR's head commit from the GitHub API. + ghprbGhRepository="ceph/ceph" + ghprbActualCommit="$(curl -s -u ${GITHUB_USER}:${GITHUB_PASS} https://api.github.com/repos/${ghprbGhRepository}/pulls/${ghprbPullId} | jq -r '.head.sha')" + + if [ -z "$ghprbActualCommit" ] || [ -z "$ghprbGhRepository" ]; then + echo "Could not determine commit or repository; skipping GitHub status update" + return 0 + fi + + echo "Setting GitHub status '$context' to '$state' for ${ghprbGhRepository}@${ghprbActualCommit}" + # Posting a status needs a token with write access, unlike the read-only token + # in GITHUB_USER/GITHUB_PASS used for the lookup above. + curl -s -u ${GITHUB_STATUS_USER}:${GITHUB_STATUS_TOKEN} \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/${ghprbGhRepository}/statuses/${ghprbActualCommit}" \ + -d "$(jq -n \ + --arg state "$state" \ + --arg target_url "$target_url" \ + --arg description "$description" \ + --arg context "$context" \ + '{state: $state, target_url: $target_url, description: $description, context: $context}')" +} + +# Convenience wrapper meant to be installed as a bash EXIT trap so a Pull Request +# job reports its overall pass/fail to GitHub regardless of which stage failed. +# Like update_github_pr_status, it's a no-op unless the job was triggered +# manually. Pass $? explicitly from the trap so the exit code is captured before +# anything in this function clobbers it, e.g.: +# trap 'report_github_pr_status $? "make check"' EXIT +# $1 - exit code (0 == success) +# $2 - status context/name (e.g. "make check (arm64)") +# $3 - label used in the description (optional, defaults to $2) +report_github_pr_status() { + local rc=$1 + local context=$2 + local label=${3:-$context} + if [ "$rc" -eq 0 ]; then + update_github_pr_status "success" "$label succeeded" "$context" + else + update_github_pr_status "failure" "$label failed" "$context" + fi +} + write_collect_logs_playbook() { cat > $WORKSPACE/collect-logs.yml << EOF - hosts: all diff --git a/scripts/ceph-windows/run_tests b/scripts/ceph-windows/run_tests index 6e2da2d79..f6e40f22e 100644 --- a/scripts/ceph-windows/run_tests +++ b/scripts/ceph-windows/run_tests @@ -85,7 +85,17 @@ function collect_artifacts() { scp_download /workspace/eventlogs $WORKSPACE/artifacts/client/eventlogs echo "Successfully retrieved artifacts." } -trap collect_artifacts EXIT +# +# On exit, report the result to GitHub (manual triggers only) and then collect +# artifacts. $? is captured first so the job's real exit code is reported +# before anything in the trap clobbers it. +# +function on_exit() { + local rc=$? + report_github_pr_status $rc "ceph windows tests" + collect_artifacts +} +trap on_exit EXIT # View cluster status before test run SSH_USER=$UBUNTU_SSH_USER SSH_ADDRESS=$UBUNTU_VM_IP ssh_exec ./ceph/build/bin/ceph status