181 lines
5.4 KiB
Python
Executable File
181 lines
5.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
||
from __future__ import annotations
|
||
|
||
import hashlib
|
||
import json
|
||
import os
|
||
import re
|
||
import sys
|
||
from datetime import datetime, timezone
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(__file__).resolve().parents[2]
|
||
PUBLIC = "https://pbf.jpcn.ccwu.cc"
|
||
|
||
|
||
def sha256(path: Path) -> str:
|
||
h = hashlib.sha256()
|
||
with path.open("rb") as handle:
|
||
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
|
||
h.update(chunk)
|
||
return h.hexdigest()
|
||
|
||
|
||
def base_version(value: str) -> str:
|
||
return re.sub(r"-particle\.\d+$", "", value.strip())
|
||
|
||
|
||
def artifact(path: Path, url: str) -> dict:
|
||
return {
|
||
"fileName": path.name,
|
||
"sizeBytes": path.stat().st_size,
|
||
"sha256": sha256(path),
|
||
"url": url,
|
||
}
|
||
|
||
|
||
def main() -> None:
|
||
if len(sys.argv) != 4:
|
||
raise SystemExit(
|
||
"usage: finalize_release.py <revision> <source-commit> <artifact-dir>"
|
||
)
|
||
|
||
revision = int(sys.argv[1])
|
||
source_commit = sys.argv[2]
|
||
artifact_dir = Path(sys.argv[3])
|
||
|
||
android_base = base_version((ROOT / "platform/android/VERSION").read_text())
|
||
ios_base = base_version((ROOT / "platform/ios/VERSION").read_text())
|
||
android_version = f"{android_base}-particle.{revision}"
|
||
ios_version = f"{ios_base}-particle.{revision}"
|
||
|
||
aar_name = f"android-sdk-particle-opengl-{android_version}.aar"
|
||
tgz_name = f"navsea-maplibre-particle-rn-{android_version}.tgz"
|
||
ios_name = "MapLibre.dynamic.xcframework.zip"
|
||
|
||
aar = artifact(
|
||
artifact_dir / aar_name,
|
||
f"{PUBLIC}/maven/cc/navsea/maplibre/android-sdk-particle-opengl/"
|
||
f"{android_version}/{aar_name}",
|
||
)
|
||
tgz = artifact(
|
||
artifact_dir / tgz_name,
|
||
f"{PUBLIC}/npm/{tgz_name}",
|
||
)
|
||
ios = artifact(
|
||
artifact_dir / ios_name,
|
||
f"{PUBLIC}/swift/maplibre-particle/{ios_version}/{ios_name}",
|
||
)
|
||
|
||
manifest = {
|
||
"schemaVersion": 2,
|
||
"releaseState": "PUBLISHED_PUBLIC_READBACK_PASS",
|
||
"particleRevision": revision,
|
||
"sourceCommit": source_commit,
|
||
"generatedAtUtc": datetime.now(timezone.utc).isoformat(),
|
||
"reactNative": {
|
||
"name": "@navsea/maplibre-particle-rn",
|
||
"version": android_version,
|
||
"artifact": tgz,
|
||
"mapLibreReactNative": json.loads((ROOT / "packages/maplibre-particle-rn/package.json").read_text())["peerDependencies"]["@maplibre/maplibre-react-native"],
|
||
},
|
||
"android": {
|
||
"version": android_version,
|
||
"coordinate": (
|
||
"cc.navsea.maplibre:android-sdk-particle-opengl:"
|
||
+ android_version
|
||
),
|
||
"renderer": "opengl",
|
||
"artifact": aar,
|
||
"ndk": os.environ.get("PARTICLE_NDK_VERSION"),
|
||
"gradle": os.environ.get("PARTICLE_GRADLE_VERSION"),
|
||
"jdk": os.environ.get("PARTICLE_JDK_VERSION"),
|
||
},
|
||
"ios": {
|
||
"distributionVersion": ios_version,
|
||
"renderer": "metal",
|
||
"compilationMode": "opt",
|
||
"moduleName": "MapLibre",
|
||
"artifact": ios,
|
||
"swiftPackage": {
|
||
"url": f"{PUBLIC}/swift/maplibre-particle-spm.git",
|
||
"requirement": "exactVersion",
|
||
"version": ios_version,
|
||
"productName": "MapLibre",
|
||
},
|
||
"xcode": os.environ.get("PARTICLE_XCODE_VERSION"),
|
||
"bazel": os.environ.get("PARTICLE_BAZEL_VERSION"),
|
||
},
|
||
}
|
||
|
||
(ROOT / "release/maplibre-particle/release-manifest.json").write_text(
|
||
json.dumps(manifest, ensure_ascii=False, indent=2) + "\n"
|
||
)
|
||
|
||
ios_manifest = {
|
||
"schemaVersion": 2,
|
||
"status": "PUBLISHED_PUBLIC_READBACK_PASS",
|
||
"distributionVersion": ios_version,
|
||
"moduleName": "MapLibre",
|
||
"compilationMode": "opt",
|
||
"artifact": ios,
|
||
"sourceCommit": source_commit,
|
||
"swiftPackage": manifest["ios"]["swiftPackage"],
|
||
"notes": (
|
||
"Metal renderer optimized release built with "
|
||
"bazel build -c opt --//:renderer=metal //platform/ios:MapLibre.dynamic"
|
||
),
|
||
}
|
||
(ROOT / "release/maplibre-particle/ios/release-manifest.json").write_text(
|
||
json.dumps(ios_manifest, ensure_ascii=False, indent=2) + "\n"
|
||
)
|
||
|
||
package_template = f"""// swift-tools-version: 5.7
|
||
import PackageDescription
|
||
|
||
let package = Package(
|
||
name: "MapLibreDistribution",
|
||
products: [
|
||
.library(name: "MapLibre", targets: ["MapLibre"]),
|
||
],
|
||
targets: [
|
||
.binaryTarget(
|
||
name: "MapLibre",
|
||
url: "{ios['url']}",
|
||
checksum: "{ios['sha256']}"
|
||
),
|
||
]
|
||
)
|
||
"""
|
||
(ROOT / "release/maplibre-particle/ios/Package.swift.template").write_text(
|
||
package_template
|
||
)
|
||
|
||
release_readme = f"""# MapLibre Particle iOS 发行
|
||
|
||
当前正式发行:{ios_version}
|
||
|
||
- Renderer:Metal
|
||
- Product / Module:MapLibre
|
||
- Binary:{ios['url']}
|
||
- SHA-256:{ios['sha256']}
|
||
- SwiftPM:{PUBLIC}/swift/maplibre-particle-spm.git
|
||
- Exact Version:{ios_version}
|
||
- Source Commit:{source_commit}
|
||
|
||
构建命令固定为:
|
||
|
||
bazel build -c opt --//:renderer=metal //platform/ios:MapLibre.dynamic
|
||
|
||
不得用默认 OpenGL XCFramework 覆盖同版本。新版本必须使用新的 Particle revision。
|
||
"""
|
||
(ROOT / "release/maplibre-particle/ios/README.md").write_text(
|
||
release_readme
|
||
)
|
||
|
||
print(json.dumps(manifest, ensure_ascii=False, indent=2))
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|