Alex Gaynor | 5951f46 | 2014-11-16 09:08:42 -0800 | [diff] [blame] | 1 | # 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 Chia | a0a47cd | 2014-07-06 17:51:26 +0800 | [diff] [blame] | 4 | |
Alex Gaynor | 0e10f57 | 2014-01-06 13:17:31 -0800 | [diff] [blame] | 5 | from __future__ import absolute_import, division, print_function |
| 6 | |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 7 | import getpass |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 8 | import os |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 9 | import time |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 10 | |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 11 | import invoke |
| 12 | |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 13 | import requests |
| 14 | |
| 15 | |
Paul Kehrer | 47e5df9 | 2014-03-15 08:24:45 -0400 | [diff] [blame] | 16 | JENKINS_URL = "https://jenkins.cryptography.io/job/cryptography-wheel-builder" |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 17 | |
| 18 | |
Alex Gaynor | 9ca7f03 | 2014-09-26 23:30:31 -0400 | [diff] [blame] | 19 | def wait_for_build_completed(session): |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 20 | while True: |
Alex Gaynor | 9ca7f03 | 2014-09-26 23:30:31 -0400 | [diff] [blame] | 21 | response = session.get( |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 22 | "{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 Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 29 | assert response.json()["result"] == "SUCCESS" |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 30 | break |
| 31 | time.sleep(0.1) |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 32 | |
Alex Gaynor | c9e4c6a | 2014-02-19 14:29:37 -0800 | [diff] [blame] | 33 | |
Alex Gaynor | 9ca7f03 | 2014-09-26 23:30:31 -0400 | [diff] [blame] | 34 | def download_artifacts(session): |
| 35 | response = session.get( |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 36 | "{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 Gaynor | 6ab3f46 | 2014-02-20 09:07:53 -0800 | [diff] [blame] | 44 | |
| 45 | paths = [] |
| 46 | |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 47 | for run in response.json()["runs"]: |
Alex Gaynor | 9ca7f03 | 2014-09-26 23:30:31 -0400 | [diff] [blame] | 48 | response = session.get( |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 49 | 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 Gaynor | 9ca7f03 | 2014-09-26 23:30:31 -0400 | [diff] [blame] | 56 | response = session.get( |
Paul Kehrer | 58f1101 | 2014-05-03 20:48:03 -0500 | [diff] [blame] | 57 | "{0}artifact/{1}".format(run["url"], artifact["relativePath"]) |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 58 | ) |
| 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 Gaynor | 6ab3f46 | 2014-02-20 09:07:53 -0800 | [diff] [blame] | 66 | paths.append(out_path) |
| 67 | return paths |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 68 | |
| 69 | |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 70 | @invoke.task |
| 71 | def release(version): |
| 72 | """ |
| 73 | ``version`` should be a string like '0.4' or '1.0'. |
| 74 | """ |
Paul Kehrer | dd32e95 | 2014-07-09 21:14:24 -0500 | [diff] [blame] | 75 | invoke.run("git tag -s {0} -m '{0} release'".format(version)) |
Alex Gaynor | 6b1235a | 2014-01-06 15:28:59 -0800 | [diff] [blame] | 76 | invoke.run("git push --tags") |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 77 | |
Alex Gaynor | fea893c | 2014-01-07 11:06:51 -0800 | [diff] [blame] | 78 | invoke.run("python setup.py sdist") |
Alex Stapleton | 3888a84 | 2014-03-24 23:05:53 +0000 | [diff] [blame] | 79 | invoke.run("cd vectors/ && python setup.py sdist bdist_wheel") |
Alex Stapleton | a39a319 | 2014-03-14 20:03:12 +0000 | [diff] [blame] | 80 | |
| 81 | invoke.run( |
| 82 | "twine upload -s dist/cryptography-{0}* " |
Alex Stapleton | 3888a84 | 2014-03-24 23:05:53 +0000 | [diff] [blame] | 83 | "vectors/dist/cryptography_vectors-{0}*".format(version) |
Alex Stapleton | a39a319 | 2014-03-14 20:03:12 +0000 | [diff] [blame] | 84 | ) |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 85 | |
Alex Gaynor | 9ca7f03 | 2014-09-26 23:30:31 -0400 | [diff] [blame] | 86 | session = requests.Session() |
| 87 | |
Alex Gaynor | b44158e | 2014-09-28 12:00:49 -0400 | [diff] [blame] | 88 | # 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 Gaynor | 0f74a2c | 2014-09-26 23:31:19 -0400 | [diff] [blame] | 91 | response = session.request( |
| 92 | "PURGE", "https://pypi.python.org/simple/cryptography/" |
| 93 | ) |
Alex Gaynor | 9ca7f03 | 2014-09-26 23:30:31 -0400 | [diff] [blame] | 94 | response.raise_for_status() |
| 95 | |
Paul Kehrer | d1d6f0f | 2014-06-20 14:32:02 -0600 | [diff] [blame] | 96 | username = getpass.getpass("Input the GitHub/Jenkins username: ") |
Alex Gaynor | 6629fa5 | 2014-02-20 16:10:53 -0800 | [diff] [blame] | 97 | token = getpass.getpass("Input the Jenkins token: ") |
Alex Gaynor | 9ca7f03 | 2014-09-26 23:30:31 -0400 | [diff] [blame] | 98 | response = session.post( |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 99 | "{0}/build".format(JENKINS_URL), |
Paul Kehrer | d1d6f0f | 2014-06-20 14:32:02 -0600 | [diff] [blame] | 100 | auth=requests.auth.HTTPBasicAuth( |
| 101 | username, token |
| 102 | ), |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 103 | params={ |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 104 | "cause": "Building wheels for {0}".format(version) |
| 105 | } |
| 106 | ) |
Alex Gaynor | c9e4c6a | 2014-02-19 14:29:37 -0800 | [diff] [blame] | 107 | response.raise_for_status() |
Alex Gaynor | 9ca7f03 | 2014-09-26 23:30:31 -0400 | [diff] [blame] | 108 | wait_for_build_completed(session) |
| 109 | paths = download_artifacts(session) |
Alex Gaynor | 6ab3f46 | 2014-02-20 09:07:53 -0800 | [diff] [blame] | 110 | invoke.run("twine upload {0}".format(" ".join(paths))) |