-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ci(sdks): Warn against non-trivial changes to multiple SDKs #17397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
szokeasaurusrex
wants to merge
3
commits into
master
Choose a base branch
from
szokeasaurusrex/single-sdk-change-enforcement
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| name: Enforce Single SDK Changes | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'docs/platforms/**' | ||
| - 'platform-includes/**' | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| check-sdk-diff-scope: | ||
| name: Check SDK diff scope | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Set up bun | ||
| uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2 | ||
|
|
||
| - name: Compute diff and evaluate | ||
| id: evaluate | ||
| run: | | ||
| set +e | ||
| SDK_LIST=$(git diff --numstat origin/${{ github.base_ref }}...HEAD | bun scripts/check-sdk-diff-scope.ts) | ||
| EXIT=$? | ||
| if [ $EXIT -eq 0 ]; then | ||
| echo "violation=false" >> "$GITHUB_OUTPUT" | ||
| elif [ -n "$SDK_LIST" ]; then | ||
| echo "violation=true" >> "$GITHUB_OUTPUT" | ||
| echo "sdk_list=$SDK_LIST" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "error=true" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Post, update, or delete PR comment | ||
| if: steps.evaluate.outputs.error != 'true' | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 | ||
| with: | ||
| script: | | ||
| const MARKER = '<!-- enforce-single-sdk-changes -->'; | ||
| const violation = '${{ steps.evaluate.outputs.violation }}' === 'true'; | ||
|
|
||
| const {data: comments} = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| }); | ||
| const existing = comments.find(c => c.body.includes(MARKER)); | ||
|
|
||
| if (violation) { | ||
| const sdkList = ${{ toJSON(steps.evaluate.outputs.sdk_list) }}; | ||
| const body = `${MARKER} | ||
| ### 🚫 Non-trivial changes to multiple SDKs | ||
|
|
||
| This PR contains non-trivial changes to multiple SDKs: ${sdkList}. | ||
| Changes to multiple SDKs should be submitted as separate PRs: **one PR per SDK**. | ||
|
|
||
| Please **split this PR** accordingly. Thank you in advance! 🙏`; | ||
|
|
||
| if (existing && existing.body !== body) { | ||
| await github.rest.issues.updateComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existing.id, | ||
| body, | ||
| }); | ||
| } else if (!existing) { | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| body, | ||
| }); | ||
| } | ||
| } else if (existing) { | ||
| await github.rest.issues.deleteComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existing.id, | ||
| }); | ||
| } | ||
|
|
||
| - name: Fail on unexpected error | ||
| if: steps.evaluate.outputs.error == 'true' | ||
| run: | | ||
| echo "::error::SDK diff check failed unexpectedly — the script produced no output. Check the job logs for details." | ||
| exit 1 | ||
|
|
||
| - name: Fail check | ||
| if: steps.evaluate.outputs.violation == 'true' | ||
| run: exit 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/usr/bin/env bun | ||
| import {readFileSync} from 'fs'; | ||
| /** | ||
| * Enforces the policy that a single PR should only contain non-trivial changes | ||
| * to one SDK at a time. PRs spanning multiple SDKs are harder to review and | ||
| * increase the risk of inconsistencies between platforms. | ||
| * | ||
| * Reads `git diff --numstat` from stdin (one `<added>\t<deleted>\t<path>` line | ||
| * per changed file) and attributes each file to an SDK. If the total lines | ||
| * changed for at least MIN_VIOLATING_SDKS SDKs each exceed LINE_THRESHOLD, | ||
| * the script prints the violating SDK list and exits 1. | ||
| * | ||
| * Used in CI as: | ||
| * git diff --numstat origin/$BASE...HEAD | bun scripts/check-sdk-diff-scope.ts | ||
| */ | ||
|
|
||
| /** SDKs with fewer total changed lines than this are ignored (e.g. a one-line typo fix that touches two SDKs should not block the PR). */ | ||
| const LINE_THRESHOLD = 5; | ||
| /** Minimum number of SDKs that must exceed LINE_THRESHOLD for the check to fail. */ | ||
| const MIN_VIOLATING_SDKS = 2; | ||
|
|
||
| /** | ||
| * Extracts the SDK name from a changed file path, or returns null if the | ||
| * file is not attributed to any SDK. | ||
| * | ||
| * Two path patterns are recognised: | ||
| * - docs/platforms/<sdk>/... → sdk is the first path segment after platforms/ | ||
| * - platform-includes/.../<sdk>.<variant>.mdx → sdk is the first dot-segment of the filename | ||
| * e.g. `javascript.angular.mdx` → `javascript`, `react-native.mdx` → `react-native` | ||
| */ | ||
| function sdkForPath(path: string): string | null { | ||
| const segs = path.split('/'); | ||
| if (segs[0] === 'docs' && segs[1] === 'platforms') { | ||
| return segs[2] ?? null; | ||
| } | ||
| if (segs[0] === 'platform-includes') { | ||
| return segs.at(-1)!.split('.')[0]; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| // Accumulate total lines changed (added + deleted) per SDK. | ||
| const sdkLines = new Map<string, number>(); | ||
|
|
||
| const input = readFileSync(0, 'utf-8'); | ||
| for (const line of input.split('\n')) { | ||
| const [added, deleted, path] = line.split('\t'); | ||
| if (!path || added === '-') continue; // binary file or empty line | ||
| const sdk = sdkForPath(path.trim()); | ||
| if (sdk) { | ||
| sdkLines.set(sdk, (sdkLines.get(sdk) ?? 0) + +added + +deleted); | ||
| } | ||
| } | ||
|
|
||
| // Collect SDKs that exceed the line threshold, ignoring trivial touches. | ||
| const violating = [...sdkLines.entries()] | ||
| .filter(([, n]) => n > LINE_THRESHOLD) | ||
| .map(([sdk]) => sdk) | ||
| .sort(); | ||
|
|
||
| if (violating.length >= MIN_VIOLATING_SDKS) { | ||
| // Print the list for the CI step to capture and include in the PR comment. | ||
| console.log(violating.map(s => `\`${s}\``).join(', ')); | ||
| process.exit(1); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-SDK files misclassified as SDK names cause false positives
Low Severity
The
sdkForPathfunction doesn't filter out non-SDK files, causing them to be counted as separate "SDKs." Forplatform-includes, files like_default.mdx(which exists inplatform-includes/capture-error/) return_defaultas the SDK name. Fordocs/platforms, the fileindex.mdxreturnsindex.mdxas the SDK name. If any of these non-SDK files accumulate >5 changed lines alongside a real SDK, the check produces a false-positive violation, which could erode trust in the advisory CI job.Additional Locations (1)
scripts/check-sdk-diff-scope.ts#L32-L35Reviewed by Cursor Bugbot for commit 6d2cb4d. Configure here.