Skip to content

Commit dd42ddf

Browse files
committed
Fixes
1 parent 848498b commit dd42ddf

2 files changed

Lines changed: 19 additions & 23 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ jobs:
3939
steps:
4040
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
4141
with:
42-
ref: ${{ github.event.pull_request.head.sha || github.sha }}
43-
fetch-depth: ${{ needs.files-changed.outputs.config_kt == 'true' && 0 || 1 }}
42+
fetch-depth: 0
4443

4544
- name: Run detector unit tests
4645
run: python3 -m unittest discover -s scripts -p 'test_detect_sdk_name_changes.py'
@@ -50,6 +49,9 @@ jobs:
5049
continue-on-error: true
5150
id: detect
5251
run: |
52+
git fetch --no-tags origin \
53+
"${{ github.event.pull_request.base.sha }}" \
54+
"${{ github.event.pull_request.head.sha }}"
5355
changes=$(python3 scripts/detect_sdk_name_changes.py \
5456
--base "${{ github.event.pull_request.base.sha }}" \
5557
--head "${{ github.event.pull_request.head.sha }}")
@@ -101,7 +103,7 @@ jobs:
101103
[
102104
'### ⚠️ SDK name check failed',
103105
'',
104-
'Could not parse `*SDK_NAME` declarations in `Config.kt`. Use `val FOO_SDK_NAME = "..."` with an optional `$OTHER_SDK_NAME` prefix.',
106+
'Could not compare `*SDK_NAME` declarations in `Config.kt`. Use `val FOO_SDK_NAME = "..."` with an optional `$OTHER_SDK_NAME` prefix.',
105107
'',
106108
'See the **Detect SDK name changes** step logs for details.',
107109
'',

‎scripts/detect_sdk_name_changes.py‎

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,6 @@ def find_sdk_name_changes(
6262
return added, removed
6363

6464

65-
def git_merge_base(base: str, head: str) -> str:
66-
return subprocess.check_output(
67-
["git", "merge-base", base, head],
68-
text=True,
69-
stderr=subprocess.PIPE,
70-
).strip()
71-
72-
7365
def git_show(ref: str, path: str) -> str:
7466
try:
7567
return subprocess.check_output(
@@ -86,8 +78,7 @@ def git_show(ref: str, path: str) -> str:
8678
def read_config_source(base: str | None, head: str | None, config_path: str) -> tuple[str, str]:
8779
if base is None or head is None:
8880
raise ValueError("Both base and head refs are required")
89-
merge_base = git_merge_base(base, head)
90-
return git_show(merge_base, config_path), git_show(head, config_path)
81+
return git_show(base, config_path), git_show(head, config_path)
9182

9283

9384
def format_changes(added: list[str], removed: list[str]) -> str:
@@ -112,22 +103,25 @@ def main(argv: list[str] | None = None) -> int:
112103
parser.add_argument("--config-path", default=CONFIG_PATH)
113104
args = parser.parse_args(argv)
114105

115-
if args.base_file and args.head_file:
116-
base_content = args.base_file.read_text(encoding="utf-8")
117-
head_content = args.head_file.read_text(encoding="utf-8")
118-
elif args.base and args.head:
119-
base_content, head_content = read_config_source(
120-
args.base, args.head, args.config_path
121-
)
122-
else:
123-
parser.error("Provide --base/--head or --base-file/--head-file")
124-
125106
try:
107+
if args.base_file and args.head_file:
108+
base_content = args.base_file.read_text(encoding="utf-8")
109+
head_content = args.head_file.read_text(encoding="utf-8")
110+
elif args.base and args.head:
111+
base_content, head_content = read_config_source(
112+
args.base, args.head, args.config_path
113+
)
114+
else:
115+
parser.error("Provide --base/--head or --base-file/--head-file")
116+
126117
base_sdk = parse_sdk_constants(base_content)
127118
head_sdk = parse_sdk_constants(head_content)
128119
except ValueError as error:
129120
print(f"error: {error}", file=sys.stderr)
130121
return 1
122+
except subprocess.CalledProcessError as error:
123+
print(f"error: git command failed: {' '.join(error.cmd)}", file=sys.stderr)
124+
return 1
131125

132126
added, removed = find_sdk_name_changes(base_sdk, head_sdk)
133127
print(format_changes(added, removed))

0 commit comments

Comments
 (0)