mitmproxy/release/deploy.py
Maximilian Hils 518fb94124
Harden CI Pipeline (#4590)
* ci: use actions/checkout@v2

* ci: always specify python version

* ci: pin external actions

* ci: split docs job, pin immediate dependencies

* ci: correct hugo sha256sum

* ci: full repo fetch depth for tests

* ci: use pip-tools to pin all the things

* ci: minor fixes

* ci: fixup

* ci: streamline pinned install

* ci: minor fixes

* ci: fix py3.8 pins

* ci: don't persist checkout credentials

* ci: always run local linter

* ci: test docs deployment from actions-hardening branch

* ci: fix docs job

* ci: pass in credentials

* ci: fix file permissions

* ci: try harder to fix docs deploy

* ci: fix docker artifact name

* Revert "ci: test docs deployment from actions-hardening branch"

This reverts commit 30cfb7a814b61a8926fc0623e3e70b6dd5106d90.

* unpin PyPI dependencies

* ci: install tox first

* ci: fixups

* ci: fixups

* ci: fixups

* ci: fixups
2021-05-11 11:17:09 +02:00

56 lines
1.5 KiB
Python
Executable File

#!/usr/bin/env python3
import os
import subprocess
from pathlib import Path
from typing import Optional
if __name__ == "__main__":
ref = os.environ["GITHUB_REF"]
branch: Optional[str] = None
tag: Optional[str] = None
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:
upload_dir = tag
else:
upload_dir = f"branches/{branch}"
subprocess.check_call([
"aws", "s3", "cp",
"--acl", "public-read",
f"./release/dist/",
f"s3://snapshots.mitmproxy.org/{upload_dir}/",
"--recursive",
])
# Upload releases to PyPI
if tag:
whl, = Path("release/dist/").glob('mitmproxy-*-py3-none-any.whl')
subprocess.check_call(["twine", "upload", whl])
# Upload dev docs
if branch == "main" or branch == "actions-hardening": # FIXME remove
subprocess.check_call([
"aws", "configure",
"set", "preview.cloudfront", "true"
])
subprocess.check_call([
"aws", "s3",
"sync",
"--delete",
"--acl", "public-read",
"docs/public",
"s3://docs.mitmproxy.org/dev"
])
subprocess.check_call([
"aws", "cloudfront",
"create-invalidation",
"--distribution-id", "E1TH3USJHFQZ5Q",
"--paths", "/dev/*"
])