Skip to content

Commit 65c892f

Browse files
committed
fix(ci): report merge train merged alerts against the base branch
1 parent 52c4d30 commit 65c892f

3 files changed

Lines changed: 123 additions & 1 deletion

File tree

.github/workflows/merge-queue-dequeue-notify.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ jobs:
3737
env:
3838
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
3939
REF_NAME: ${{ github.event.pull_request.head.ref }}
40+
TARGET_BRANCH: ${{ github.event.pull_request.base.ref }}
4041
PR_URL: ${{ github.event.pull_request.html_url }}
4142
run: ./ci3/merge_train_failure_slack_notify --merged

ci3/merge_train_failure_slack_notify

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ if [[ "$MODE" == "dequeued" ]]; then
5454
--target-ref "origin/$REF_NAME"
5555

5656
elif [[ "$MODE" == "merged" ]]; then
57-
"$TOPDIR/ci3/slack_notify" "PR merged into $REF_NAME: <$PR_URL|$commit_title> by $commit_author" "$channel"
57+
merged_target="${TARGET_BRANCH:-$REF_NAME}"
58+
"$TOPDIR/ci3/slack_notify" "PR merged into $merged_target: <$PR_URL|$commit_title> by $commit_author" "$channel"
5859

5960
else
6061
"$TOPDIR/ci3/slack_notify_with_claudebox_kickoff" "$channel" \
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
6+
7+
RED=$'\033[0;31m'
8+
GREEN=$'\033[0;32m'
9+
NC=$'\033[0m'
10+
11+
TESTS_PASSED=0
12+
TESTS_FAILED=0
13+
14+
pass() { echo "${GREEN}PASS${NC} $1"; ((TESTS_PASSED++)) || true; }
15+
fail() {
16+
echo "${RED}FAIL${NC} $1: $2"
17+
((TESTS_FAILED++)) || true
18+
}
19+
20+
setup_repo() {
21+
local tmp
22+
tmp=$(mktemp -d)
23+
mkdir -p "$tmp/ci3"
24+
cp "$ROOT/ci3/merge_train_failure_slack_notify" "$tmp/ci3/"
25+
cat > "$tmp/ci3/slack_notify" <<'STUB'
26+
#!/usr/bin/env bash
27+
printf 'slack_notify\n%s\n%s\n' "$1" "$2" > "$TMPDIR/slack_notify.out"
28+
STUB
29+
cat > "$tmp/ci3/slack_notify_with_claudebox_kickoff" <<'STUB'
30+
#!/usr/bin/env bash
31+
printf 'slack_notify_with_claudebox_kickoff\n%s\n%s\n%s\n' "$1" "$2" "$3" > "$TMPDIR/kickoff.out"
32+
STUB
33+
chmod +x "$tmp/ci3/"*
34+
35+
git -C "$tmp" init -q
36+
git -C "$tmp" config user.name "Test Author"
37+
git -C "$tmp" config user.email test@example.com
38+
git -C "$tmp" add ci3
39+
GIT_AUTHOR_NAME="Alice" GIT_AUTHOR_EMAIL=alice@example.com \
40+
GIT_COMMITTER_NAME="Alice" GIT_COMMITTER_EMAIL=alice@example.com \
41+
git -C "$tmp" commit -q -m "feat: example (#123)"
42+
printf '%s\n' "$tmp"
43+
}
44+
45+
test_merged_notification_uses_target_branch() {
46+
local tmp output expected_text expected_channel
47+
tmp=$(setup_repo)
48+
(
49+
cd "$tmp"
50+
TMPDIR="$tmp" REF_NAME="merge-train/spartan-v5" TARGET_BRANCH="v5-next" \
51+
PR_URL="https://github.com/AztecProtocol/aztec-packages/pull/123" \
52+
./ci3/merge_train_failure_slack_notify --merged
53+
)
54+
55+
output=$(cat "$tmp/slack_notify.out")
56+
expected_text="PR merged into v5-next: <https://github.com/AztecProtocol/aztec-packages/pull/123|feat: example (#123)> by Alice"
57+
expected_channel="#team-alpha"
58+
if [[ "$output" == $'slack_notify\n'"$expected_text"$'\n'"$expected_channel" ]]; then
59+
pass "merged notification uses PR base branch"
60+
else
61+
fail "merged notification uses PR base branch" "got: $output"
62+
fi
63+
rm -rf "$tmp"
64+
}
65+
66+
test_merged_notification_falls_back_to_ref_name() {
67+
local tmp output expected_text expected_channel
68+
tmp=$(setup_repo)
69+
(
70+
cd "$tmp"
71+
TMPDIR="$tmp" REF_NAME="merge-train/spartan" \
72+
PR_URL="https://github.com/AztecProtocol/aztec-packages/pull/456" \
73+
./ci3/merge_train_failure_slack_notify --merged
74+
)
75+
76+
output=$(cat "$tmp/slack_notify.out")
77+
expected_text="PR merged into merge-train/spartan: <https://github.com/AztecProtocol/aztec-packages/pull/456|feat: example (#123)> by Alice"
78+
expected_channel="#team-alpha"
79+
if [[ "$output" == $'slack_notify\n'"$expected_text"$'\n'"$expected_channel" ]]; then
80+
pass "merged notification falls back to ref name"
81+
else
82+
fail "merged notification falls back to ref name" "got: $output"
83+
fi
84+
rm -rf "$tmp"
85+
}
86+
87+
test_dequeued_notification_still_names_merge_train() {
88+
local tmp output
89+
tmp=$(setup_repo)
90+
(
91+
cd "$tmp"
92+
TMPDIR="$tmp" REF_NAME="merge-train/spartan-v5" TARGET_BRANCH="v5-next" \
93+
PR_URL="https://github.com/AztecProtocol/aztec-packages/pull/789" \
94+
GITHUB_REPOSITORY="AztecProtocol/aztec-packages" \
95+
./ci3/merge_train_failure_slack_notify --dequeued
96+
)
97+
98+
output=$(cat "$tmp/kickoff.out")
99+
if grep -q "PR was removed from the merge-train/spartan-v5 merge queue" <<< "$output" &&
100+
grep -q "PR was dequeued from merge queue for merge-train/spartan-v5" <<< "$output"; then
101+
pass "dequeued notification still names merge train"
102+
else
103+
fail "dequeued notification still names merge train" "got: $output"
104+
fi
105+
rm -rf "$tmp"
106+
}
107+
108+
echo "=== Merge Train Slack Notify Test Suite ==="
109+
test_merged_notification_uses_target_branch
110+
test_merged_notification_falls_back_to_ref_name
111+
test_dequeued_notification_still_names_merge_train
112+
113+
echo
114+
if [[ $TESTS_FAILED -eq 0 ]]; then
115+
echo "${GREEN}All $TESTS_PASSED tests passed.${NC}"
116+
exit 0
117+
else
118+
echo "${RED}$TESTS_FAILED of $((TESTS_PASSED + TESTS_FAILED)) tests failed.${NC}"
119+
exit 1
120+
fi

0 commit comments

Comments
 (0)