Skip to content

Commit a0db218

Browse files
authored
Update CocoaPods package release script. (#20608)
- Update method for uploading to Azure storage to use managed identity. - Allow helper script tasks to be split across different calls. - Rewrite helper script in Python. Motivation: Recently the Azure storage account configuration was changed and now the old way of uploading to it no longer works.
1 parent 274d162 commit a0db218

File tree

3 files changed

+108
-45
lines changed

3 files changed

+108
-45
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env python3
2+
3+
# Note: This script is intended to be called from the CocoaPods package release pipeline or a similar context.
4+
5+
from __future__ import annotations
6+
7+
import argparse
8+
import os
9+
import shlex
10+
import subprocess
11+
from enum import Enum
12+
from pathlib import Path
13+
14+
15+
class Task(Enum):
16+
upload_pod_archive = 1
17+
update_podspec = 2
18+
19+
20+
def _run(command: list[str], **kwargs):
21+
print(f"Running command: {shlex.join(command)}", flush=True)
22+
kwargs.setdefault("check", True)
23+
return subprocess.run(command, **kwargs) # noqa: PLW1510 # we add 'check' to kwargs if not present
24+
25+
26+
def upload_pod_archive(pod_archive_path: Path):
27+
env = os.environ.copy()
28+
env.update(
29+
{
30+
# configure azcopy to use managed identity
31+
"AZCOPY_AUTO_LOGIN_TYPE": "MSI",
32+
"AZCOPY_MSI_CLIENT_ID": "63b63039-6328-442f-954b-5a64d124e5b4",
33+
}
34+
)
35+
36+
storage_account_name = "onnxruntimepackages"
37+
storage_account_container_name = "$web"
38+
dest_url = f"https://{storage_account_name}.blob.core.windows.net/{storage_account_container_name}/"
39+
40+
upload_command = ["azcopy", "cp", str(pod_archive_path), dest_url]
41+
42+
_run(upload_command, env=env)
43+
44+
45+
def update_podspec(pod_archive_path: Path, podspec_path: Path):
46+
storage_url = f"https://download.onnxruntime.ai/{pod_archive_path.name}"
47+
48+
podspec_content = podspec_path.read_text()
49+
podspec_content = podspec_content.replace("file:///http_source_placeholder", storage_url)
50+
podspec_path.write_text(podspec_content)
51+
52+
53+
def _parse_args():
54+
parser = argparse.ArgumentParser(
55+
description="Helper script to perform release tasks. "
56+
"Mostly useful for the CocoaPods package release pipeline.",
57+
)
58+
59+
parser.add_argument(
60+
"--pod-archive-path",
61+
type=Path,
62+
help="Pod archive path.",
63+
)
64+
65+
parser.add_argument(
66+
"--podspec-path",
67+
type=Path,
68+
help="Podspec path.",
69+
)
70+
71+
parser.add_argument(
72+
"task",
73+
choices=[task.name for task in Task],
74+
help="Specify the task to run.",
75+
)
76+
77+
return parser.parse_args()
78+
79+
80+
def _validate_args(
81+
args: argparse.Namespace, require_pod_archive_path: bool = False, require_podspec_path: bool = False
82+
):
83+
if require_pod_archive_path:
84+
assert args.pod_archive_path is not None, "--pod-archive-path must be specified."
85+
args.pod_archive_path = args.pod_archive_path.resolve(strict=True)
86+
87+
if require_podspec_path:
88+
assert args.podspec_path is not None, "--podspec-path must be specified."
89+
args.podspec_path = args.podspec_path.resolve(strict=True)
90+
91+
92+
def main():
93+
args = _parse_args()
94+
95+
task = Task[args.task]
96+
97+
if task == Task.update_podspec:
98+
_validate_args(args, require_pod_archive_path=True, require_podspec_path=True)
99+
update_podspec(args.pod_archive_path, args.podspec_path)
100+
101+
elif task == Task.upload_pod_archive:
102+
_validate_args(args, require_pod_archive_path=True)
103+
upload_pod_archive(args.pod_archive_path)
104+
105+
106+
if __name__ == "__main__":
107+
main()

tools/ci_build/github/apple/upload_pod_archive_and_update_podspec.sh

Lines changed: 0 additions & 44 deletions
This file was deleted.

tools/ci_build/github/azure-pipelines/templates/stages/mac-ios-packaging-build-stage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ stages:
142142
done
143143
144144
# copy over helper script for use in release pipeline
145-
cp tools/ci_build/github/apple/upload_pod_archive_and_update_podspec.sh "$(Build.ArtifactStagingDirectory)"
145+
cp tools/ci_build/github/apple/package_release_tasks.py "$(Build.ArtifactStagingDirectory)"
146146
displayName: "Assemble artifacts"
147147
148148
- script: |

0 commit comments

Comments
 (0)