Skip to content

Commit 9da602e

Browse files
committed
ci(sdk): add proto drift detection and sync notifications
Add automated proto drift detection for Go and TypeScript SDKs with issue-based notifications when SDK builds break due to proto changes. Signed-off-by: Ignas Baranauskas <ibaranau@redhat.com>
1 parent 2ad86c1 commit 9da602e

7 files changed

Lines changed: 951 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: SDK Proto Check
5+
6+
on:
7+
merge_group:
8+
types: [checks_requested]
9+
push:
10+
branches:
11+
- "pull-request/[0-9]+"
12+
workflow_dispatch:
13+
14+
env:
15+
MISE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
17+
permissions:
18+
contents: read
19+
packages: read
20+
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.ref }}
23+
cancel-in-progress: true
24+
25+
jobs:
26+
pr_metadata:
27+
name: Resolve PR metadata
28+
runs-on: ubuntu-latest
29+
permissions:
30+
contents: read
31+
pull-requests: read
32+
outputs:
33+
should_run: ${{ steps.gate.outputs.should_run }}
34+
steps:
35+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
36+
37+
- id: gate
38+
uses: ./.github/actions/pr-gate
39+
40+
sdk_proto_drift:
41+
name: Proto Drift (${{ matrix.sdk.name }})
42+
needs: pr_metadata
43+
if: needs.pr_metadata.outputs.should_run == 'true'
44+
runs-on: linux-amd64-cpu8
45+
container:
46+
image: ghcr.io/nvidia/openshell/ci:latest
47+
credentials:
48+
username: ${{ github.actor }}
49+
password: ${{ secrets.GITHUB_TOKEN }}
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
sdk:
54+
- name: go
55+
drift_task: "go:proto:drift"
56+
- name: typescript
57+
drift_task: "sdk:ts:proto:drift"
58+
steps:
59+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
60+
61+
- name: Install tools
62+
run: mise install --locked
63+
64+
- name: Check proto drift
65+
id: drift
66+
run: |
67+
REPORT=$(mise run ${{ matrix.sdk.drift_task }} 2>"$RUNNER_TEMP/drift_stderr.log") || true
68+
69+
if echo "$REPORT" | jq -e '.synced' >/dev/null 2>&1; then
70+
SYNCED=$(echo "$REPORT" | jq -r '.synced')
71+
{
72+
echo "report<<REPORT_EOF"
73+
echo "$REPORT"
74+
echo "REPORT_EOF"
75+
} >> "$GITHUB_OUTPUT"
76+
echo "synced=$SYNCED" >> "$GITHUB_OUTPUT"
77+
else
78+
echo "::warning::Proto drift check failed: unable to parse report"
79+
echo "stderr: $(cat "$RUNNER_TEMP/drift_stderr.log")"
80+
echo "synced=error" >> "$GITHUB_OUTPUT"
81+
fi
82+
83+
- name: Annotate drift warning
84+
if: steps.drift.outputs.synced == 'false'
85+
env:
86+
DRIFT_REPORT: ${{ steps.drift.outputs.report }}
87+
SDK_NAME: ${{ matrix.sdk.name }}
88+
run: |
89+
SUMMARY=$(echo "$DRIFT_REPORT" | jq -r '.summary')
90+
FILES=$(echo "$DRIFT_REPORT" | jq -r '.files[] | select(.status != "synced") | " - \(.name) (\(.status), \(.diff_lines) lines changed)"' | sed ':a;N;$!ba;s/\n/%0A/g')
91+
echo "::warning::SDK proto drift detected for ${SDK_NAME}: ${SUMMARY}%0A${FILES}"
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
name: SDK Proto Sync
5+
6+
on:
7+
schedule:
8+
- cron: "0 6 * * *"
9+
workflow_dispatch:
10+
11+
env:
12+
MISE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
14+
permissions:
15+
actions: read
16+
contents: read
17+
packages: read
18+
issues: write
19+
20+
concurrency:
21+
group: sdk-proto-sync
22+
cancel-in-progress: true
23+
24+
jobs:
25+
sdk_sync_check:
26+
name: Sync Check
27+
runs-on: linux-amd64-cpu8
28+
container:
29+
image: ghcr.io/nvidia/openshell/ci:latest
30+
credentials:
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
outputs:
34+
go_drift_report: ${{ steps.go_drift.outputs.report }}
35+
go_has_drift: ${{ steps.go_drift.outputs.has_drift }}
36+
go_build_report: ${{ steps.go_build.outputs.report }}
37+
go_build_failed: ${{ steps.go_build.outputs.build_failed || 'false' }}
38+
ts_drift_report: ${{ steps.ts_drift.outputs.report }}
39+
ts_has_drift: ${{ steps.ts_drift.outputs.has_drift }}
40+
ts_build_report: ${{ steps.ts_build.outputs.report }}
41+
ts_build_failed: ${{ steps.ts_build.outputs.build_failed || 'false' }}
42+
steps:
43+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
44+
45+
- name: Install tools
46+
run: mise install --locked
47+
48+
- name: Check Go proto drift
49+
id: go_drift
50+
run: |
51+
REPORT=$(mise run go:proto:drift 2>"$RUNNER_TEMP/go_drift_stderr.log") || true
52+
if echo "$REPORT" | jq -e '.synced' >/dev/null 2>&1; then
53+
SYNCED=$(echo "$REPORT" | jq -r '.synced')
54+
{
55+
echo "report<<REPORT_EOF"
56+
echo "$REPORT"
57+
echo "REPORT_EOF"
58+
} >> "$GITHUB_OUTPUT"
59+
[ "$SYNCED" = "true" ] && echo "has_drift=false" >> "$GITHUB_OUTPUT" || echo "has_drift=true" >> "$GITHUB_OUTPUT"
60+
else
61+
echo "::error::Go proto drift check failed"
62+
echo "stderr: $(cat "$RUNNER_TEMP/go_drift_stderr.log")"
63+
echo "report={}" >> "$GITHUB_OUTPUT"
64+
echo "has_drift=error" >> "$GITHUB_OUTPUT"
65+
fi
66+
67+
- name: Go build check
68+
id: go_build
69+
if: steps.go_drift.outputs.has_drift == 'true'
70+
run: |
71+
REPORT=$(mise run go:proto:build-check 2>"$RUNNER_TEMP/go_build_stderr.log") && BUILD_OK=true || BUILD_OK=false
72+
if echo "$REPORT" | jq -e '.sdk' >/dev/null 2>&1; then
73+
{ echo "report<<REPORT_EOF"; echo "$REPORT"; echo "REPORT_EOF"; } >> "$GITHUB_OUTPUT"
74+
else
75+
echo "stderr: $(cat "$RUNNER_TEMP/go_build_stderr.log")"
76+
echo "report={}" >> "$GITHUB_OUTPUT"
77+
fi
78+
[ "$BUILD_OK" = "true" ] && echo "build_failed=false" >> "$GITHUB_OUTPUT" || echo "build_failed=true" >> "$GITHUB_OUTPUT"
79+
80+
- name: Check TypeScript proto drift
81+
id: ts_drift
82+
run: |
83+
REPORT=$(mise run sdk:ts:proto:drift 2>"$RUNNER_TEMP/ts_drift_stderr.log") || true
84+
if echo "$REPORT" | jq -e '.synced' >/dev/null 2>&1; then
85+
SYNCED=$(echo "$REPORT" | jq -r '.synced')
86+
{
87+
echo "report<<REPORT_EOF"
88+
echo "$REPORT"
89+
echo "REPORT_EOF"
90+
} >> "$GITHUB_OUTPUT"
91+
[ "$SYNCED" = "true" ] && echo "has_drift=false" >> "$GITHUB_OUTPUT" || echo "has_drift=true" >> "$GITHUB_OUTPUT"
92+
else
93+
echo "::error::TypeScript proto drift check failed"
94+
echo "stderr: $(cat "$RUNNER_TEMP/ts_drift_stderr.log")"
95+
echo "report={}" >> "$GITHUB_OUTPUT"
96+
echo "has_drift=error" >> "$GITHUB_OUTPUT"
97+
fi
98+
99+
- name: TypeScript build check
100+
id: ts_build
101+
if: steps.ts_drift.outputs.has_drift == 'true'
102+
run: |
103+
REPORT=$(mise run sdk:ts:proto:build-check 2>"$RUNNER_TEMP/ts_build_stderr.log") && BUILD_OK=true || BUILD_OK=false
104+
if echo "$REPORT" | jq -e '.sdk' >/dev/null 2>&1; then
105+
{ echo "report<<REPORT_EOF"; echo "$REPORT"; echo "REPORT_EOF"; } >> "$GITHUB_OUTPUT"
106+
else
107+
echo "stderr: $(cat "$RUNNER_TEMP/ts_build_stderr.log")"
108+
echo "report={}" >> "$GITHUB_OUTPUT"
109+
fi
110+
[ "$BUILD_OK" = "true" ] && echo "build_failed=false" >> "$GITHUB_OUTPUT" || echo "build_failed=true" >> "$GITHUB_OUTPUT"
111+
112+
issue_management:
113+
name: Manage Drift Issue (${{ matrix.sdk.name }})
114+
needs: sdk_sync_check
115+
if: always() && needs.sdk_sync_check.result == 'success'
116+
runs-on: linux-amd64-cpu8
117+
container:
118+
image: ghcr.io/nvidia/openshell/ci:latest
119+
credentials:
120+
username: ${{ github.actor }}
121+
password: ${{ secrets.GITHUB_TOKEN }}
122+
strategy:
123+
fail-fast: false
124+
matrix:
125+
sdk:
126+
- name: go
127+
label: "sdk:go:sync"
128+
has_drift: ${{ needs.sdk_sync_check.outputs.go_has_drift }}
129+
build_failed: ${{ needs.sdk_sync_check.outputs.go_build_failed }}
130+
drift_report: ${{ needs.sdk_sync_check.outputs.go_drift_report }}
131+
build_report: ${{ needs.sdk_sync_check.outputs.go_build_report }}
132+
- name: typescript
133+
label: "sdk:typescript:sync"
134+
has_drift: ${{ needs.sdk_sync_check.outputs.ts_has_drift }}
135+
build_failed: ${{ needs.sdk_sync_check.outputs.ts_build_failed }}
136+
drift_report: ${{ needs.sdk_sync_check.outputs.ts_drift_report }}
137+
build_report: ${{ needs.sdk_sync_check.outputs.ts_build_report }}
138+
steps:
139+
- name: Warn on drift detection error
140+
if: matrix.sdk.has_drift == 'error'
141+
run: |
142+
echo "::error::Drift detection failed for ${{ matrix.sdk.name }} SDK — check the sdk_sync_check job logs"
143+
exit 1
144+
145+
- if: matrix.sdk.has_drift == 'true' && matrix.sdk.build_failed == 'true'
146+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
147+
148+
- name: Install tools
149+
if: matrix.sdk.has_drift == 'true' && matrix.sdk.build_failed == 'true'
150+
run: mise install --locked
151+
152+
- name: Create or update drift issue
153+
if: matrix.sdk.has_drift == 'true' && matrix.sdk.build_failed == 'true'
154+
env:
155+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
156+
DRIFT_REPORT: ${{ matrix.sdk.drift_report }}
157+
BUILD_REPORT: ${{ matrix.sdk.build_report }}
158+
run: |
159+
RESULT=$(uv run python tasks/scripts/sdk_sync.py manage-issue \
160+
--drift-report "${DRIFT_REPORT:-{}}" \
161+
--build-report "${BUILD_REPORT:-{}}" \
162+
--sdk "${{ matrix.sdk.name }}" \
163+
--repo "$GITHUB_REPOSITORY" \
164+
--label "${{ matrix.sdk.label }}")
165+
echo "$RESULT" | jq .
166+
ACTION=$(echo "$RESULT" | jq -r '.action // "unknown"')
167+
if [ "$ACTION" = "error" ] || [ "$ACTION" = "unknown" ]; then
168+
echo "::error::Issue management for ${{ matrix.sdk.name }} failed: $ACTION"
169+
exit 1
170+
fi
171+
172+
- name: Close resolved drift issue
173+
if: matrix.sdk.has_drift == 'false' || (matrix.sdk.has_drift == 'true' && matrix.sdk.build_failed == 'false')
174+
env:
175+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176+
run: |
177+
ISSUE=$(gh issue list --repo "$GITHUB_REPOSITORY" --label "${{ matrix.sdk.label }}" --state open --json number --jq '.[0].number')
178+
if [ -n "$ISSUE" ]; then
179+
gh issue close "$ISSUE" --repo "$GITHUB_REPOSITORY" --comment "SDK builds and tests pass after proto regeneration. Closing automatically."
180+
echo "Closed issue #$ISSUE"
181+
fi

