Skip to content

Commit 58b59c6

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 58b5f8f commit 58b59c6

10 files changed

Lines changed: 1270 additions & 53 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
timeout-minutes: 5
30+
permissions:
31+
contents: read
32+
pull-requests: read
33+
outputs:
34+
should_run: ${{ steps.gate.outputs.should_run }}
35+
matrix: ${{ steps.config.outputs.matrix }}
36+
steps:
37+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
38+
39+
- id: gate
40+
uses: ./.github/actions/pr-gate
41+
42+
- id: config
43+
name: Load SDK configuration
44+
run: echo "matrix=$(jq -c '.include' tasks/sdk-sync-config.json)" >> "$GITHUB_OUTPUT"
45+
46+
sdk_proto_drift:
47+
name: Proto Drift (${{ matrix.sdk.name }})
48+
needs: pr_metadata
49+
if: needs.pr_metadata.outputs.should_run == 'true'
50+
runs-on: linux-amd64-cpu8
51+
timeout-minutes: 15
52+
container:
53+
image: ghcr.io/nvidia/openshell/ci:5b9daab9351b1e053f9a5e0ce4c899f5d3f674b0
54+
credentials:
55+
username: ${{ github.actor }}
56+
password: ${{ secrets.GITHUB_TOKEN }}
57+
strategy:
58+
fail-fast: false
59+
matrix:
60+
sdk: ${{ fromJSON(needs.pr_metadata.outputs.matrix) }}
61+
steps:
62+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
63+
64+
- name: Install tools
65+
run: mise install --locked
66+
67+
- name: Check proto drift
68+
id: drift
69+
run: |
70+
REPORT=$(mise run ${{ matrix.sdk.drift_task }} 2>"$RUNNER_TEMP/drift_stderr.log") || true
71+
72+
if echo "$REPORT" | jq -e 'has("synced") and (.synced | type == "boolean")' >/dev/null 2>&1; then
73+
SYNCED=$(echo "$REPORT" | jq -r '.synced')
74+
DELIMITER="REPORT_EOF_$(openssl rand -hex 16)"
75+
{
76+
echo "report<<$DELIMITER"
77+
echo "$REPORT"
78+
echo "$DELIMITER"
79+
} >> "$GITHUB_OUTPUT"
80+
echo "synced=$SYNCED" >> "$GITHUB_OUTPUT"
81+
else
82+
echo "::warning::Proto drift check failed: unable to parse report"
83+
echo "stderr: $(cat "$RUNNER_TEMP/drift_stderr.log")"
84+
echo "synced=error" >> "$GITHUB_OUTPUT"
85+
fi
86+
87+
- name: Annotate drift warning
88+
if: steps.drift.outputs.synced == 'false'
89+
env:
90+
DRIFT_REPORT: ${{ steps.drift.outputs.report }}
91+
SDK_NAME: ${{ matrix.sdk.name }}
92+
run: |
93+
SUMMARY=$(echo "$DRIFT_REPORT" | jq -r '.summary')
94+
FILES=$(echo "$DRIFT_REPORT" | jq -r '.files[] | select(.status != "synced") | " - \(.name) (\(.status), \(.diff_lines) lines changed)"' | sed ':a;N;$!ba;s/\n/%0A/g')
95+
echo "::warning::SDK proto drift detected for ${SDK_NAME}: ${SUMMARY}%0A${FILES}"
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
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+
19+
concurrency:
20+
group: sdk-proto-sync
21+
cancel-in-progress: true
22+
23+
jobs:
24+
load_config:
25+
name: Load SDK configuration
26+
runs-on: ubuntu-latest
27+
timeout-minutes: 5
28+
outputs:
29+
matrix: ${{ steps.config.outputs.matrix }}
30+
steps:
31+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
32+
- id: config
33+
run: echo "matrix=$(jq -c '.include' tasks/sdk-sync-config.json)" >> "$GITHUB_OUTPUT"
34+
35+
sdk_sync_check:
36+
name: Sync Check (${{ matrix.sdk.name }})
37+
needs: load_config
38+
runs-on: linux-amd64-cpu8
39+
timeout-minutes: 30
40+
container:
41+
image: ghcr.io/nvidia/openshell/ci:5b9daab9351b1e053f9a5e0ce4c899f5d3f674b0
42+
credentials:
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
sdk: ${{ fromJSON(needs.load_config.outputs.matrix) }}
49+
steps:
50+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
51+
- name: Install tools
52+
run: mise install --locked
53+
- name: Check proto drift and build
54+
env:
55+
SDK_NAME: ${{ matrix.sdk.name }}
56+
DRIFT_TASK: ${{ matrix.sdk.drift_task }}
57+
BUILD_CHECK_TASK: ${{ matrix.sdk.build_check_task }}
58+
run: |
59+
mkdir -p report
60+
mise run "$DRIFT_TASK" > report/drift.json 2> report/drift.stderr || true
61+
if ! jq -e 'type == "object" and has("synced") and (.synced | type == "boolean") and (has("error") | not)' report/drift.json >/dev/null 2>&1; then
62+
jq -n --arg sdk "$SDK_NAME" '{sdk:$sdk, has_drift:"error", build_failed:"false"}' > report/status.json
63+
exit 0
64+
fi
65+
SYNCED=$(jq -r '.synced' report/drift.json)
66+
if [ "$SYNCED" = "true" ]; then
67+
jq -n --arg sdk "$SDK_NAME" '{sdk:$sdk, has_drift:"false", build_failed:"false"}' > report/status.json
68+
exit 0
69+
fi
70+
if mise run "$BUILD_CHECK_TASK" > report/build.json 2> report/build.stderr; then
71+
BUILD_FAILED=false
72+
else
73+
BUILD_FAILED=true
74+
fi
75+
jq -n --arg sdk "$SDK_NAME" --arg build_failed "$BUILD_FAILED" \
76+
'{sdk:$sdk, has_drift:"true", build_failed:$build_failed}' > report/status.json
77+
- name: Upload SDK report
78+
if: always()
79+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
80+
with:
81+
name: sdk-sync-${{ matrix.sdk.name }}
82+
path: report/
83+
if-no-files-found: error
84+
retention-days: 1
85+
86+
issue_management:
87+
name: Manage Drift Issue (${{ matrix.sdk.name }})
88+
needs: [load_config, sdk_sync_check]
89+
if: always() && needs.load_config.result == 'success' && needs.sdk_sync_check.result == 'success'
90+
runs-on: linux-amd64-cpu8
91+
timeout-minutes: 5
92+
permissions:
93+
contents: read
94+
issues: write
95+
packages: read
96+
container:
97+
image: ghcr.io/nvidia/openshell/ci:5b9daab9351b1e053f9a5e0ce4c899f5d3f674b0
98+
credentials:
99+
username: ${{ github.actor }}
100+
password: ${{ secrets.GITHUB_TOKEN }}
101+
strategy:
102+
fail-fast: false
103+
matrix:
104+
sdk: ${{ fromJSON(needs.load_config.outputs.matrix) }}
105+
steps:
106+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
107+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
108+
with:
109+
name: sdk-sync-${{ matrix.sdk.name }}
110+
path: report
111+
- name: Read SDK status
112+
id: status
113+
run: |
114+
echo "has_drift=$(jq -r '.has_drift' report/status.json)" >> "$GITHUB_OUTPUT"
115+
echo "build_failed=$(jq -r '.build_failed' report/status.json)" >> "$GITHUB_OUTPUT"
116+
- name: Warn on drift detection error
117+
if: steps.status.outputs.has_drift == 'error'
118+
run: |
119+
echo "::error::Drift detection failed for ${{ matrix.sdk.name }} SDK"
120+
cat report/drift.stderr
121+
exit 1
122+
- name: Install tools
123+
if: steps.status.outputs.has_drift == 'true'
124+
run: mise install --locked
125+
- name: Create or update drift issue
126+
if: steps.status.outputs.has_drift == 'true'
127+
env:
128+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
129+
run: |
130+
set +e
131+
RESULT=$(uv run python tasks/scripts/sdk_sync.py manage-issue \
132+
--drift-report "$(cat report/drift.json)" \
133+
--build-report "$(cat report/build.json)" \
134+
--sdk "${{ matrix.sdk.name }}" \
135+
--repo "$GITHUB_REPOSITORY" \
136+
--label "${{ matrix.sdk.label }}")
137+
STATUS=$?
138+
set -e
139+
if ! printf '%s\n' "$RESULT" | jq .; then
140+
printf '%s\n' "$RESULT"
141+
fi
142+
if [ "$STATUS" -ne 0 ]; then
143+
echo "::error::Issue management command failed with exit code $STATUS"
144+
exit "$STATUS"
145+
fi
146+
if ! ACTION=$(printf '%s\n' "$RESULT" | jq -er '.action // "unknown"'); then
147+
ACTION=unknown
148+
fi
149+
if [ "$ACTION" != "created" ] && [ "$ACTION" != "updated" ]; then
150+
echo "::error::Issue management for ${{ matrix.sdk.name }} failed: $ACTION"
151+
exit 1
152+
fi
153+
- name: Close resolved drift issue
154+
if: steps.status.outputs.has_drift == 'false'
155+
env:
156+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157+
run: |
158+
ISSUE=$(gh issue list --repo "$GITHUB_REPOSITORY" --label "${{ matrix.sdk.label }}" --state open --json number --jq '.[0].number')
159+
if [ -n "$ISSUE" ]; then
160+
gh issue close "$ISSUE" --repo "$GITHUB_REPOSITORY" --comment "The SDK proto drift check passed. Closing automatically."
161+
echo "Closed issue #$ISSUE"
162+
fi

