2021-05-11 09:17:09 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
from pathlib import Path
|
2022-04-26 11:53:35 +00:00
|
|
|
|
2021-07-19 09:38:20 +00:00
|
|
|
# Security: No third-party dependencies here!
|
2021-05-11 09:17:09 +00:00
|
|
|
|
2022-07-23 09:34:56 +00:00
|
|
|
root = Path(__file__).absolute().parent.parent
|
|
|
|
|
2021-05-11 09:17:09 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
ref = os.environ["GITHUB_REF"]
|
2023-02-27 07:28:30 +00:00
|
|
|
branch: str | None = None
|
|
|
|
tag: str | None = None
|
2021-05-11 09:17:09 +00:00
|
|
|
if ref.startswith("refs/heads/"):
|
|
|
|
branch = ref.replace("refs/heads/", "")
|
|
|
|
elif ref.startswith("refs/tags/"):
|
|
|
|
tag = ref.replace("refs/tags/", "")
|
|
|
|
else:
|
|
|
|
raise AssertionError
|
|
|
|
|
|
|
|
# Upload binaries (be it release or snapshot)
|
|
|
|
if tag:
|
2022-07-23 09:34:56 +00:00
|
|
|
upload_dir = tag
|
2021-05-11 09:17:09 +00:00
|
|
|
else:
|
|
|
|
upload_dir = f"branches/{branch}"
|
2022-07-23 09:34:56 +00:00
|
|
|
print(f"Uploading binaries to snapshots.mitmproxy.org/{upload_dir}...")
|
2022-04-26 11:53:35 +00:00
|
|
|
subprocess.check_call(
|
|
|
|
[
|
|
|
|
"aws",
|
|
|
|
"s3",
|
2022-10-24 15:06:40 +00:00
|
|
|
"sync",
|
|
|
|
"--delete",
|
2022-04-26 11:53:35 +00:00
|
|
|
"--acl",
|
|
|
|
"public-read",
|
2022-07-29 11:42:42 +00:00
|
|
|
"--exclude",
|
|
|
|
"*.msix",
|
2022-07-23 09:34:56 +00:00
|
|
|
root / "release/dist",
|
2022-10-24 15:06:40 +00:00
|
|
|
f"s3://snapshots.mitmproxy.org/{upload_dir}",
|
2022-04-26 11:53:35 +00:00
|
|
|
]
|
|
|
|
)
|
2021-05-11 09:17:09 +00:00
|
|
|
|
|
|
|
# Upload releases to PyPI
|
|
|
|
if tag:
|
2022-07-23 09:34:56 +00:00
|
|
|
print(f"Uploading wheel to PyPI...")
|
|
|
|
(whl,) = root.glob("release/dist/mitmproxy-*-py3-none-any.whl")
|
2021-05-11 09:17:09 +00:00
|
|
|
subprocess.check_call(["twine", "upload", whl])
|
|
|
|
|
2022-10-24 15:06:40 +00:00
|
|
|
# Upload docs
|
|
|
|
def upload_docs(path: str, src: Path = root / "docs/public"):
|
2022-04-26 11:53:35 +00:00
|
|
|
subprocess.check_call(["aws", "configure", "set", "preview.cloudfront", "true"])
|
|
|
|
subprocess.check_call(
|
|
|
|
[
|
|
|
|
"aws",
|
|
|
|
"s3",
|
|
|
|
"sync",
|
|
|
|
"--delete",
|
|
|
|
"--acl",
|
|
|
|
"public-read",
|
2022-10-24 15:06:40 +00:00
|
|
|
src,
|
|
|
|
f"s3://docs.mitmproxy.org{path}",
|
2022-04-26 11:53:35 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
subprocess.check_call(
|
|
|
|
[
|
|
|
|
"aws",
|
|
|
|
"cloudfront",
|
|
|
|
"create-invalidation",
|
|
|
|
"--distribution-id",
|
|
|
|
"E1TH3USJHFQZ5Q",
|
|
|
|
"--paths",
|
2022-10-24 15:06:40 +00:00
|
|
|
f"{path}/*",
|
2022-04-26 11:53:35 +00:00
|
|
|
]
|
|
|
|
)
|
2022-10-24 15:06:40 +00:00
|
|
|
|
|
|
|
if branch == "main":
|
|
|
|
print(f"Uploading dev docs...")
|
|
|
|
upload_docs("/dev")
|
|
|
|
if tag:
|
|
|
|
print(f"Uploading release docs...")
|
|
|
|
upload_docs("/stable")
|
|
|
|
upload_docs(f"/archive/v{tag.split('.')[0]}", src=root / "docs/archive")
|