blob: c9fdfa9949d611bea035d8fbab2fe0d61a40e801 [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.
Terry Chiaa0a47cd2014-07-06 17:51:26 +080013
Alex Gaynor0e10f572014-01-06 13:17:31 -080014from __future__ import absolute_import, division, print_function
15
Alex Gaynor86201592014-02-19 14:01:06 -080016import getpass
Alex Gaynor7a2b3582014-02-20 07:48:46 -080017import os
Alex Gaynora1dff052014-02-19 16:44:06 -080018import time
Alex Gaynor86201592014-02-19 14:01:06 -080019
Alex Gaynor6bc3af72014-01-06 12:04:53 -080020import invoke
21
Alex Gaynor86201592014-02-19 14:01:06 -080022import requests
23
24
Paul Kehrer47e5df92014-03-15 08:24:45 -040025JENKINS_URL = "https://jenkins.cryptography.io/job/cryptography-wheel-builder"
Alex Gaynora1dff052014-02-19 16:44:06 -080026
27
28def 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 Gaynor7a2b3582014-02-20 07:48:46 -080038 assert response.json()["result"] == "SUCCESS"
Alex Gaynora1dff052014-02-19 16:44:06 -080039 break
40 time.sleep(0.1)
Alex Gaynor6bc3af72014-01-06 12:04:53 -080041
Alex Gaynorc9e4c6a2014-02-19 14:29:37 -080042
Alex Gaynor7a2b3582014-02-20 07:48:46 -080043def 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 Gaynor6ab3f462014-02-20 09:07:53 -080053
54 paths = []
55
Alex Gaynor7a2b3582014-02-20 07:48:46 -080056 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 Kehrer58f11012014-05-03 20:48:03 -050066 "{0}artifact/{1}".format(run["url"], artifact["relativePath"])
Alex Gaynor7a2b3582014-02-20 07:48:46 -080067 )
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 Gaynor6ab3f462014-02-20 09:07:53 -080075 paths.append(out_path)
76 return paths
Alex Gaynor7a2b3582014-02-20 07:48:46 -080077
78
Alex Gaynor6bc3af72014-01-06 12:04:53 -080079@invoke.task
80def release(version):
81 """
82 ``version`` should be a string like '0.4' or '1.0'.
83 """
Paul Kehrerdd32e952014-07-09 21:14:24 -050084 invoke.run("git tag -s {0} -m '{0} release'".format(version))
Alex Gaynor6b1235a2014-01-06 15:28:59 -080085 invoke.run("git push --tags")
Alex Gaynor6bc3af72014-01-06 12:04:53 -080086
Alex Gaynorfea893c2014-01-07 11:06:51 -080087 invoke.run("python setup.py sdist")
Alex Stapleton3888a842014-03-24 23:05:53 +000088 invoke.run("cd vectors/ && python setup.py sdist bdist_wheel")
Alex Stapletona39a3192014-03-14 20:03:12 +000089
90 invoke.run(
91 "twine upload -s dist/cryptography-{0}* "
Alex Stapleton3888a842014-03-24 23:05:53 +000092 "vectors/dist/cryptography_vectors-{0}*".format(version)
Alex Stapletona39a3192014-03-14 20:03:12 +000093 )
Alex Gaynor86201592014-02-19 14:01:06 -080094
Paul Kehrerd1d6f0f2014-06-20 14:32:02 -060095 username = getpass.getpass("Input the GitHub/Jenkins username: ")
Alex Gaynor6629fa52014-02-20 16:10:53 -080096 token = getpass.getpass("Input the Jenkins token: ")
Alex Gaynorc9e4c6a2014-02-19 14:29:37 -080097 response = requests.post(
Alex Gaynora1dff052014-02-19 16:44:06 -080098 "{0}/build".format(JENKINS_URL),
Paul Kehrerd1d6f0f2014-06-20 14:32:02 -060099 auth=requests.auth.HTTPBasicAuth(
100 username, token
101 ),
Alex Gaynor86201592014-02-19 14:01:06 -0800102 params={
Alex Gaynor86201592014-02-19 14:01:06 -0800103 "cause": "Building wheels for {0}".format(version)
104 }
105 )
Alex Gaynorc9e4c6a2014-02-19 14:29:37 -0800106 response.raise_for_status()
Alex Gaynora1dff052014-02-19 16:44:06 -0800107 wait_for_build_completed()
Alex Gaynor6ab3f462014-02-20 09:07:53 -0800108 paths = download_artifacts()
109 invoke.run("twine upload {0}".format(" ".join(paths)))