Skip to content

Commit 848498b

Browse files
committed
More refinements
1 parent 30aa71b commit 848498b

4 files changed

Lines changed: 65 additions & 27 deletions

File tree

‎.github/workflows/sdk-name-check.yml‎

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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).
45
name: 'SDK Name Check'
56
run-name: sdk.name change check (Config.kt)
67

@@ -29,7 +30,7 @@ jobs:
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,
@@ -77,6 +77,45 @@ jobs:
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'));

‎buildSrc/src/main/java/Config.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ object Config {
4040
}
4141

4242
object Sentry {
43-
// New *SDK_NAME constants are checked by .github/workflows/sdk-name-check.yml.
43+
// .github/workflows/sdk-name-check.yml expects all SDK name declarations to end in `*SDK_NAME`.
4444
val SENTRY_JAVA_SDK_NAME = "sentry.java"
4545
val SENTRY_ANDROID_SDK_NAME = "$SENTRY_JAVA_SDK_NAME.android"
4646
val SENTRY_TIMBER_SDK_NAME = "$SENTRY_ANDROID_SDK_NAME.timber"

‎scripts/detect_sdk_name_changes.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def resolve_rhs(rhs: str, resolved: dict[str, str]) -> str:
4040

4141

4242
def expand_interpolation(value: str, resolved: dict[str, str]) -> str:
43+
if "${" in value:
44+
raise ValueError(f"Unsupported brace interpolation in SDK name value: {value}")
45+
4346
def replace(match: re.Match[str]) -> str:
4447
name = match.group(1)
4548
if name not in resolved:

‎scripts/test_detect_sdk_name_changes.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ class DetectSdkNameChangesTest(unittest.TestCase):
6969
val SENTRY_FOO_SDK_NAME = buildSdkName("foo")
7070
}
7171
}
72+
"""
73+
74+
HEAD_WITH_BRACE_INTERPOLATION = """
75+
object Config {
76+
object Sentry {
77+
val SENTRY_JAVA_SDK_NAME = "sentry.java"
78+
val SENTRY_FOO_SDK_NAME = "${SENTRY_JAVA_SDK_NAME}.foo"
79+
}
80+
}
7281
"""
7382

7483
def test_no_changes(self) -> None:
@@ -103,6 +112,10 @@ def test_parse_failure_returns_error(self) -> None:
103112
with self.assertRaises(ValueError):
104113
parse_sdk_constants(self.HEAD_WITH_INVALID_RHS)
105114

115+
def test_brace_interpolation_is_rejected(self) -> None:
116+
with self.assertRaises(ValueError):
117+
parse_sdk_constants(self.HEAD_WITH_BRACE_INTERPOLATION)
118+
106119
def test_cli_reports_parse_failure(self) -> None:
107120
with tempfile.TemporaryDirectory() as temp_dir:
108121
temp_path = Path(temp_dir)

0 commit comments

Comments
 (0)