blob: 2dd005ba25947fb23b1102cbe21f413fc48d4077 [file] [log] [blame]
Alex Gaynor5951f462014-11-16 09:08:42 -08001# This file is dual licensed under the terms of the Apache License, Version
2# 2.0, and the BSD License. See the LICENSE file in the root of this repository
3# for complete details.
Terry Chiaa0a47cd2014-07-06 17:51:26 +08004
Alex Gaynor0e10f572014-01-06 13:17:31 -08005from __future__ import absolute_import, division, print_function
6
Alex Gaynor86201592014-02-19 14:01:06 -08007import getpass
Alex Gaynor7a2b3582014-02-20 07:48:46 -08008import os
Alex Gaynora1dff052014-02-19 16:44:06 -08009import time
Alex Gaynor86201592014-02-19 14:01:06 -080010
Alex Gaynor6bc3af72014-01-06 12:04:53 -080011import invoke
12
Alex Gaynor86201592014-02-19 14:01:06 -080013import requests
14
15
Paul Kehrer47e5df92014-03-15 08:24:45 -040016JENKINS_URL = "https://jenkins.cryptography.io/job/cryptography-wheel-builder"
Alex Gaynora1dff052014-02-19 16:44:06 -080017
18
Alex Gaynor9ca7f032014-09-26 23:30:31 -040019def wait_for_build_completed(session):
Alex Gaynora1dff052014-02-19 16:44:06 -080020 while True:
Alex Gaynor9ca7f032014-09-26 23:30:31 -040021 response = session.get(
Alex Gaynora1dff052014-02-19 16:44:06 -080022 "{0}/lastBuild/api/json/".format(JENKINS_URL),
23 headers={
24 "Accept": "application/json",
25 }
26 )
27 response.raise_for_status()
28 if not response.json()["building"]:
Alex Gaynor7a2b3582014-02-20 07:48:46 -080029 assert response.json()["result"] == "SUCCESS"
Alex Gaynora1dff052014-02-19 16:44:06 -080030 break
31 time.sleep(0.1)
Alex Gaynor6bc3af72014-01-06 12:04:53 -080032
Alex Gaynorc9e4c6a2014-02-19 14:29:37 -080033
Alex Gaynor9ca7f032014-09-26 23:30:31 -040034def download_artifacts(session):
35 response = session.get(
Alex Gaynor7a2b3582014-02-20 07:48:46 -080036 "{0}/lastBuild/api/json/".format(JENKINS_URL),
37 headers={
38 "Accept": "application/json"
39 }
40 )
41 response.raise_for_status()
42 assert not response.json()["building"]
43 assert response.json()["result"] == "SUCCESS"
Alex Gaynor6ab3f462014-02-20 09:07:53 -080044
45 paths = []
46
Alex Gaynor7a2b3582014-02-20 07:48:46 -080047 for run in response.json()["runs"]:
Alex Gaynor9ca7f032014-09-26 23:30:31 -040048 response = session.get(
Alex Gaynor7a2b3582014-02-20 07:48:46 -080049 run["url"] + "api/json/",
50 headers={
51 "Accept": "application/json",
52 }
53 )
54 response.raise_for_status()
55 for artifact in response.json()["artifacts"]:
Alex Gaynor9ca7f032014-09-26 23:30:31 -040056 response = session.get(
Paul Kehrer58f11012014-05-03 20:48:03 -050057 "{0}artifact/{1}".format(run["url"], artifact["relativePath"])
Alex Gaynor7a2b3582014-02-20 07:48:46 -080058 )
59 out_path = os.path.join(
60 os.path.dirname(__file__),
61 "dist",
62 artifact["fileName"],
63 )
64 with open(out_path, "wb") as f:
65 f.write(response.content)
Alex Gaynor6ab3f462014-02-20 09:07:53 -080066 paths.append(out_path)
67 return paths
Alex Gaynor7a2b3582014-02-20 07:48:46 -080068
69
Alex Gaynor6bc3af72014-01-06 12:04:53 -080070@invoke.task
71def release(version):
72 """
73 ``version`` should be a string like '0.4' or '1.0'.
74 """
Paul Kehrerdd32e952014-07-09 21:14:24 -050075 invoke.run("git tag -s {0} -m '{0} release'".format(version))
Alex Gaynor6b1235a2014-01-06 15:28:59 -080076 invoke.run("git push --tags")
Alex Gaynor6bc3af72014-01-06 12:04:53 -080077
Alex Gaynorfea893c2014-01-07 11:06:51 -080078 invoke.run("python setup.py sdist")
Alex Stapleton3888a842014-03-24 23:05:53 +000079 invoke.run("cd vectors/ && python setup.py sdist bdist_wheel")
Alex Stapletona39a3192014-03-14 20:03:12 +000080
81 invoke.run(
82 "twine upload -s dist/cryptography-{0}* "
Alex Stapleton3888a842014-03-24 23:05:53 +000083 "vectors/dist/cryptography_vectors-{0}*".format(version)
Alex Stapletona39a3192014-03-14 20:03:12 +000084 )
Alex Gaynor86201592014-02-19 14:01:06 -080085
Alex Gaynor9ca7f032014-09-26 23:30:31 -040086 session = requests.Session()
87
Alex Gaynorb44158e2014-09-28 12:00:49 -040088 # This tells the CDN to delete the cached response for the URL. We do this
89 # so that the Jenkins builders will see the new sdist immediately when they
90 # go to build the wheels.
Alex Gaynor0f74a2c2014-09-26 23:31:19 -040091 response = session.request(
92 "PURGE", "https://pypi.python.org/simple/cryptography/"
93 )
Alex Gaynor9ca7f032014-09-26 23:30:31 -040094 response.raise_for_status()
95
Paul Kehrerd1d6f0f2014-06-20 14:32:02 -060096 username = getpass.getpass("Input the GitHub/Jenkins username: ")
Alex Gaynor6629fa52014-02-20 16:10:53 -080097 token = getpass.getpass("Input the Jenkins token: ")
Alex Gaynor9ca7f032014-09-26 23:30:31 -040098 response = session.post(
Alex Gaynora1dff052014-02-19 16:44:06 -080099 "{0}/build".format(JENKINS_URL),
Paul Kehrerd1d6f0f2014-06-20 14:32:02 -0600100 auth=requests.auth.HTTPBasicAuth(
101 username, token
102 ),
Alex Gaynor86201592014-02-19 14:01:06 -0800103 params={
Alex Gaynor86201592014-02-19 14:01:06 -0800104 "cause": "Building wheels for {0}".format(version)
105 }
106 )
Alex Gaynorc9e4c6a2014-02-19 14:29:37 -0800107 response.raise_for_status()
Alex Gaynor9ca7f032014-09-26 23:30:31 -0400108 wait_for_build_completed(session)
109 paths = download_artifacts(session)
Alex Gaynor6ab3f462014-02-20 09:07:53 -0800110 invoke.run("twine upload {0}".format(" ".join(paths)))