‎tasks/go.toml‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,74 @@ fi
178178
echo "Proto check passed: generated files are up to date."
179179
"""
180180
hide = true
181+
182+
["go:proto:drift"]
183+
description = "Check Go SDK proto drift and output a JSON report"
184+
dir = "sdk/go"
185+
run = """
186+
#!/usr/bin/env bash
187+
set -euo pipefail
188+
189+
SDK_ROOT=$(pwd -P)
190+
REPO_ROOT=$(cd ../.. && pwd -P)
191+
192+
for tool in buf protoc-gen-go protoc-gen-go-grpc jq; do
193+
if ! command -v "$tool" &>/dev/null; then
194+
echo '{"sdk":"go","synced":false,"error":"'"$tool"' not found"}'
195+
exit 1
196+
fi
197+
done
198+
199+
WORK_DIR=$(mktemp -d)
200+
trap 'rm -rf "$WORK_DIR"' EXIT
201+
202+
CHECK_TEMPLATE=$(sed 's|out: sdk/go|out: '"$WORK_DIR"'|' buf.gen.yaml)
203+
if ! (cd "$REPO_ROOT" && buf generate --template "$CHECK_TEMPLATE") >/dev/null 2>&1; then
204+
jq -n -c --arg sdk "go" '{sdk:$sdk, synced:false, files:[], summary:"buf generate failed"}'
205+
exit 1
206+
fi
207+
208+
NDJSON_FILE=$(mktemp)
209+
210+
for f in $(find "$WORK_DIR/proto" -name '*.go' -type f | sort); do
211+
REL=${f#"$WORK_DIR/proto/"}
212+
COMMITTED="$SDK_ROOT/proto/$REL"
213+
214+
if [ ! -f "$COMMITTED" ]; then
215+
printf '%s\t%s\t%s\n' "$REL" "added" "0" >> "$NDJSON_FILE"
216+
else
217+
DIFF_LINES=$(diff -u "$COMMITTED" "$f" 2>/dev/null | wc -l | tr -d ' ') || true
218+
if [ "$DIFF_LINES" -gt 0 ]; then
219+
printf '%s\t%s\t%s\n' "$REL" "modified" "$DIFF_LINES" >> "$NDJSON_FILE"
220+
fi
221+
fi
222+
done
223+
224+
for f in $(find "$SDK_ROOT/proto" -name '*.go' -type f | sort); do
225+
REL=${f#"$SDK_ROOT/proto/"}
226+
REGEN="$WORK_DIR/proto/$REL"
227+
if [ ! -f "$REGEN" ]; then
228+
printf '%s\t%s\t%s\n' "$REL" "removed" "0" >> "$NDJSON_FILE"
229+
fi
230+
done
231+
232+
jq -R -c -s --arg sdk "go" '
233+
split("\n") | map(select(length > 0) | split("\t") |
234+
{name: .[0], status: .[1], diff_lines: (.[2] | tonumber)}) |
235+
{sdk: $sdk, synced: (length == 0), files: .,
236+
summary: (if length == 0 then "all files synced"
237+
else "\\(length) file(s) drifted" end)}
238+
' "$NDJSON_FILE"
239+
240+
DRIFTED=$(wc -l < "$NDJSON_FILE" | tr -d ' ')
241+
rm -f "$NDJSON_FILE"
242+
243+
[ "$DRIFTED" -eq 0 ] && exit 0 || exit 1
244+
"""
245+
hide = true
246+
247+
["go:proto:build-check"]
248+
description = "Run full Go SDK proto sync, generate, build, and test pipeline"
249+
dir = "sdk/go"
250+
run = 'bash ../../tasks/scripts/sdk_build_check.sh go gen=go:proto:gen build=go:build test=go:test'
251+
hide = true

‎tasks/scripts/sdk_build_check.sh‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
set -euo pipefail
7+
8+
SDK="${1:?Usage: sdk_build_check.sh <sdk> <step1=task1> [step2=task2] ...}"
9+
shift
10+
11+
PAIRS=("$@")
12+
LOG_FILE=$(mktemp)
13+
trap 'rm -f "$LOG_FILE"' EXIT
14+
15+
FAILED_STEP=""
16+
for pair in "${PAIRS[@]}"; do
17+
STEP="${pair%%=*}"
18+
TASK="${pair#*=}"
19+
20+
if ! mise run "$TASK" >> "$LOG_FILE" 2>&1; then
21+
FAILED_STEP="$STEP"
22+
break
23+
fi
24+
done
25+
26+
LOG_CONTENT=$(tail -500 "$LOG_FILE")
27+
28+
if [ -z "$FAILED_STEP" ]; then
29+
jq -n -c --arg sdk "$SDK" \
30+
'{sdk: $sdk, success: true, failed_step: null, log: ""}'
31+
else
32+
jq -n -c --arg sdk "$SDK" --arg step "$FAILED_STEP" --arg log "$LOG_CONTENT" \
33+
'{sdk: $sdk, success: false, failed_step: $step, log: $log}'
34+
exit 1
35+
fi

0 commit comments

Comments
 (0)