Alex Gaynor | 0e10f57 | 2014-01-06 13:17:31 -0800 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | # you may not use this file except in compliance with the License. |
| 3 | # You may obtain a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 10 | # implied. |
| 11 | # See the License for the specific language governing permissions and |
| 12 | # limitations under the License. |
Terry Chia | a0a47cd | 2014-07-06 17:51:26 +0800 | [diff] [blame] | 13 | |
Alex Gaynor | 0e10f57 | 2014-01-06 13:17:31 -0800 | [diff] [blame] | 14 | from __future__ import absolute_import, division, print_function |
| 15 | |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 16 | import getpass |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 17 | import os |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 18 | import time |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 19 | |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 20 | import invoke |
| 21 | |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 22 | import requests |
| 23 | |
| 24 | |
Paul Kehrer | 47e5df9 | 2014-03-15 08:24:45 -0400 | [diff] [blame] | 25 | JENKINS_URL = "https://jenkins.cryptography.io/job/cryptography-wheel-builder" |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 26 | |
| 27 | |
| 28 | def wait_for_build_completed(): |
| 29 | while True: |
| 30 | response = requests.get( |
| 31 | "{0}/lastBuild/api/json/".format(JENKINS_URL), |
| 32 | headers={ |
| 33 | "Accept": "application/json", |
| 34 | } |
| 35 | ) |
| 36 | response.raise_for_status() |
| 37 | if not response.json()["building"]: |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 38 | assert response.json()["result"] == "SUCCESS" |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 39 | break |
| 40 | time.sleep(0.1) |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 41 | |
Alex Gaynor | c9e4c6a | 2014-02-19 14:29:37 -0800 | [diff] [blame] | 42 | |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 43 | def download_artifacts(): |
| 44 | response = requests.get( |
| 45 | "{0}/lastBuild/api/json/".format(JENKINS_URL), |
| 46 | headers={ |
| 47 | "Accept": "application/json" |
| 48 | } |
| 49 | ) |
| 50 | response.raise_for_status() |
| 51 | assert not response.json()["building"] |
| 52 | assert response.json()["result"] == "SUCCESS" |
Alex Gaynor | 6ab3f46 | 2014-02-20 09:07:53 -0800 | [diff] [blame] | 53 | |
| 54 | paths = [] |
| 55 | |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 56 | for run in response.json()["runs"]: |
| 57 | response = requests.get( |
| 58 | run["url"] + "api/json/", |
| 59 | headers={ |
| 60 | "Accept": "application/json", |
| 61 | } |
| 62 | ) |
| 63 | response.raise_for_status() |
| 64 | for artifact in response.json()["artifacts"]: |
| 65 | response = requests.get( |
Paul Kehrer | 58f1101 | 2014-05-03 20:48:03 -0500 | [diff] [blame] | 66 | "{0}artifact/{1}".format(run["url"], artifact["relativePath"]) |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 67 | ) |
| 68 | out_path = os.path.join( |
| 69 | os.path.dirname(__file__), |
| 70 | "dist", |
| 71 | artifact["fileName"], |
| 72 | ) |
| 73 | with open(out_path, "wb") as f: |
| 74 | f.write(response.content) |
Alex Gaynor | 6ab3f46 | 2014-02-20 09:07:53 -0800 | [diff] [blame] | 75 | paths.append(out_path) |
| 76 | return paths |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 77 | |
| 78 | |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 79 | @invoke.task |
| 80 | def release(version): |
| 81 | """ |
| 82 | ``version`` should be a string like '0.4' or '1.0'. |
| 83 | """ |
Paul Kehrer | dd32e95 | 2014-07-09 21:14:24 -0500 | [diff] [blame^] | 84 | invoke.run("git tag -s {0} -m '{0} release'".format(version)) |
Alex Gaynor | 6b1235a | 2014-01-06 15:28:59 -0800 | [diff] [blame] | 85 | invoke.run("git push --tags") |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 86 | |
Alex Gaynor | fea893c | 2014-01-07 11:06:51 -0800 | [diff] [blame] | 87 | invoke.run("python setup.py sdist") |
Alex Stapleton | 3888a84 | 2014-03-24 23:05:53 +0000 | [diff] [blame] | 88 | invoke.run("cd vectors/ && python setup.py sdist bdist_wheel") |
Alex Stapleton | a39a319 | 2014-03-14 20:03:12 +0000 | [diff] [blame] | 89 | |
| 90 | invoke.run( |
| 91 | "twine upload -s dist/cryptography-{0}* " |
Alex Stapleton | 3888a84 | 2014-03-24 23:05:53 +0000 | [diff] [blame] | 92 | "vectors/dist/cryptography_vectors-{0}*".format(version) |
Alex Stapleton | a39a319 | 2014-03-14 20:03:12 +0000 | [diff] [blame] | 93 | ) |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 94 | |
Paul Kehrer | d1d6f0f | 2014-06-20 14:32:02 -0600 | [diff] [blame] | 95 | username = getpass.getpass("Input the GitHub/Jenkins username: ") |
Alex Gaynor | 6629fa5 | 2014-02-20 16:10:53 -0800 | [diff] [blame] | 96 | token = getpass.getpass("Input the Jenkins token: ") |
Alex Gaynor | c9e4c6a | 2014-02-19 14:29:37 -0800 | [diff] [blame] | 97 | response = requests.post( |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 98 | "{0}/build".format(JENKINS_URL), |
Paul Kehrer | d1d6f0f | 2014-06-20 14:32:02 -0600 | [diff] [blame] | 99 | auth=requests.auth.HTTPBasicAuth( |
| 100 | username, token |
| 101 | ), |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 102 | params={ |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 103 | "cause": "Building wheels for {0}".format(version) |
| 104 | } |
| 105 | ) |
Alex Gaynor | c9e4c6a | 2014-02-19 14:29:37 -0800 | [diff] [blame] | 106 | response.raise_for_status() |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 107 | wait_for_build_completed() |
Alex Gaynor | 6ab3f46 | 2014-02-20 09:07:53 -0800 | [diff] [blame] | 108 | paths = download_artifacts() |
| 109 | invoke.run("twine upload {0}".format(" ".join(paths))) |