blob: 9ffdc8a7c7e28d8b69a96c7cc487e0150c3be166 [file] [log] [blame]
Alex Gaynor0e10f572014-01-06 13:17:31 -08001# 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.
13from __future__ import absolute_import, division, print_function
14
Alex Gaynor86201592014-02-19 14:01:06 -080015import getpass
Alex Gaynor7a2b3582014-02-20 07:48:46 -080016import os
Alex Gaynora1dff052014-02-19 16:44:06 -080017import time
Alex Gaynor86201592014-02-19 14:01:06 -080018
Alex Gaynor6bc3af72014-01-06 12:04:53 -080019import invoke
20
Alex Gaynor86201592014-02-19 14:01:06 -080021import requests
22
23
Paul Kehrer47e5df92014-03-15 08:24:45 -040024JENKINS_URL = "https://jenkins.cryptography.io/job/cryptography-wheel-builder"
Alex Gaynora1dff052014-02-19 16:44:06 -080025
26
27def 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 Gaynor7a2b3582014-02-20 07:48:46 -080037 assert response.json()["result"] == "SUCCESS"
Alex Gaynora1dff052014-02-19 16:44:06 -080038 break
39 time.sleep(0.1)
Alex Gaynor6bc3af72014-01-06 12:04:53 -080040
Alex Gaynorc9e4c6a2014-02-19 14:29:37 -080041
Alex Gaynor7a2b3582014-02-20 07:48:46 -080042def 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 Gaynor6ab3f462014-02-20 09:07:53 -080052
53 paths = []
54
Alex Gaynor7a2b3582014-02-20 07:48:46 -080055 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 Kehrer58f11012014-05-03 20:48:03 -050065 "{0}artifact/{1}".format(run["url"], artifact["relativePath"])
Alex Gaynor7a2b3582014-02-20 07:48:46 -080066 )
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 Gaynor6ab3f462014-02-20 09:07:53 -080074 paths.append(out_path)
75 return paths
Alex Gaynor7a2b3582014-02-20 07:48:46 -080076
77
Alex Gaynor6bc3af72014-01-06 12:04:53 -080078@invoke.task
79def release(version):
80 """
81 ``version`` should be a string like '0.4' or '1.0'.
82 """
Alex Gaynor4345c0d2014-01-07 11:12:47 -080083 invoke.run("git tag -s {0}".format(version))
Alex Gaynor6b1235a2014-01-06 15:28:59 -080084 invoke.run("git push --tags")
Alex Gaynor6bc3af72014-01-06 12:04:53 -080085
Alex Gaynorfea893c2014-01-07 11:06:51 -080086 invoke.run("python setup.py sdist")
Alex Stapleton3888a842014-03-24 23:05:53 +000087 invoke.run("cd vectors/ && python setup.py sdist bdist_wheel")
Alex Stapletona39a3192014-03-14 20:03:12 +000088
89 invoke.run(
90 "twine upload -s dist/cryptography-{0}* "
Alex Stapleton3888a842014-03-24 23:05:53 +000091 "vectors/dist/cryptography_vectors-{0}*".format(version)
Alex Stapletona39a3192014-03-14 20:03:12 +000092 )
Alex Gaynor86201592014-02-19 14:01:06 -080093
Alex Gaynor6629fa52014-02-20 16:10:53 -080094 token = getpass.getpass("Input the Jenkins token: ")
Alex Gaynorc9e4c6a2014-02-19 14:29:37 -080095 response = requests.post(
Alex Gaynora1dff052014-02-19 16:44:06 -080096 "{0}/build".format(JENKINS_URL),
Alex Gaynor86201592014-02-19 14:01:06 -080097 params={
98 "token": token,
99 "cause": "Building wheels for {0}".format(version)
100 }
101 )
Alex Gaynorc9e4c6a2014-02-19 14:29:37 -0800102 response.raise_for_status()
Alex Gaynora1dff052014-02-19 16:44:06 -0800103 wait_for_build_completed()
Alex Gaynor6ab3f462014-02-20 09:07:53 -0800104 paths = download_artifacts()
105 invoke.run("twine upload {0}".format(" ".join(paths)))