Files
MapLibreParticleLab/tools/particle_release_pipeline/prepare_release.py

129 lines
4.6 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
from __future__ import annotations
import json
import re
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
ANDROID_VERSION_FILE = ROOT / "platform/android/VERSION"
IOS_VERSION_FILE = ROOT / "platform/ios/VERSION"
RN_ROOT = ROOT / "packages/maplibre-particle-rn"
def die(message: str) -> None:
raise SystemExit(f"PREPARE_RELEASE_ERROR: {message}")
def base_version(value: str) -> str:
return re.sub(r"-particle\.\d+$", "", value.strip())
def replace_current_particle(path: Path, previous: str, target: str) -> None:
text = path.read_text()
updated, count = re.subn(re.escape(previous), target, text)
if count == 0:
die(f"previous RN/Native version {previous} not found in {path}")
path.write_text(updated)
def replace_exact(path: Path, old: str, new: str) -> None:
text = path.read_text()
if text.count(old) != 1:
die(f"expected exactly one version reference {old!r} in {path}")
path.write_text(text.replace(old, new, 1))
def update_changelog(target: str, revision: int) -> None:
path = RN_ROOT / "CHANGELOG.md"
text = path.read_text()
heading = f"## {target}(Android / iOS 统一发行)"
if heading in text:
return
marker = "## Unreleased\n\n"
if marker not in text:
die("CHANGELOG missing Unreleased heading")
entry = (
marker
+ heading
+ "\n\n"
+ "- Mac unified release pipeline 统一生成 Android Native、RN package 与 iOS SwiftPM/XCFramework;"
+ f"共享 Particle revision {revision}。\n"
)
path.write_text(text.replace(marker, entry, 1))
def main() -> None:
if len(sys.argv) != 2 or not sys.argv[1].isdigit():
die("usage: prepare_release.py <particle-revision>")
revision = int(sys.argv[1])
if revision < 1:
die("revision must be positive")
android_base = base_version(ANDROID_VERSION_FILE.read_text())
ios_base = base_version(IOS_VERSION_FILE.read_text())
android_version = f"{android_base}-particle.{revision}"
ios_version = f"{ios_base}-particle.{revision}"
ANDROID_VERSION_FILE.write_text(android_version + "\n")
package_path = RN_ROOT / "package.json"
package = json.loads(package_path.read_text())
previous_rn_version = package["version"]
package["version"] = android_version
# v22 upgrades the host MapLibre React Native baseline together with native.
package["peerDependencies"]["@maplibre/maplibre-react-native"] = "11.5.0"
package["devDependencies"]["@maplibre/maplibre-react-native"] = "11.5.0"
package_path.write_text(json.dumps(package, ensure_ascii=False, indent=2) + "\n")
for relative in (
"packages/maplibre-particle-rn/android/build.gradle",
"packages/maplibre-particle-rn/app.plugin.js",
"integration/react-native/MapLibreParticleRNTestHost/plugins/withParticleNativeAndroid.js",
):
replace_current_particle(ROOT / relative, previous_rn_version, android_version)
readme = RN_ROOT / "README.md"
readme_text = readme.read_text()
if previous_rn_version not in readme_text:
die("README missing previous RN version")
readme_text = readme_text.replace(previous_rn_version, android_version)
readme_text = readme_text.replace("11.3.6", "11.5.0")
readme_text = re.sub(
r"必须指向同一 `\.\d+`",
f"必须指向同一 `.{revision}`",
readme_text,
)
readme.write_text(readme_text)
# Both Expo plugins must request the same upstream Native base as the new AAR.
for relative in (
"packages/maplibre-particle-rn/app.plugin.js",
"integration/react-native/MapLibreParticleRNTestHost/plugins/withParticleNativeAndroid.js",
):
replace_exact(ROOT / relative,
'nativeVersion", "13.4.1"',
f'nativeVersion", "{android_base}"')
podspec = RN_ROOT / "MapLibreParticleRN.podspec"
podtext = podspec.read_text()
if podtext.count('11.3.6') != 2:
die("podspec must contain exactly two pinned RN 11.3.6 references")
podspec.write_text(podtext.replace("11.3.6", "11.5.0"))
host_path = ROOT / "integration/react-native/MapLibreParticleRNTestHost/package.json"
host = json.loads(host_path.read_text())
host["dependencies"]["@maplibre/maplibre-react-native"] = "11.5.0"
host_path.write_text(json.dumps(host, ensure_ascii=False, indent=2) + "\n")
update_changelog(android_version, revision)
print(f"PARTICLE_REVISION={revision}")
print(f"ANDROID_RN_VERSION={android_version}")
print(f"IOS_DISTRIBUTION_VERSION={ios_version}")
if __name__ == "__main__":
main()