Skip to content

Commit 307ed34

Browse files
committed
feat: Add cross-repo breaking change detection system
- Extend build-wasm-internal.yml with trigger-breaking-change-check job - Add consolidated comment strategy for real-time status updates - Implement synchronous workflow coordination with 10min timeout - Add comprehensive error handling and retry mechanisms - Include Azure Key Vault PAT token integration - Add Breaking Changes section to PR template - Support for matrix strategy (ready for mobile expansion) Implements comprehensive SDK CI breaking change detection per PM-22218
1 parent 0364659 commit 307ed34

File tree

2 files changed

+318
-0
lines changed

2 files changed

+318
-0
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66

77
<!-- Describe what the purpose of this PR is, for example what bug you're fixing or new feature you're adding. -->
88

9+
## 🚨 Breaking Changes
10+
11+
<!-- Does this PR introduce any breaking changes? If so, please describe the impact and migration path for clients.
12+
13+
If you're unsure, the automated TypeScript compatibility check will run when you open/update this PR and provide feedback.
14+
15+
For breaking changes:
16+
1. Describe what changed in the client interface
17+
2. Explain why the change was necessary
18+
3. Provide migration steps for client developers
19+
4. Link to any paired client PRs if needed
20+
21+
Otherwise, you can remove this section. -->
22+
923
## ⏰ Reminders before review
1024

1125
- Contributor guidelines followed

