11# When sdk.name values are added, removed, or updated in Config.kt, posts a PR comment
22# reminding authors to update the sdk_map spreadsheet for Looker/Hex reporting.
33# Warn-only: does not block merge. See scripts/detect_sdk_name_changes.py.
4+ # Fork PRs cannot post comments (read-only GITHUB_TOKEN on pull_request).
45name : ' SDK Name Check'
56run-name : sdk.name change check (Config.kt)
67
2930 filters : .github/file-filters.yml
3031
3132 sdk-name-check :
32- name : ${{ needs.files-changed.outputs.config_kt == 'true' && ' SDK name check' || 'SDK name detector tests' }}
33+ name : SDK name check
3334 if : needs.files-changed.outputs.config_kt == 'true' || needs.files-changed.outputs.sdk_name_check_scripts == 'true'
3435 needs : files-changed
3536 runs-on : ubuntu-latest
@@ -38,34 +39,33 @@ jobs:
3839 steps :
3940 - uses : actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
4041 with :
42+ ref : ${{ github.event.pull_request.head.sha || github.sha }}
4143 fetch-depth : ${{ needs.files-changed.outputs.config_kt == 'true' && 0 || 1 }}
4244
4345 - name : Run detector unit tests
4446 run : python3 -m unittest discover -s scripts -p 'test_detect_sdk_name_changes.py'
4547
4648 - name : Detect SDK name changes
4749 if : needs.files-changed.outputs.config_kt == 'true'
50+ continue-on-error : true
4851 id : detect
4952 run : |
5053 changes=$(python3 scripts/detect_sdk_name_changes.py \
5154 --base "${{ github.event.pull_request.base.sha }}" \
52- --head "${{ github.sha }}")
55+ --head "${{ github.event.pull_request.head. sha }}")
5356 echo "changes=${changes}" >> "$GITHUB_OUTPUT"
5457
5558 - name : Update PR comment
56- if : needs.files-changed.outputs.config_kt == 'true'
59+ if : needs.files-changed.outputs.config_kt == 'true' && (steps.detect.outcome == 'success' || steps.detect.outcome == 'failure')
5760 uses : actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
5861 env :
5962 SDK_NAME_CHANGES : ${{ steps.detect.outputs.changes }}
63+ DETECT_OUTCOME : ${{ steps.detect.outcome }}
6064 with :
6165 script : |
6266 const marker = '<!-- sdk-name-check -->';
63- const changes = JSON.parse(process.env.SDK_NAME_CHANGES || '{}');
64- const added = changes.added || [];
65- const removed = changes.removed || [];
66- const sheetUrl = changes.sdk_map_sheet_url;
6767
68- const { data: comments } = await github.rest.issues.listComments( {
68+ const comments = await github.paginate(github. rest.issues.listComments, {
6969 owner: context.repo.owner,
7070 repo: context.repo.repo,
7171 issue_number: context.issue.number,
7777 comment.user?.type === 'Bot',
7878 );
7979
80+ const upsertComment = async (body) => {
81+ if (existing) {
82+ await github.rest.issues.updateComment({
83+ owner: context.repo.owner,
84+ repo: context.repo.repo,
85+ comment_id: existing.id,
86+ body,
87+ });
88+ return;
89+ }
90+
91+ await github.rest.issues.createComment({
92+ owner: context.repo.owner,
93+ repo: context.repo.repo,
94+ issue_number: context.issue.number,
95+ body,
96+ });
97+ };
98+
99+ if (process.env.DETECT_OUTCOME === 'failure') {
100+ await upsertComment(
101+ [
102+ '### ⚠️ SDK name check failed',
103+ '',
104+ 'Could not parse `*SDK_NAME` declarations in `Config.kt`. Use `val FOO_SDK_NAME = "..."` with an optional `$OTHER_SDK_NAME` prefix.',
105+ '',
106+ 'See the **Detect SDK name changes** step logs for details.',
107+ '',
108+ marker,
109+ ].join('\n'),
110+ );
111+ return;
112+ }
113+
114+ const changes = JSON.parse(process.env.SDK_NAME_CHANGES || '{}');
115+ const added = changes.added || [];
116+ const removed = changes.removed || [];
117+ const sheetUrl = changes.sdk_map_sheet_url;
118+
80119 if (added.length === 0 && removed.length === 0) {
81120 if (existing) {
82121 await github.rest.issues.deleteComment({
@@ -114,21 +153,4 @@ jobs:
114153 }
115154
116155 sections.push(marker);
117- const body = sections.join('\n');
118-
119- if (existing) {
120- await github.rest.issues.updateComment({
121- owner: context.repo.owner,
122- repo: context.repo.repo,
123- comment_id: existing.id,
124- body,
125- });
126- return;
127- }
128-
129- await github.rest.issues.createComment({
130- owner: context.repo.owner,
131- repo: context.repo.repo,
132- issue_number: context.issue.number,
133- body,
134- });
156+ await upsertComment(sections.join('\n'));
0 commit comments