89 lines
2.7 KiB
Python
Executable File
89 lines
2.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
||
from __future__ import annotations
|
||
|
||
import subprocess
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
PUBLIC_ROOT = "https://pbf.jpcn.ccwu.cc/swift/maplibre-particle"
|
||
GIT_REMOTE = "nas:/volume1/work/pbf/swift/maplibre-particle-spm.git"
|
||
WORK = Path.home() / "dev/MapLibreParticleDistribution"
|
||
|
||
|
||
def run(*args: str, cwd: Path | None = None) -> str:
|
||
result = subprocess.run(
|
||
args,
|
||
cwd=cwd,
|
||
check=True,
|
||
text=True,
|
||
stdout=subprocess.PIPE,
|
||
stderr=subprocess.STDOUT,
|
||
)
|
||
return result.stdout
|
||
|
||
|
||
def main() -> None:
|
||
if len(sys.argv) != 3:
|
||
raise SystemExit("usage: publish_swiftpm.py <ios-version> <zip-sha256>")
|
||
version, checksum = sys.argv[1], sys.argv[2]
|
||
if not WORK.exists():
|
||
run("git", "clone", GIT_REMOTE, str(WORK))
|
||
|
||
run("git", "fetch", "origin", cwd=WORK)
|
||
run("git", "checkout", "main", cwd=WORK)
|
||
run("git", "pull", "--ff-only", "origin", "main", cwd=WORK)
|
||
|
||
tag_check = subprocess.run(
|
||
["git", "ls-remote", "--tags", "origin", f"refs/tags/{version}"],
|
||
cwd=WORK,
|
||
text=True,
|
||
stdout=subprocess.PIPE,
|
||
check=True,
|
||
).stdout.strip()
|
||
if tag_check:
|
||
raise SystemExit(f"SwiftPM tag already exists: {version}")
|
||
|
||
url = f"{PUBLIC_ROOT}/{version}/MapLibre.dynamic.xcframework.zip"
|
||
package = f'''// swift-tools-version: 5.7
|
||
import PackageDescription
|
||
|
||
let package = Package(
|
||
name: "MapLibreDistribution",
|
||
products: [
|
||
.library(name: "MapLibre", targets: ["MapLibre"]),
|
||
],
|
||
targets: [
|
||
.binaryTarget(
|
||
name: "MapLibre",
|
||
url: "{url}",
|
||
checksum: "{checksum}"
|
||
),
|
||
]
|
||
)
|
||
'''
|
||
|
||
(WORK / "Package.swift").write_text(package)
|
||
(WORK / "README.md").write_text(
|
||
"# MapLibre Particle SwiftPM Distribution\n\n"
|
||
"该仓库只保存 NavSea MapLibre Particle iOS binary distribution 的 SwiftPM manifest。\n"
|
||
"产品和模块名固定为 MapLibre,供 MapLibre React Native 11.3.6 消费。\n\n"
|
||
f"当前版本:{version}。\n"
|
||
f"对应 binary:{url}\n"
|
||
)
|
||
run("git", "add", "Package.swift", "README.md", cwd=WORK)
|
||
run("git", "commit", "-m", f"release: MapLibre Particle iOS {version}", cwd=WORK)
|
||
run("git", "tag", "-a", version, "-m", f"MapLibre Particle iOS {version}", cwd=WORK)
|
||
run("git", "push", "origin", "main", cwd=WORK)
|
||
run("git", "push", "origin", version, cwd=WORK)
|
||
run(
|
||
"ssh", "nas",
|
||
"git --git-dir=/volume1/work/pbf/swift/maplibre-particle-spm.git "
|
||
"symbolic-ref HEAD refs/heads/main && "
|
||
"git --git-dir=/volume1/work/pbf/swift/maplibre-particle-spm.git update-server-info",
|
||
)
|
||
print(f"SWIFTPM_PUBLISHED={version}")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|