‎tasks/go.toml‎

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -163,58 +163,17 @@ hide = true
163163
["go:proto:check"]
164164
description = "Verify generated Go SDK proto files are up to date"
165165
dir = "sdk/go"
166-
run = """
167-
#!/usr/bin/env bash
168-
set -euo pipefail
169-
170-
SDK_ROOT=$(pwd -P)
171-
REPO_ROOT=$(cd ../.. && pwd -P)
172-
173-
for tool in buf protoc-gen-go protoc-gen-go-grpc; do
174-
if ! command -v "$tool" &>/dev/null; then
175-
echo "ERROR: $tool not found. Run 'mise install' to install it."
176-
exit 1
177-
fi
178-
done
179-
180-
WORK_DIR=$(mktemp -d)
181-
trap 'rm -rf "$WORK_DIR"' EXIT
182-
183-
if find proto -maxdepth 1 -name '*.proto' -print -quit | grep -q .; then
184-
echo "ERROR: sdk/go/proto contains copied proto sources."
185-
echo "Proto sources belong in the repository root proto/ directory."
186-
exit 1
187-
fi
188-
189-
# Generate to temp directory with adjusted output path
190-
BUF_OUTPUT_DIR="$WORK_DIR"
191-
if command -v cygpath &>/dev/null; then
192-
BUF_OUTPUT_DIR=$(cygpath -m "$WORK_DIR")
193-
fi
194-
sed "s|out: sdk/go|out: $BUF_OUTPUT_DIR|" "$SDK_ROOT/buf.gen.yaml" > "$WORK_DIR/buf.gen.yaml"
195-
if command -v cygpath &>/dev/null; then
196-
GO_PLUGIN=$(cygpath -m "$(command -v protoc-gen-go)")
197-
GRPC_PLUGIN=$(cygpath -m "$(command -v protoc-gen-go-grpc)")
198-
GO_PLUGIN=${GO_PLUGIN//&/\\&}
199-
GRPC_PLUGIN=${GRPC_PLUGIN//&/\\&}
200-
sed \
201-
-e "s|local: protoc-gen-go$|local: $GO_PLUGIN|" \
202-
-e "s|local: protoc-gen-go-grpc$|local: $GRPC_PLUGIN|" \
203-
"$WORK_DIR/buf.gen.yaml" > "$WORK_DIR/buf.gen.windows.yaml"
204-
mv "$WORK_DIR/buf.gen.windows.yaml" "$WORK_DIR/buf.gen.yaml"
205-
fi
206-
(cd "$REPO_ROOT" && buf generate --template "$WORK_DIR/buf.gen.yaml")
207-
208-
DIFF_OUTPUT=$(diff -r "$WORK_DIR/proto" "$SDK_ROOT/proto" 2>&1) || true
166+
run = 'bash ../../tasks/scripts/go_proto_check.sh text'
167+
hide = true
209168

210-
if [ -n "$DIFF_OUTPUT" ]; then
211-
echo "ERROR: Generated proto files are out of date."
212-
echo "Run 'mise run go:proto:gen' to regenerate."
213-
echo ""
214-
echo "$DIFF_OUTPUT"
215-
exit 1
216-
fi
169+
["go:proto:drift"]
170+
description = "Check Go SDK proto drift and output a JSON report"
171+
dir = "sdk/go"
172+
run = 'bash ../../tasks/scripts/go_proto_check.sh json'
173+
hide = true
217174

218-
echo "Proto check passed: generated files are up to date."
219-
"""
175+
["go:proto:build-check"]
176+
description = "Run full Go SDK proto sync, generate, build, and test pipeline"
177+
dir = "sdk/go"
178+
run = 'bash ../../tasks/scripts/sdk_build_check.sh go gen=go:proto:gen build=go:build test=go:test'
220179
hide = true

0 commit comments

Comments
 (0)