From 937a7daf1ffbec28e06ecda9be28b17d776fc442 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 21 Mar 2020 15:14:46 -0400 Subject: Move wheel builer to github actions (#5147) --- release.py | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 4 deletions(-) (limited to 'release.py') diff --git a/release.py b/release.py index c03d22d5..a2219e6e 100644 --- a/release.py +++ b/release.py @@ -6,6 +6,7 @@ from __future__ import absolute_import, division, print_function import getpass import glob +import io import json import os import subprocess @@ -20,6 +21,8 @@ import click from msrest.authentication import BasicAuthentication +import requests + def run(*args, **kwargs): print("[running] {0}".format(list(args))) @@ -61,8 +64,7 @@ def download_artifacts_azure(build_client, build_id): return paths -def build_wheels_azure(version): - token = getpass.getpass("Azure personal access token: ") +def build_wheels_azure(token, version): credentials = BasicAuthentication("", token) connection = Connection( base_url="https://dev.azure.com/pyca", creds=credentials @@ -82,12 +84,96 @@ def build_wheels_azure(version): return download_artifacts_azure(build_client, build.id) +def wait_for_build_complete_github_actions(session, token, run_url): + while True: + response = session.get(run_url, headers={ + "Content-Type": "application/json", + "Authorization": "token {}".format(token), + }) + response.raise_for_status() + if response.json()["conclusion"] is not None: + break + time.sleep(3) + + +def download_artifacts_github_actions(session, token, run_url): + response = session.get(run_url, headers={ + "Content-Type": "application/json", + "Authorization": "token {}".format(token), + }) + response.raise_for_status() + + response = session.get(response.json()["artifacts_url"], headers={ + "Content-Type": "application/json", + "Authorization": "token {}".format(token), + }) + response.raise_for_status() + paths = [] + for artifact in response.json()["artifacts"]: + response = session.get(artifact["archive_download_url"], headers={ + "Content-Type": "application/json", + "Authorization": "token {}".format(token), + }) + with zipfile.ZipFile(io.BytesIO(response.content)) 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_github_actions_wheels(token, version): + session = requests.Session() + + response = session.post( + "https://api.github.com/repos/pyca/cryptography/dispatches", + headers={ + "Content-Type": "application/json", + "Accept": "application/vnd.github.everest-preview+json", + "Authorization": "token {}".format(token), + }, + data=json.dumps({ + "event_type": "wheel-builder", + "client_payload": { + "BUILD_VERSION": version, + }, + }), + ) + response.raise_for_status() + + response = session.get( + ( + "https://api.github.com/repos/pyca/cryptography/actions/workflows/" + "wheel-builder.yml/runs?event=repository_dispatch" + ), + headers={ + "Content-Type": "application/json", + "Authorization": "token {}".format(token), + }, + ) + response.raise_for_status() + run_url = response.json()["workflow_runs"][0]["url"] + wait_for_build_complete_github_actions(session, token, run_url) + return download_artifacts_github_actions(session, token, run_url) + + @click.command() @click.argument("version") def release(version): """ ``version`` should be a string like '0.4' or '1.0'. """ + azure_token = getpass.getpass("Azure personal access token: ") + github_token = getpass.getpass("Github person access token: ") + run("git", "tag", "-s", version, "-m", "{0} release".format(version)) run("git", "push", "--tags") @@ -100,8 +186,11 @@ def release(version): ) run("twine", "upload", "-s", *packages) - azure_wheel_paths = build_wheels_azure(version) - run("twine", "upload", *azure_wheel_paths) + azure_wheel_paths = build_wheels_azure(azure_token, version) + github_actions_wheel_paths = build_github_actions_wheels( + github_token, version + ) + run("twine", "upload", *(azure_wheel_paths, github_actions_wheel_paths)) if __name__ == "__main__": -- cgit v1.2.3