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. |
| 13 | from __future__ import absolute_import, division, print_function |
| 14 | |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 15 | import getpass |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 16 | import os |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 17 | import time |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 18 | |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 19 | import invoke |
| 20 | |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 21 | import requests |
| 22 | |
| 23 | |
Paul Kehrer | 47e5df9 | 2014-03-15 08:24:45 -0400 | [diff] [blame] | 24 | JENKINS_URL = "https://jenkins.cryptography.io/job/cryptography-wheel-builder" |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 25 | |
| 26 | |
| 27 | def wait_for_build_completed(): |
| 28 | while True: |
| 29 | response = requests.get( |
| 30 | "{0}/lastBuild/api/json/".format(JENKINS_URL), |
| 31 | headers={ |
| 32 | "Accept": "application/json", |
| 33 | } |
| 34 | ) |
| 35 | response.raise_for_status() |
| 36 | if not response.json()["building"]: |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 37 | assert response.json()["result"] == "SUCCESS" |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 38 | break |
| 39 | time.sleep(0.1) |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 40 | |
Alex Gaynor | c9e4c6a | 2014-02-19 14:29:37 -0800 | [diff] [blame] | 41 | |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 42 | def download_artifacts(): |
| 43 | response = requests.get( |
| 44 | "{0}/lastBuild/api/json/".format(JENKINS_URL), |
| 45 | headers={ |
| 46 | "Accept": "application/json" |
| 47 | } |
| 48 | ) |
| 49 | response.raise_for_status() |
| 50 | assert not response.json()["building"] |
| 51 | assert response.json()["result"] == "SUCCESS" |
Alex Gaynor | 6ab3f46 | 2014-02-20 09:07:53 -0800 | [diff] [blame] | 52 | |
| 53 | paths = [] |
| 54 | |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 55 | for run in response.json()["runs"]: |
| 56 | response = requests.get( |
| 57 | run["url"] + "api/json/", |
| 58 | headers={ |
| 59 | "Accept": "application/json", |
| 60 | } |
| 61 | ) |
| 62 | response.raise_for_status() |
| 63 | for artifact in response.json()["artifacts"]: |
| 64 | response = requests.get( |
Paul Kehrer | 58f1101 | 2014-05-03 20:48:03 -0500 | [diff] [blame] | 65 | "{0}artifact/{1}".format(run["url"], artifact["relativePath"]) |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 66 | ) |
| 67 | out_path = os.path.join( |
| 68 | os.path.dirname(__file__), |
| 69 | "dist", |
| 70 | artifact["fileName"], |
| 71 | ) |
| 72 | with open(out_path, "wb") as f: |
| 73 | f.write(response.content) |
Alex Gaynor | 6ab3f46 | 2014-02-20 09:07:53 -0800 | [diff] [blame] | 74 | paths.append(out_path) |
| 75 | return paths |
Alex Gaynor | 7a2b358 | 2014-02-20 07:48:46 -0800 | [diff] [blame] | 76 | |
| 77 | |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 78 | @invoke.task |
| 79 | def release(version): |
| 80 | """ |
| 81 | ``version`` should be a string like '0.4' or '1.0'. |
| 82 | """ |
Alex Gaynor | 4345c0d | 2014-01-07 11:12:47 -0800 | [diff] [blame] | 83 | invoke.run("git tag -s {0}".format(version)) |
Alex Gaynor | 6b1235a | 2014-01-06 15:28:59 -0800 | [diff] [blame] | 84 | invoke.run("git push --tags") |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 85 | |
Alex Gaynor | fea893c | 2014-01-07 11:06:51 -0800 | [diff] [blame] | 86 | invoke.run("python setup.py sdist") |
Alex Stapleton | 3888a84 | 2014-03-24 23:05:53 +0000 | [diff] [blame] | 87 | invoke.run("cd vectors/ && python setup.py sdist bdist_wheel") |
Alex Stapleton | a39a319 | 2014-03-14 20:03:12 +0000 | [diff] [blame] | 88 | |
| 89 | invoke.run( |
| 90 | "twine upload -s dist/cryptography-{0}* " |
Alex Stapleton | 3888a84 | 2014-03-24 23:05:53 +0000 | [diff] [blame] | 91 | "vectors/dist/cryptography_vectors-{0}*".format(version) |
Alex Stapleton | a39a319 | 2014-03-14 20:03:12 +0000 | [diff] [blame] | 92 | ) |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 93 | |
Alex Gaynor | 6629fa5 | 2014-02-20 16:10:53 -0800 | [diff] [blame] | 94 | token = getpass.getpass("Input the Jenkins token: ") |
Alex Gaynor | c9e4c6a | 2014-02-19 14:29:37 -0800 | [diff] [blame] | 95 | response = requests.post( |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 96 | "{0}/build".format(JENKINS_URL), |
Alex Gaynor | 8620159 | 2014-02-19 14:01:06 -0800 | [diff] [blame] | 97 | params={ |
| 98 | "token": token, |
| 99 | "cause": "Building wheels for {0}".format(version) |
| 100 | } |
| 101 | ) |
Alex Gaynor | c9e4c6a | 2014-02-19 14:29:37 -0800 | [diff] [blame] | 102 | response.raise_for_status() |
Alex Gaynor | a1dff05 | 2014-02-19 16:44:06 -0800 | [diff] [blame] | 103 | wait_for_build_completed() |
Alex Gaynor | 6ab3f46 | 2014-02-20 09:07:53 -0800 | [diff] [blame] | 104 | paths = download_artifacts() |
| 105 | invoke.run("twine upload {0}".format(" ".join(paths))) |