diff --git a/.github/scripts/integration-governance.cjs b/.github/scripts/integration-governance.cjs index f855b1d469..1d33203b46 100644 --- a/.github/scripts/integration-governance.cjs +++ b/.github/scripts/integration-governance.cjs @@ -9,7 +9,7 @@ const MAX_COMMITS = 1000; const MAX_AUTHOR_BATCH = 50; // This literal is inside the enrolled .github closure. A caller-supplied // preparedBy.sourceSHA must never choose a new executable verifier tree. -const TRUSTED_SCRIPTS_TREE = '22b8f6c54d4b00a9d1193a5e2416591691177970'; +const TRUSTED_SCRIPTS_TREE = '262f909fd6e9874f9e37665e82347031b3d873f4'; const SOURCE = 'https://github.com/kubernetes-sigs/kubebuilder-release-tools/tree/012269a88fa4c034a0acf1ba84c26b195c0dbab4'; const sha = value => crypto.createHash('sha256').update(value).digest('hex'); const git = (args, cwd = process.cwd()) => diff --git a/.github/workflows/cli-pin-bump.yml b/.github/workflows/cli-pin-bump.yml index ccd98e1053..b445e0509f 100644 --- a/.github/workflows/cli-pin-bump.yml +++ b/.github/workflows/cli-pin-bump.yml @@ -64,6 +64,8 @@ on: - '.github/workflows/cli-pin-bump.yml' - 'src/scripts/cli-pin-bump.sh' - 'src/scripts/test-cli-pin-bump.sh' + - 'src/scripts/cli-pin-signoff.sh' + - 'src/scripts/test-cli-pin-signoff.sh' - 'src/scripts/check-cli-model-lists.sh' - 'src/scripts/test-check-cli-model-lists.sh' - 'src/scripts/cli-model-requirements.txt' @@ -95,6 +97,9 @@ jobs: bash -n src/scripts/test-cli-pin-bump.sh bash -n .github/scripts/check-bob-launch-flags.sh bash src/scripts/test-cli-pin-bump.sh + bash -n src/scripts/cli-pin-signoff.sh + bash -n src/scripts/test-cli-pin-signoff.sh + bash src/scripts/test-cli-pin-signoff.sh bash -n src/scripts/check-cli-model-lists.sh bash -n src/scripts/test-check-cli-model-lists.sh bash src/scripts/test-check-cli-model-lists.sh @@ -279,8 +284,22 @@ jobs: echo "::error::Could not resolve the TOPUP_PUSH_TOKEN owner; a PR it opens would squash to a mismatched-signoff (#11412)." exit 1 fi - git commit --amend --no-edit \ - --trailer "Signed-off-by: ${login} <${id}+${login}@users.noreply.github.com>" + # The squash is authored under the owner's PRIMARY email, which is + # not the noreply one, so the DCO app flagged every bump on the + # v5 -> v6 top-up (#18697). Sign off for each address GitHub may + # attribute (public profile email, then the primary from + # user/emails when the token may read it; best-effort). + emails=() + pub="$(GH_TOKEN="$PR_TOKEN" gh api user --jq '.email // empty' 2>/dev/null || true)" + [ -z "$pub" ] || emails+=("$pub") + while IFS= read -r em; do + [ -z "$em" ] || emails+=("$em") + done < <(GH_TOKEN="$PR_TOKEN" gh api user/emails --jq '.[] | select(.primary) | .email' 2>/dev/null || true) + args=() + while IFS= read -r t; do + [ -z "$t" ] || args+=(--trailer "$t") + done < <(bash src/scripts/cli-pin-signoff.sh "$login" "$id" "${emails[@]}") + git commit --amend --no-edit "${args[@]}" fi git push --force-with-lease origin "$HEAD_BRANCH" diff --git a/changelog.d/fixed-18697-image-bump-dco-signoff.md b/changelog.d/fixed-18697-image-bump-dco-signoff.md new file mode 100644 index 0000000000..77cdabb1f6 --- /dev/null +++ b/changelog.d/fixed-18697-image-bump-dco-signoff.md @@ -0,0 +1 @@ +- The CLI pin-bump workflow now signs its commit off for every email GitHub may attribute the squash to (the `TOPUP_PUSH_TOKEN` owner's public and primary addresses, not only the noreply one), so the DCO app no longer flags image-bump commits and blocks v5 -> v6 top-ups (#18697). diff --git a/src/scripts/cli-pin-signoff.sh b/src/scripts/cli-pin-signoff.sh new file mode 100755 index 0000000000..d864f129f9 --- /dev/null +++ b/src/scripts/cli-pin-signoff.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# Prints the extra Signed-off-by trailers a cli-pin-bump commit needs so the +# probot DCO rule passes on the commit GitHub's squash writes (#18697). +# +# Usage: cli-pin-signoff.sh LOGIN ID [EMAIL...] +# +# The squash commit is authored as the PR opener (the TOPUP_PUSH_TOKEN owner), +# under whatever email GitHub attributes to them: their primary address, which +# is not the users.noreply.github.com one. The DCO app wants the AUTHOR email +# in a Signed-off-by, so emit one trailer per distinct email: the noreply +# identity first (always valid), then each real address supplied. Empty, +# "null" and malformed emails are skipped; duplicates are dropped. +set -euo pipefail + +login="${1:?login required}" +id="${2:?id required}" +shift 2 + +declare -A seen=() +emit() { + local email="${1,,}" + [ -n "$email" ] && [ "$email" != "null" ] || return 0 + [[ "$email" =~ ^[^[:space:]@\<\>]+@[^[:space:]@\<\>]+$ ]] || return 0 + [ -z "${seen[$email]:-}" ] || return 0 + seen[$email]=1 + printf 'Signed-off-by: %s <%s>\n' "$login" "$1" +} + +emit "${id}+${login}@users.noreply.github.com" +for e in "$@"; do emit "$e"; done diff --git a/src/scripts/test-cli-pin-signoff.sh b/src/scripts/test-cli-pin-signoff.sh new file mode 100755 index 0000000000..62af4a489d --- /dev/null +++ b/src/scripts/test-cli-pin-signoff.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# Self-test for cli-pin-signoff.sh (#18697). No network. Builds a commit the way +# the bump workflow does (bot author + bot sign-off, then the extra trailers) +# and applies the probot DCO rule to the commit GitHub's squash would write: +# the author email must appear in some Signed-off-by trailer. +set -euo pipefail + +HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SCRIPT="$HERE/cli-pin-signoff.sh" +PASS=0; FAIL=0 +pass() { PASS=$((PASS+1)); echo " ok: $1"; } +fail() { FAIL=$((FAIL+1)); echo " FAIL: $1"; } + +TMP="$(mktemp -d)" +trap 'rm -rf "$TMP"' EXIT + +# dco_ok AUTHOR_EMAIL MESSAGE: probot/dco's rule, case-insensitive. +dco_ok() { + printf '%s\n' "$2" | grep -iE '^Signed-off-by: .*<'"$1"'>[[:space:]]*$' >/dev/null +} + +build_msg() { + local login="$1" id="$2"; shift 2 + git init -q "$TMP/r" + ( + cd "$TMP/r" + # Exported so the --amend below has a committer too: CI runners have no + # global git identity. + export GIT_AUTHOR_NAME="hive-release[bot]" GIT_AUTHOR_EMAIL="hive-release@hive.kubestellar.io" + export GIT_COMMITTER_NAME="hive-release[bot]" GIT_COMMITTER_EMAIL="hive-release@hive.kubestellar.io" + git commit -q --allow-empty -s -m "images: bump x 1 -> 2" + trailers="$(bash "$SCRIPT" "$login" "$id" "$@")" + args=() + while IFS= read -r t; do [ -n "$t" ] && args+=(--trailer "$t"); done <<<"$trailers" + git commit -q --amend --allow-empty --no-edit "${args[@]}" + git log -1 --format=%B + ) + rm -rf "$TMP/r" +} + +msg="$(build_msg clubanderson 407614 andy@clubanderson.com null "" Andy@ClubAnderson.com)" +dco_ok 'andy@clubanderson\.com' "$msg" && pass "primary author email is signed off" || fail "primary author email missing" +dco_ok '407614\+clubanderson@users\.noreply\.github\.com' "$msg" && pass "noreply identity signed off" || fail "noreply missing" +dco_ok 'hive-release@hive\.kubestellar\.io' "$msg" && pass "bot sign-off kept" || fail "bot sign-off lost" +[ "$(grep -ic '^Signed-off-by: .*andy@clubanderson' <<<"$msg")" = 1 ] && pass "duplicate/null/empty emails dropped" || fail "duplicate trailer" + +msg="$(build_msg someone 5)" +if dco_ok 'andy@clubanderson\.com' "$msg"; then fail "unrelated author wrongly matched"; else pass "no email supplied -> only noreply (author without sign-off is still detected)"; fi + +echo "$PASS passed, $FAIL failed" +[ "$FAIL" = 0 ]