@@ -138,3 +138,306 @@ 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 '.[] | select(.body | contains(\"'$COMMENT_HEADER'\")) | .id' | head -1)
256+
257+ if [ -n "$EXISTING_COMMENT" ]; then
258+ echo "Updating existing consolidated comment ID: $EXISTING_COMMENT"
259+ gh api --method PATCH repos/${{ github.repository }}/issues/comments/$EXISTING_COMMENT \
260+ --field body="$CONSOLIDATED_COMMENT"
261+ echo "comment_id=$EXISTING_COMMENT" >> $GITHUB_OUTPUT
262+ else
263+ echo "Creating new consolidated comment"
264+ COMMENT_ID=$(gh api --method POST repos/${{ github.repository }}/issues/${{ github.event.number }}/comments \
265+ --field body="$CONSOLIDATED_COMMENT" --jq '.id')
266+ echo "comment_id=$COMMENT_ID" >> $GITHUB_OUTPUT
267+ fi
268+
269+ echo "✅ Consolidated comment created/updated"
270+ - name : Log in to Azure
271+ uses : bitwarden/gh-actions/azure-login@main
272+ with :
273+ subscription_id : ${{ secrets.AZURE_SUBSCRIPTION_ID }}
274+ tenant_id : ${{ secrets.AZURE_TENANT_ID }}
275+ client_id : ${{ secrets.AZURE_CLIENT_ID }}
276+ - name : Retrieve GitHub PAT secrets
277+ id : retrieve-secret-pat
278+ uses : bitwarden/gh-actions/get-keyvault-secrets@main
279+ with :
280+ keyvault : " bitwarden-ci"
281+ secrets : " github-pat-bitwarden-devops-bot-repo-scope"
282+ - name : Log out from Azure
283+ uses : bitwarden/gh-actions/azure-logout@main
284+ - name : Trigger client repository dispatch
285+ run : |
286+ echo "🚀 Triggering $WORKFLOW_NAME in $CLIENT_REPO..."
287+
288+ RETRY_COUNT=0
289+ DISPATCH_SUCCESS=false
290+
291+ while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
292+ RETRY_COUNT=$((RETRY_COUNT + 1))
293+ echo "🔄 Attempt $RETRY_COUNT of $MAX_RETRIES for $CLIENT_REPO..."
294+
295+ if GH_TOKEN="${{ steps.retrieve-secret-pat.outputs.github-pat-bitwarden-devops-bot-repo-scope }}" gh api repos/$CLIENT_REPO/dispatches \
296+ --method POST \
297+ --field event_type="$EVENT_TYPE" \
298+ --raw-field client_payload='${{ steps.payload.outputs.payload }}'; then
299+
300+ echo "✅ Successfully triggered $CLIENT_REPO ($CLIENT_LABEL)"
301+ echo "📋 Results will be posted to PR #${{ github.event.number }} when ready"
302+ echo "✅ **$CLIENT_REPO**: $WORKFLOW_NAME triggered - [Monitor Progress](https://github.com/$CLIENT_REPO/actions)" >> $GITHUB_STEP_SUMMARY
303+ DISPATCH_SUCCESS=true
304+ break
305+ else
306+ echo "⚠️ $CLIENT_REPO dispatch attempt $RETRY_COUNT failed"
307+ [ $RETRY_COUNT -lt $MAX_RETRIES ] && sleep 5
308+ fi
309+ done
310+
311+ if [ "$DISPATCH_SUCCESS" = "false" ]; then
312+ echo "::error::Failed to trigger $CLIENT_REPO after $MAX_RETRIES attempts"
313+ echo "::warning::$CLIENT_LABEL breaking change detection will be skipped"
314+ echo "❌ **$CLIENT_REPO**: Failed to trigger - [Manual Check Required](https://github.com/$CLIENT_REPO)" >> $GITHUB_STEP_SUMMARY
315+ fi
316+
317+ - name : Wait for client workflow completion
318+ timeout-minutes : 12
319+ run : |
320+ echo "⏳ Waiting for all client type checking workflows to complete..."
321+
322+ WAIT_START_TIME=$(date +%s)
323+ MAX_WAIT_SECONDS=600 # 10 minutes max wait
324+ POLL_INTERVAL=30 # Check every 30 seconds
325+
326+ # Expected clients list - expand when adding mobile
327+ EXPECTED_CLIENTS=("typescript")
328+ COMPLETED_CLIENTS=()
329+
330+ while true; do
331+ CURRENT_TIME=$(date +%s)
332+ ELAPSED=$((CURRENT_TIME - WAIT_START_TIME))
333+
334+ # Check timeout
335+ if [ $ELAPSED -gt $MAX_WAIT_SECONDS ]; then
336+ echo "⏰ Timeout reached after ${ELAPSED}s - proceeding with available results"
337+ echo "::warning::Some client workflows may still be running"
338+ break
339+ fi
340+
341+ echo "🔍 Polling for completion markers (${ELAPSED}s elapsed)..."
342+
343+ # Check for completion markers in PR comments
344+ COMMENTS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.number }}/comments \
345+ --jq '.[] | select(.body | contains("<!-- SDK-BREAKING-CHANGE-COMPLETION:")) | .body')
346+
347+ # Reset completed clients for this check
348+ COMPLETED_CLIENTS=()
349+
350+ # Check each expected client
351+ for CLIENT in "${EXPECTED_CLIENTS[@]}"; do
352+ if echo "$COMMENTS" | grep -q "<!-- SDK-BREAKING-CHANGE-COMPLETION:$CLIENT -->"; then
353+ COMPLETED_CLIENTS+=("$CLIENT")
354+ echo "✅ $CLIENT workflow completed"
355+ else
356+ echo "⏳ $CLIENT workflow still running..."
357+ fi
358+ done
359+
360+ # Check if all clients completed
361+ if [ ${#COMPLETED_CLIENTS[@]} -eq ${#EXPECTED_CLIENTS[@]} ]; then
362+ echo "🎉 All client workflows completed!"
363+ break
364+ fi
365+
366+ # Wait before next poll
367+ echo "⏸️ Waiting ${POLL_INTERVAL}s before next check..."
368+ sleep $POLL_INTERVAL
369+ done
370+
371+ # Summary
372+ echo ""
373+ echo "=== Final Status ==="
374+ echo "Completed clients: ${COMPLETED_CLIENTS[*]}"
375+ echo "Total wait time: ${ELAPSED}s"
376+
377+ if [ ${#COMPLETED_CLIENTS[@]} -eq ${#EXPECTED_CLIENTS[@]} ]; then
378+ echo "✅ All expected client workflows completed successfully"
379+ echo "status=complete" >> $GITHUB_OUTPUT
380+ else
381+ MISSING_CLIENTS=()
382+ for CLIENT in "${EXPECTED_CLIENTS[@]}"; do
383+ if [[ ! " ${COMPLETED_CLIENTS[*]} " =~ " ${CLIENT} " ]]; then
384+ MISSING_CLIENTS+=("$CLIENT")
385+ fi
386+ done
387+ echo "⚠️ Some workflows incomplete: ${MISSING_CLIENTS[*]}"
388+ echo "status=partial" >> $GITHUB_OUTPUT
389+ fi
390+
391+ # Update GitHub step summary
392+ echo "⏱️ **Synchronization Complete**: Waited ${ELAPSED}s for client workflows" >> $GITHUB_STEP_SUMMARY
393+ echo "📊 **Completed**: ${#COMPLETED_CLIENTS[@]}/${#EXPECTED_CLIENTS[@]} clients" >> $GITHUB_STEP_SUMMARY
394+ - name : Report final workflow status
395+ run : |
396+ echo "📊 Final SDK workflow status summary"
397+
398+ # Analyze all PR comments for breaking change results
399+ COMMENTS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.number }}/comments \
400+ --jq '.[] | select(.body | contains("SDK-BREAKING-CHANGE-CHECK")) | .body')
401+
402+ BREAKING_DETECTED=false
403+ CLIENT_RESULTS=()
404+
405+ for CLIENT in typescript; do # Expand when adding mobile
406+ if echo "$COMMENTS" | grep -q "❌ TypeScript Breaking Changes Detected" && [[ "$CLIENT" == "typescript" ]]; then
407+ BREAKING_DETECTED=true
408+ CLIENT_RESULTS+=("❌ $CLIENT: Breaking changes detected")
409+ elif echo "$COMMENTS" | grep -q "✅ TypeScript Compatibility Check Passed" && [[ "$CLIENT" == "typescript" ]]; then
410+ CLIENT_RESULTS+=("✅ $CLIENT: No breaking changes")
411+ else
412+ CLIENT_RESULTS+=("⚠️ $CLIENT: Status unclear or incomplete")
413+ fi
414+ done
415+
416+ echo ""
417+ echo "=== Breaking Change Detection Results ==="
418+ for RESULT in "${CLIENT_RESULTS[@]}"; do
419+ echo "$RESULT"
420+ done
421+
422+ # Set overall status
423+ if [ "$BREAKING_DETECTED" = "true" ]; then
424+ echo ""
425+ echo "🚨 BREAKING CHANGES DETECTED - Review PR comments for details"
426+ echo "⚠️ This is non-blocking - PR can still be merged if changes are intentional"
427+ echo "status=breaking-changes" >> $GITHUB_OUTPUT
428+ else
429+ echo ""
430+ echo "✅ No breaking changes detected across all clients"
431+ echo "status=clean" >> $GITHUB_OUTPUT
432+ fi
433+
434+ # Add results to job summary
435+ echo "## 🔍 Breaking Change Detection Results" >> $GITHUB_STEP_SUMMARY
436+ for RESULT in "${CLIENT_RESULTS[@]}"; do
437+ echo "- $RESULT" >> $GITHUB_STEP_SUMMARY
438+ done
439+
440+ if [ "$BREAKING_DETECTED" = "true" ]; then
441+ echo "" >> $GITHUB_STEP_SUMMARY
442+ echo "⚠️ **Breaking changes detected** - See PR comments for migration guidance" >> $GITHUB_STEP_SUMMARY
443+ fi
0 commit comments