Skip to content

Commit 0ec74d6

Browse files
authored
ci: calmer regen alerts that name breaking tickets, three integration attempts (#185)
1 parent 7a6e4c3 commit 0ec74d6

2 files changed

Lines changed: 35 additions & 8 deletions

File tree

‎.github/workflows/regen.yml‎

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
tag:
1212
description: Protocol release, e.g. openapi-v240.4.0. Empty takes the latest.
1313
required: false
14-
# Each finished integration attempt is handled right away: a pass merges the PR, a first red one is rerun even after the run that pushed has given up waiting, and a red rerun reaches a human.
14+
# Each finished integration attempt is handled right away: a pass merges the PR, a red one is rerun up to three attempts even after the run that pushed has given up waiting, and a third red attempt reaches a human.
1515
workflow_run:
1616
workflows: [Regen integration]
1717
types: [completed]
@@ -95,9 +95,34 @@ jobs:
9595
# Leaves a major to a human, who merges it in a breaking-change window, and disarms any auto-merge so an approval alone cannot merge it.
9696
hold() {
9797
gh pr merge "$num" --disable-auto 2>/dev/null || true
98-
if [ "${2:-}" = quiet ]; then echo "::notice::#$num $1, so a human merges it"; else human "$1, so a human merges it"; fi
98+
if [ "${2:-}" = quiet ]; then echo "::notice::#$num $1, so a human merges it"; else human "$1"; fi
9999
exit 0
100100
}
101+
# The approved breaking-change tickets the spec at commit $1 brings over the spec on $base: tickets new to the Breaking changes check's lists and, when both specs carry lines, tickets that gained a line the footers use. A base spec without a list cannot say which are new, as in that check.
102+
new_tickets() {
103+
local ref tag lines=true
104+
for ref in "$base" "$1"; do
105+
tag=$(gh api "repos/$GITHUB_REPOSITORY/contents/.spec-version?ref=$ref" -H 'Accept: application/vnd.github.raw' | sed -n 's/^spec: //p') && [ -n "$tag" ] || return 1
106+
curl -fsSL "https://raw.githubusercontent.com/GetStream/protocol/$tag/openapi/v2/serverside-api.yaml" -o "$RUNNER_TEMP/tickets-$ref.yaml" || return 1
107+
yq -e '.info."x-stream-breaking-changes"' "$RUNNER_TEMP/tickets-$ref.yaml" > /dev/null 2>&1 || return 1
108+
yq -e '.info."x-stream-breaking-change-lines"' "$RUNNER_TEMP/tickets-$ref.yaml" > /dev/null 2>&1 || lines=false
109+
done
110+
for ref in "$base" "$1"; do
111+
{ yq -r '(.info as $i | ($i."x-stream-breaking-changes".wire // []) + [$i."x-stream-breaking-change-lines" // {} | to_entries | .[] | select(.value.sdk // [] | any_c(test("^stream-sdk-java "))) | .key]) + (.info."x-stream-breaking-changes".go // []) | .[]' "$RUNNER_TEMP/tickets-$ref.yaml" && if [ "$lines" = true ]; then yq -r '.info."x-stream-breaking-change-lines" // {} | to_entries | .[] | .key as $t | (.value.wire // []) + (.value.sdk // [] | map(select(test("^stream-sdk-java ")))) | .[] | $t + "\t" + .' "$RUNNER_TEMP/tickets-$ref.yaml"; fi; } | sort -u > "$RUNNER_TEMP/tickets-$ref" || return 1
112+
done
113+
comm -13 "$RUNNER_TEMP/tickets-$base" "$RUNNER_TEMP/tickets-$1" | cut -f1 | sort -u
114+
}
115+
# What a human judges in a breaking regen at commit $1: the tickets behind it, or that none explains it.
116+
held() {
117+
local t list n
118+
t=$(new_tickets "$1") || { echo "is held as breaking. See the PR body and the Breaking changes check"; return; }
119+
[ -n "$t" ] || { echo "is held as breaking, but no approved ticket explains it. See the PR body and the Breaking changes check"; return; }
120+
list=$(head -3 <<< "$t" | while read -r id date; do printf '<https://linear.app/stream/issue/%s|%s %s>, ' "$id" "$id" "$date"; done)
121+
list=${list%, }
122+
n=$(wc -l <<< "$t")
123+
if [ "$n" -gt 3 ]; then list="$list and $((n - 3)) more"; fi
124+
echo "is held as breaking: $list. Label sdk-not-breaking if no customer can hit them, otherwise hold for the next window"
125+
}
101126
# Whether a human took the open `!` PR: a `!` the regen wrote moves on with each newer tag, and a human takes the PR by renaming it or editing its body. A read error stops the run rather than overwrite their edit.
102127
took() {
103128
[[ $(gh pr view "$num" --json title --jq .title) =~ $bang ]] || return 1
@@ -120,7 +145,7 @@ jobs:
120145
# Posted when this run changed the PR's breaking changes ($prev is the body it replaced), not on every run that finds them unchanged.
121146
if grep -q '^BREAKING CHANGE: ' <<< "$body"; then
122147
if [ "$(grep '^BREAKING CHANGE: ' <<< "$body")" = "$(grep '^BREAKING CHANGE: ' <<< "${prev-$body}" || true)" ]; then hold "carries breaking changes" quiet; fi
123-
hold "carries breaking changes"
148+
hold "$(held "$1")"
124149
fi
125150
for _ in $(seq 45); do
126151
sleep 60
@@ -138,10 +163,12 @@ jobs:
138163
conclusion=${state#completed/}
139164
case $state in
140165
completed/success) ;;
141-
# The shared app and the repo-wide run-integration concurrency group, which drops a queued run, make a first red or cancelled run often not the regen's fault. The workflow_run trigger merges once the rerun passes.
166+
# The shared app and the repo-wide run-integration concurrency group, which drops a queued run, make a red or cancelled run often not the regen's fault, so up to three attempts run before a human is asked. The workflow_run trigger merges once a rerun passes.
142167
completed/*)
143-
if [ "$attempt" = 1 ] && GH_TOKEN=$CHECKS_TOKEN gh run rerun "$id"; then echo "::notice::#$num reran its integration tests after a $conclusion, and a pass merges it"; exit 0; fi
144-
human "has integration tests that ended in $conclusion on attempt $attempt, so a human takes it from here"
168+
if [ "$attempt" -lt 3 ]; then
169+
if GH_TOKEN=$CHECKS_TOKEN gh run rerun "$id"; then echo "::notice::#$num reran its integration tests after a $conclusion on attempt $attempt, and a pass merges it"; exit 0; fi
170+
human "is waiting: its integration tests ended in $conclusion on attempt $attempt and could not be rerun. SDK bot needs a human to check"
171+
else human "is waiting: integration tests failed after several retries. SDK bot needs a human to check"; fi
145172
if [ "$GITHUB_EVENT_NAME" = workflow_run ]; then echo "ping=true" >> "$GITHUB_OUTPUT"; fi
146173
exit 0 ;;
147174
''|queued/|in_progress/|waiting/|pending/|requested/) continue ;;
@@ -285,4 +312,4 @@ jobs:
285312
if [ -z "$SLACK_WEBHOOK_URL" ]; then echo "SLACK_WEBHOOK_URL is not set, so nothing is posted"; exit 0; fi
286313
mention=
287314
if [ "$PING" = true ] || [ -z "$NOTE" ]; then mention='<!subteam^S0CE4DYJ9SA> '; fi
288-
jq -n --arg text "${mention}:warning: stream-sdk-java auto-regen ${NOTE:-failed}. <$RUN|Details>" '{text: $text}' | curl -fsS -X POST -H 'Content-Type: application/json' --data @- "$SLACK_WEBHOOK_URL"
315+
jq -n --arg text "${mention}stream-sdk-java regen ${NOTE:-failed}. <$RUN|Details>" '{text: $text}' | curl -fsS -X POST -H 'Content-Type: application/json' --data @- "$SLACK_WEBHOOK_URL"

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ A regen PR waits for a human when its changelog carries a `BREAKING CHANGE:` foo
140140
- **Regenerate now:** run **Regenerate** from the Actions tab with an `openapi-vX` tag, or leave it empty for the latest. Locally, `SPEC_TAG=openapi-vX ./generate.sh` does the same with the generator built from a `../chat` checkout at that tag.
141141
- **A breaking change that breaks this SDK:** when the regen titled the PR `feat!:`, review its footers. It moves on to each newer spec until you rename the PR or edit its body, which keeps it on the spec you judged. Otherwise add `!` to the PR title, and before `END_COMMIT_OVERRIDE` add a blank line and `BREAKING CHANGE: <what breaks for customers>`. Then merge it yourself in a breaking-change window, with a `MIGRATION_vX_to_vY.md` guide.
142142
- **An approved breaking change that does not break this SDK:** label the PR `sdk-not-breaking` and name each ticket the check lists in the PR body. When the regen titled it `feat!:`, also drop the `!` and delete the entries that carry a `BREAKING CHANGE:` footer. The next Regenerate run merges it, daily at 06:23 UTC or when you start one.
143-
- **Failed integration tests:** the tests share their Stream app with other SDKs' CI, so the Regenerate run reruns a red or cancelled **Regen integration** run once by itself, and merges the PR when the rerun passes. If the rerun is red too, fix the cause or rerun it again; a pass merges the PR. If no run started for the PR's head commit, start **Regen integration** on `regen/auto` from the Actions tab.
143+
- **Failed integration tests:** the tests share their Stream app with other SDKs' CI, so the Regenerate run reruns a red or cancelled **Regen integration** run by itself for up to three attempts, and merges the PR when one passes. If the third attempt is red too, it pings the group: fix the cause or rerun it again; a pass merges the PR. If no run started for the PR's head commit, start **Regen integration** on `regen/auto` from the Actions tab.
144144
- **Rewrite a changelog line:** edit the `BEGIN_COMMIT_OVERRIDE` block in the merged PR's body, then run the **Release** workflow to rebuild the Release PR. Keep ticket IDs out of PR titles, because a title becomes a changelog line.
145145

146146
## Releasing a new version (for Stream developers)

0 commit comments

Comments
 (0)