.github/workflows/build-wasm-internal.yml

Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,307 @@ jobs:
138138
workflow_id: 'publish-wasm-internal.yml',
139139
ref: 'main',
140140
})
141+
trigger-breaking-change-check:
142+
name: Trigger client breaking change checks
143+
if: github.event_name == 'pull_request'
144+
runs-on: ubuntu-24.04
145+
needs: build
146+
defaults:
147+
run:
148+
shell: bash
149+
working-directory: .
150+
permissions:
151+
contents: read
152+
actions: write
153+
pull-requests: write
154+
id-token: write
155+
strategy:
156+
matrix:
157+
client:
158+
- repo: "bitwarden/clients"
159+
event_type: "sdk-breaking-change-check"
160+
label: "typescript"
161+
workflow: "sdk-breaking-change-check.yml"
162+
env:
163+
CLIENT_REPO: ${{ matrix.client.repo }}
164+
EVENT_TYPE: ${{ matrix.client.event_type }}
165+
CLIENT_LABEL: ${{ matrix.client.label }}
166+
WORKFLOW_NAME: ${{ matrix.client.workflow }}
167+
MAX_RETRIES: 3
168+
169+
steps:
170+
- name: Download SDK artifacts
171+
uses: actions/download-artifact@v4
172+
with:
173+
name: sdk-internal
174+
path: ./sdk-artifacts
175+
176+
- name: Prepare dispatch payload
177+
id: payload
178+
run: |
179+
PR_HEAD_SHA="${{ github.event.pull_request.head.sha }}"
180+
SHORT_SHA="${PR_HEAD_SHA:0:7}"
181+
SDK_VERSION="${{ github.event.pull_request.head.ref }} ($SHORT_SHA)"
182+
183+
# Create payload JSON (compact format to avoid GitHub Actions output parsing issues)
184+
PAYLOAD=$(jq -n \
185+
--arg pr_number "${{ github.event.number }}" \
186+
--arg sdk_version "$SDK_VERSION" \
187+
--arg source_repo "${{ github.repository }}" \
188+
--arg workflow_context "$WORKFLOW_NAME" \
189+
--arg client_label "$CLIENT_LABEL" \
190+
--arg pr_head_sha "${{ github.event.pull_request.head.sha }}" \
191+
--arg pr_base_ref "${{ github.event.pull_request.base.ref }}" \
192+
--arg comment_id "${{ steps.consolidated-comment.outputs.comment_id }}" \
193+
--arg run_id "${{ github.run_id }}" \
194+
--arg artifact_name "sdk-internal" \
195+
'{
196+
pr_number: $pr_number,
197+
sdk_version: $sdk_version,
198+
source_repo: $source_repo,
199+
workflow_context: $workflow_context,
200+
client_label: $client_label,
201+
pr_head_sha: $pr_head_sha,
202+
pr_base_ref: $pr_base_ref,
203+
comment_id: $comment_id,
204+
artifacts_info: {
205+
run_id: $run_id,
206+
artifact_name: $artifact_name
207+
}
208+
}')
209+
210+
# Use GitHub Actions multiline output format for JSON
211+
echo "payload<<EOF" >> $GITHUB_OUTPUT
212+
echo "$PAYLOAD" >> $GITHUB_OUTPUT
213+
echo "EOF" >> $GITHUB_OUTPUT
214+
215+
echo "sdk_version=$SDK_VERSION" >> $GITHUB_OUTPUT
216+
217+
- name: Create or update consolidated status comment
218+
id: consolidated-comment
219+
run: |
220+
echo "💬 Creating/updating consolidated breaking change status comment..."
221+
222+
COMMENT_HEADER="<!-- SDK-BREAKING-CHANGE-CHECK -->"
223+
SDK_VERSION="${{ steps.payload.outputs.sdk_version }}"
224+
TIMESTAMP=$(date -u '+%Y-%m-%d %H:%M:%S UTC')
225+
226+
# Expected clients list - expand when adding mobile
227+
EXPECTED_CLIENTS=("typescript")
228+
229+
# Build status table
230+
STATUS_TABLE="| Client | Status | Details |
231+
|--------|---------|---------|"
232+
233+
for CLIENT in "${EXPECTED_CLIENTS[@]}"; do
234+
STATUS_TABLE+="
235+
|$CLIENT|⏳ Pending|Type checking in progress...|"
236+
done
237+
238+
CONSOLIDATED_COMMENT=$(cat << EOF
239+
$COMMENT_HEADER
240+
## 🔍 SDK Breaking Change Detection Status
241+
242+
**SDK Version:** \`$SDK_VERSION\`
243+
**Triggered:** $TIMESTAMP
244+
**Progress:** Dispatching client workflows...
245+
246+
$STATUS_TABLE
247+
248+
---
249+
*This status updates automatically as client workflows complete. [View SDK workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})*
250+
EOF
251+
)
252+
253+
# Check for existing consolidated comment
254+
EXISTING_COMMENT=$(gh api repos/${{ github.repository }}/issues/${{ github.event.number }}/comments | \
255+
jq -r --arg header "$COMMENT_HEADER" '.[] | select(.body | contains($header)) | .id' | head -1)
256+
257+
258+
if [ -n "$EXISTING_COMMENT" ]; then
259+
echo "Updating existing consolidated comment ID: $EXISTING_COMMENT"
260+
gh api --method PATCH repos/${{ github.repository }}/issues/comments/$EXISTING_COMMENT \
261+
--field body="$CONSOLIDATED_COMMENT"
262+
echo "comment_id=$EXISTING_COMMENT" >> $GITHUB_OUTPUT
263+
else
264+
echo "Creating new consolidated comment"
265+
COMMENT_ID=$(gh api --method POST repos/${{ github.repository }}/issues/${{ github.event.number }}/comments \
266+
--field body="$CONSOLIDATED_COMMENT" --jq '.id')
267+
echo "comment_id=$COMMENT_ID" >> $GITHUB_OUTPUT
268+
fi
269+
270+
echo "✅ Consolidated comment created/updated"
271+
- name: Log in to Azure
272+
uses: bitwarden/gh-actions/azure-login@main
273+
with:
274+
subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
275+
tenant_id: ${{ secrets.AZURE_TENANT_ID }}
276+
client_id: ${{ secrets.AZURE_CLIENT_ID }}
277+
- name: Retrieve GitHub PAT secrets
278+
id: retrieve-secret-pat
279+
uses: bitwarden/gh-actions/get-keyvault-secrets@main
280+
with:
281+
keyvault: "bitwarden-ci"
282+
secrets: "github-pat-bitwarden-devops-bot-repo-scope"
283+
- name: Log out from Azure
284+
uses: bitwarden/gh-actions/azure-logout@main
285+
- name: Trigger client repository dispatch
286+
run: |
287+
echo "🚀 Triggering $WORKFLOW_NAME in $CLIENT_REPO..."
288+
289+
RETRY_COUNT=0
290+
DISPATCH_SUCCESS=false
291+
292+
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
293+
RETRY_COUNT=$((RETRY_COUNT + 1))
294+
echo "🔄 Attempt $RETRY_COUNT of $MAX_RETRIES for $CLIENT_REPO..."
295+
296+
if GH_TOKEN="${{ steps.retrieve-secret-pat.outputs.github-pat-bitwarden-devops-bot-repo-scope }}" gh api repos/$CLIENT_REPO/dispatches \
297+
--method POST \
298+
--field event_type="$EVENT_TYPE" \
299+
--raw-field client_payload='${{ steps.payload.outputs.payload }}'; then
300+
301+
echo "✅ Successfully triggered $CLIENT_REPO ($CLIENT_LABEL)"
302+
echo "📋 Results will be posted to PR #${{ github.event.number }} when ready"
303+
echo "✅ **$CLIENT_REPO**: $WORKFLOW_NAME triggered - [Monitor Progress](https://github.com/$CLIENT_REPO/actions)" >> $GITHUB_STEP_SUMMARY
304+
DISPATCH_SUCCESS=true
305+
break
306+
else
307+
echo "⚠️ $CLIENT_REPO dispatch attempt $RETRY_COUNT failed"
308+
[ $RETRY_COUNT -lt $MAX_RETRIES ] && sleep 5
309+
fi
310+
done
311+
312+
if [ "$DISPATCH_SUCCESS" = "false" ]; then
313+
echo "::error::Failed to trigger $CLIENT_REPO after $MAX_RETRIES attempts"
314+
echo "::warning::$CLIENT_LABEL breaking change detection will be skipped"
315+
echo "❌ **$CLIENT_REPO**: Failed to trigger - [Manual Check Required](https://github.com/$CLIENT_REPO)" >> $GITHUB_STEP_SUMMARY
316+
fi
317+
318+
- name: Wait for client workflow completion
319+
timeout-minutes: 12
320+
run: |
321+
echo "⏳ Waiting for all client type checking workflows to complete..."
322+
323+
WAIT_START_TIME=$(date +%s)
324+
MAX_WAIT_SECONDS=600 # 10 minutes max wait
325+
POLL_INTERVAL=30 # Check every 30 seconds
326+
327+
# Expected clients list - expand when adding mobile
328+
EXPECTED_CLIENTS=("typescript")
329+
COMPLETED_CLIENTS=()
330+
331+
while true; do
332+
CURRENT_TIME=$(date +%s)
333+
ELAPSED=$((CURRENT_TIME - WAIT_START_TIME))
334+
335+
# Check timeout
336+
if [ $ELAPSED -gt $MAX_WAIT_SECONDS ]; then
337+
echo "⏰ Timeout reached after ${ELAPSED}s - proceeding with available results"
338+
echo "::warning::Some client workflows may still be running"
339+
break
340+
fi
341+
342+
echo "🔍 Polling for completion markers (${ELAPSED}s elapsed)..."
343+
344+
# Check for completion markers in PR comments
345+
COMMENTS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.number }}/comments \
346+
--jq '.[] | select(.body | contains("<!-- SDK-BREAKING-CHANGE-COMPLETION:")) | .body')
347+
348+
# Reset completed clients for this check
349+
COMPLETED_CLIENTS=()
350+
351+
# Check each expected client
352+
for CLIENT in "${EXPECTED_CLIENTS[@]}"; do
353+
if echo "$COMMENTS" | grep -q "<!-- SDK-BREAKING-CHANGE-COMPLETION:$CLIENT -->"; then
354+
COMPLETED_CLIENTS+=("$CLIENT")
355+
echo "✅ $CLIENT workflow completed"
356+
else
357+
echo "⏳ $CLIENT workflow still running..."
358+
fi
359+
done
360+
361+
# Check if all clients completed
362+
if [ ${#COMPLETED_CLIENTS[@]} -eq ${#EXPECTED_CLIENTS[@]} ]; then
363+
echo "🎉 All client workflows completed!"
364+
break
365+
fi
366+
367+
# Wait before next poll
368+
echo "⏸️ Waiting ${POLL_INTERVAL}s before next check..."
369+
sleep $POLL_INTERVAL
370+
done
371+
372+
# Summary
373+
echo ""
374+
echo "=== Final Status ==="
375+
echo "Completed clients: ${COMPLETED_CLIENTS[*]}"
376+
echo "Total wait time: ${ELAPSED}s"
377+
378+
if [ ${#COMPLETED_CLIENTS[@]} -eq ${#EXPECTED_CLIENTS[@]} ]; then
379+
echo "✅ All expected client workflows completed successfully"
380+
echo "status=complete" >> $GITHUB_OUTPUT
381+
else
382+
MISSING_CLIENTS=()
383+
for CLIENT in "${EXPECTED_CLIENTS[@]}"; do
384+
if [[ ! " ${COMPLETED_CLIENTS[*]} " =~ " ${CLIENT} " ]]; then
385+
MISSING_CLIENTS+=("$CLIENT")
386+
fi
387+
done
388+
echo "⚠️ Some workflows incomplete: ${MISSING_CLIENTS[*]}"
389+
echo "status=partial" >> $GITHUB_OUTPUT
390+
fi
391+
392+
# Update GitHub step summary
393+
echo "⏱️ **Synchronization Complete**: Waited ${ELAPSED}s for client workflows" >> $GITHUB_STEP_SUMMARY
394+
echo "📊 **Completed**: ${#COMPLETED_CLIENTS[@]}/${#EXPECTED_CLIENTS[@]} clients" >> $GITHUB_STEP_SUMMARY
395+
- name: Report final workflow status
396+
run: |
397+
echo "📊 Final SDK workflow status summary"
398+
399+
# Analyze all PR comments for breaking change results
400+
COMMENTS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.number }}/comments \
401+
--jq '.[] | select(.body | contains("SDK-BREAKING-CHANGE-CHECK")) | .body')
402+
403+
BREAKING_DETECTED=false
404+
CLIENT_RESULTS=()
405+
406+
for CLIENT in typescript; do # Expand when adding mobile
407+
if echo "$COMMENTS" | grep -q "❌ TypeScript Breaking Changes Detected" && [[ "$CLIENT" == "typescript" ]]; then
408+
BREAKING_DETECTED=true
409+
CLIENT_RESULTS+=("❌ $CLIENT: Breaking changes detected")
410+
elif echo "$COMMENTS" | grep -q "✅ TypeScript Compatibility Check Passed" && [[ "$CLIENT" == "typescript" ]]; then
411+
CLIENT_RESULTS+=("✅ $CLIENT: No breaking changes")
412+
else
413+
CLIENT_RESULTS+=("⚠️ $CLIENT: Status unclear or incomplete")
414+
fi
415+
done
416+
417+
echo ""
418+
echo "=== Breaking Change Detection Results ==="
419+
for RESULT in "${CLIENT_RESULTS[@]}"; do
420+
echo "$RESULT"
421+
done
422+
423+
# Set overall status
424+
if [ "$BREAKING_DETECTED" = "true" ]; then
425+
echo ""
426+
echo "🚨 BREAKING CHANGES DETECTED - Review PR comments for details"
427+
echo "⚠️ This is non-blocking - PR can still be merged if changes are intentional"
428+
echo "status=breaking-changes" >> $GITHUB_OUTPUT
429+
else
430+
echo ""
431+
echo "✅ No breaking changes detected across all clients"
432+
echo "status=clean" >> $GITHUB_OUTPUT
433+
fi
434+
435+
# Add results to job summary
436+
echo "## 🔍 Breaking Change Detection Results" >> $GITHUB_STEP_SUMMARY
437+
for RESULT in "${CLIENT_RESULTS[@]}"; do
438+
echo "- $RESULT" >> $GITHUB_STEP_SUMMARY
439+
done
440+
441+
if [ "$BREAKING_DETECTED" = "true" ]; then
442+
echo "" >> $GITHUB_STEP_SUMMARY
443+
echo "⚠️ **Breaking changes detected** - See PR comments for migration guidance" >> $GITHUB_STEP_SUMMARY
444+
fi

0 commit comments

Comments
 (0)