From 0a82053a1e8ca9f5f430558ddf34efde86387057 Mon Sep 17 00:00:00 2001 From: caiyiping Date: Wed, 2 Dec 2026 21:51:42 +0800 Subject: [PATCH] Fix Apple packaging without a supplied SDK archive Select the declared published Agora pod when sdk_url is empty instead of retaining an empty local sdk pod. Keep injected package selection for supplied archives and cover all five Apple Podfiles in regression checks. --- .github/ci/README.md | 4 +- .github/ci/build/modify_podfile.py | 9 +- .github/ci/build/tests/test_modify_podfile.py | 84 +++++++++++++++++++ 3 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 .github/ci/build/tests/test_modify_podfile.py diff --git a/.github/ci/README.md b/.github/ci/README.md index c74c621ad..801bc66c6 100644 --- a/.github/ci/README.md +++ b/.github/ci/README.md @@ -9,10 +9,10 @@ policy helpers and the release packaging scripts loaded by Jenkins. | `build/` | Jenkins platform Groovy entry points call packaging scripts, which use each project's `cloud_build.*` adapters. IPA entry points also depend on external Jenkins configuration. | Run the signing-preflight unit tests below; actual signing, private SDK injection and artifact verification belong to Jenkins. | | `policy/` | `repository-policy.yml` runs AI asset validation and native template lifecycle regressions; `.git-hooks/` supplies the local credential and commit-message checks. | Follow [AI validation](../../docs/ai/README.md) for venv setup and policy checks. | -After creating the venv described above, run the packaging helper tests from the repository root: +After creating the venv described above, run the packaging helper tests (signing preflight and public/local SDK dependency selection) from the repository root: ```bash -.venv/bin/python -m unittest discover --start-directory .github/ci/build/tests --pattern 'test_check_ios_signing_assets.py' +.venv/bin/python -m unittest discover --start-directory .github/ci/build/tests --pattern 'test_*.py' ``` Keep the Jenkins entry point and `build/` paths stable: external jobs and existing scripts diff --git a/.github/ci/build/modify_podfile.py b/.github/ci/build/modify_podfile.py index 787d9c7a8..52d01f9f6 100644 --- a/.github/ci/build/modify_podfile.py +++ b/.github/ci/build/modify_podfile.py @@ -1,4 +1,5 @@ -import os, sys +import re +import sys def modfiy(path, sdk_flag): with open(path, 'r', encoding='utf-8') as file: @@ -7,9 +8,11 @@ def modfiy(path, sdk_flag): if "pod 'Agora" in line: if sdk_flag: line = '\t'+"pod 'sdk', :path => '../../sdk.podspec'" + "\n" + else: + # Without an SDK package, use the declared public pod and version. + line = re.sub(r"^(\s*)#\s*(pod\s)", r"\1\2", line) elif "pod 'sdk" in line: - if sdk_flag: - line = "" + line = "" elif 'sh .download_script' in line: line = line.replace('true', 'false') + "\n" contents.append(line) diff --git a/.github/ci/build/tests/test_modify_podfile.py b/.github/ci/build/tests/test_modify_podfile.py new file mode 100644 index 000000000..6dce8e228 --- /dev/null +++ b/.github/ci/build/tests/test_modify_podfile.py @@ -0,0 +1,84 @@ +import importlib.util +from pathlib import Path +import re +import subprocess +import tempfile +import unittest + + +BUILD_DIR = Path(__file__).resolve().parents[1] +REPO_ROOT = BUILD_DIR.parents[2] +SPEC = importlib.util.spec_from_file_location("modify_podfile", BUILD_DIR / "modify_podfile.py") +MODULE = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(MODULE) +PROJECTS = { + "iOS/APIExample": "AgoraRtcEngine_iOS", + "iOS/APIExample-Audio": "AgoraAudio_iOS", + "iOS/APIExample-SwiftUI": "AgoraRtcEngine_iOS", + "iOS/APIExample-OC": "AgoraRtcEngine_iOS", + "macOS": "AgoraRtcEngine_macOS", +} + + +def active_sdk_dependencies(content): + return re.findall(r"^\s*pod\s+['\"]((?:Agora|sdk)[^'\"]*)['\"](.*)$", content, re.MULTILINE) + + +class ModifyPodfileTests(unittest.TestCase): + def transform(self, project, supplied_sdk): + original = (REPO_ROOT / project / "Podfile").read_text(encoding="utf-8") + with tempfile.TemporaryDirectory() as directory: + path = Path(directory) / "Podfile" + path.write_text(original, encoding="utf-8") + MODULE.modfiy(str(path), supplied_sdk) + return original, path.read_text(encoding="utf-8") + + def test_no_sdk_url_selects_exact_published_sdk(self): + for project, pod in PROJECTS.items(): + with self.subTest(project=project): + original, result = self.transform(project, False) + version = re.search(rf"pod '{pod}', '([^']+)'", original).group(1) + self.assertEqual(active_sdk_dependencies(result), [(pod, f", '{version}'")]) + + def test_supplied_sdk_selects_only_injected_package(self): + for project in PROJECTS: + with self.subTest(project=project): + _, result = self.transform(project, True) + self.assertEqual(active_sdk_dependencies(result), [("sdk", ", :path => '../../sdk.podspec'")]) + + def test_preserves_non_sdk_configuration_and_disabled_download_hook(self): + for project in PROJECTS: + for supplied_sdk in (False, True): + with self.subTest(project=project, supplied_sdk=supplied_sdk): + original, result = self.transform(project, supplied_sdk) + def unrelated(content): + return [line for line in content.splitlines() if line.strip() + and "pod 'Agora" not in line and "pod 'sdk" not in line + and "sh .download_script" not in line] + self.assertEqual(unrelated(result), unrelated(original)) + hooks = [line for line in result.splitlines() if "sh .download_script" in line] + self.assertTrue(hooks) + self.assertTrue(all(line.lstrip().startswith("#") for line in hooks)) + + def test_public_dependency_selection_is_repeatable(self): + for project in PROJECTS: + with self.subTest(project=project), tempfile.TemporaryDirectory() as directory: + _, result = self.transform(project, False) + path = Path(directory) / "Podfile" + path.write_text(result, encoding="utf-8") + MODULE.modfiy(str(path), False) + self.assertEqual(active_sdk_dependencies(path.read_text()), active_sdk_dependencies(result)) + + def test_generated_podfiles_have_valid_ruby_syntax(self): + for project in PROJECTS: + for supplied_sdk in (False, True): + with self.subTest(project=project, supplied_sdk=supplied_sdk), tempfile.TemporaryDirectory() as directory: + _, result = self.transform(project, supplied_sdk) + path = Path(directory) / "Podfile" + path.write_text(result, encoding="utf-8") + check = subprocess.run(["ruby", "-c", str(path)], capture_output=True, text=True) + self.assertEqual(check.returncode, 0, check.stdout + check.stderr) + + +if __name__ == "__main__": + unittest.main()