aboutsummaryrefslogtreecommitdiffstats
path: root/release.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2019-05-25 11:11:49 -0400
committerPaul Kehrer <paul.l.kehrer@gmail.com>2019-05-25 11:11:49 -0400
commit37b9ac0c8acf769335cbff49540a13fdaeb2b9bf (patch)
treefc451f5d7e104b59a49b2e89fe03002c84bd26a5 /release.py
parent551abfadc9e9375daf4354c76020595ad9b34c41 (diff)
downloadcryptography-37b9ac0c8acf769335cbff49540a13fdaeb2b9bf.tar.gz
cryptography-37b9ac0c8acf769335cbff49540a13fdaeb2b9bf.tar.bz2
cryptography-37b9ac0c8acf769335cbff49540a13fdaeb2b9bf.zip
Update release.py to use azure for wheel building (#4878)
* Initial stab at this script * Convert to the old style artifact publish * Update script based on some testing * Remove this * Adapt release.py to combine azure and jenkins wheels
Diffstat (limited to 'release.py')
-rw-r--r--release.py109
1 files changed, 84 insertions, 25 deletions
diff --git a/release.py b/release.py
index d7c18d10..b8269114 100644
--- a/release.py
+++ b/release.py
@@ -7,13 +7,19 @@ from __future__ import absolute_import, division, print_function
import getpass
import glob
import io
+import json
import os
import subprocess
+import tempfile
import time
+import zipfile
+
+from azure.devops.connection import Connection
+from azure.devops.v5_1.build.models import Build
import click
-from clint.textui.progress import Bar as ProgressBar
+from msrest.authentication import BasicAuthentication
import requests
@@ -29,7 +35,63 @@ def run(*args, **kwargs):
subprocess.check_call(list(args), **kwargs)
-def wait_for_build_completed(session):
+def wait_for_build_completed_azure(build_client, build_id):
+ while True:
+ build = build_client.get_build("cryptography", build_id)
+ if build.finish_time is not None:
+ break
+ time.sleep(3)
+
+
+def download_artifacts_azure(build_client, build_id):
+ artifacts = build_client.get_artifacts("cryptography", build_id)
+ paths = []
+ for artifact in artifacts:
+ contents = build_client.get_artifact_content_zip(
+ "cryptography", build_id, artifact.name
+ )
+ with tempfile.NamedTemporaryFile() as f:
+ for chunk in contents:
+ f.write(chunk)
+ f.flush()
+ with zipfile.ZipFile(f.name) as z:
+ for name in z.namelist():
+ if not name.endswith(".whl"):
+ continue
+ p = z.open(name)
+ out_path = os.path.join(
+ os.path.dirname(__file__),
+ "dist",
+ os.path.basename(name),
+ )
+ with open(out_path, "wb") as f:
+ f.write(p.read())
+ paths.append(out_path)
+ return paths
+
+
+def build_wheels_azure(version):
+ token = getpass.getpass("Azure personal access token: ")
+ credentials = BasicAuthentication("", token)
+ connection = Connection(
+ base_url="https://dev.azure.com/pyca", creds=credentials
+ )
+ build_client = connection.clients.get_build_client()
+ [definition] = build_client.get_definitions(
+ "cryptography", "wheel builder"
+ )
+ build_description = Build(
+ definition=definition,
+ parameters=json.dumps({"BUILD_VERSION": version}),
+ )
+ build = build_client.queue_build(
+ project="cryptography", build=build_description
+ )
+ wait_for_build_completed_azure(build_client, build.id)
+ return download_artifacts_azure(build_client, build.id)
+
+
+def wait_for_build_completed_jenkins(session):
# Wait 20 seconds before actually checking if the build is complete, to
# ensure that it had time to really start.
time.sleep(20)
@@ -47,7 +109,7 @@ def wait_for_build_completed(session):
time.sleep(0.1)
-def download_artifacts(session):
+def download_artifacts_jenkins(session):
response = session.get(
"{0}/lastBuild/api/json/".format(JENKINS_URL),
headers={
@@ -69,16 +131,9 @@ def download_artifacts(session):
)
assert response.headers["content-length"]
print("Downloading {0}".format(artifact["fileName"]))
- bar = ProgressBar(
- expected_size=int(response.headers["content-length"]),
- filled_char="="
- )
content = io.BytesIO()
for data in response.iter_content(chunk_size=8192):
content.write(data)
- bar.show(content.tell())
- assert bar.expected_size == content.tell()
- bar.done()
out_path = os.path.join(
os.path.dirname(__file__),
"dist",
@@ -90,6 +145,22 @@ def download_artifacts(session):
return paths
+def build_wheels_jenkins(version):
+ token = getpass.getpass("Input the Jenkins token: ")
+ session = requests.Session()
+ response = session.get(
+ "{0}/buildWithParameters".format(JENKINS_URL),
+ params={
+ "token": token,
+ "BUILD_VERSION": version,
+ "cause": "Building wheels for {0}".format(version)
+ }
+ )
+ response.raise_for_status()
+ wait_for_build_completed_jenkins(session)
+ return download_artifacts_jenkins(session)
+
+
@click.command()
@click.argument("version")
def release(version):
@@ -108,21 +179,9 @@ def release(version):
)
run("twine", "upload", "-s", *packages)
- session = requests.Session()
-
- token = getpass.getpass("Input the Jenkins token: ")
- response = session.get(
- "{0}/buildWithParameters".format(JENKINS_URL),
- params={
- "token": token,
- "BUILD_VERSION": version,
- "cause": "Building wheels for {0}".format(version)
- }
- )
- response.raise_for_status()
- wait_for_build_completed(session)
- paths = download_artifacts(session)
- run("twine", "upload", *paths)
+ azure_wheel_paths = build_wheels_azure(version)
+ jenkins_wheel_paths = build_wheels_jenkins(version)
+ run("twine", "upload", *(azure_wheel_paths + jenkins_wheel_paths))
if __name__ == "__main__":