2014-11-16 17:08:42 +00:00
|
|
|
# This file is dual licensed under the terms of the Apache License, Version
|
|
|
|
|
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
|
|
|
|
|
# for complete details.
|
2014-07-06 09:51:26 +00:00
|
|
|
|
2014-01-06 21:17:31 +00:00
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
|
|
2014-02-19 22:01:06 +00:00
|
|
|
import getpass
|
2014-02-20 15:48:46 +00:00
|
|
|
import os
|
2014-02-20 00:44:06 +00:00
|
|
|
import time
|
2014-02-19 22:01:06 +00:00
|
|
|
|
2014-01-06 20:04:53 +00:00
|
|
|
import invoke
|
|
|
|
|
|
2014-02-19 22:01:06 +00:00
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
|
2014-03-15 12:24:45 +00:00
|
|
|
JENKINS_URL = "https://jenkins.cryptography.io/job/cryptography-wheel-builder"
|
2014-02-20 00:44:06 +00:00
|
|
|
|
|
|
|
|
|
2014-09-27 03:30:31 +00:00
|
|
|
def wait_for_build_completed(session):
|
2014-12-24 14:07:56 +00:00
|
|
|
# Wait 20 seconds before actually checking if the build is complete, to
|
2014-12-16 17:32:59 +00:00
|
|
|
# ensure that it had time to really start.
|
2014-12-24 14:07:56 +00:00
|
|
|
time.sleep(20)
|
2014-02-20 00:44:06 +00:00
|
|
|
while True:
|
2014-09-27 03:30:31 +00:00
|
|
|
response = session.get(
|
2014-02-20 00:44:06 +00:00
|
|
|
"{0}/lastBuild/api/json/".format(JENKINS_URL),
|
|
|
|
|
headers={
|
|
|
|
|
"Accept": "application/json",
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
response.raise_for_status()
|
|
|
|
|
if not response.json()["building"]:
|
2014-02-20 15:48:46 +00:00
|
|
|
assert response.json()["result"] == "SUCCESS"
|
2014-02-20 00:44:06 +00:00
|
|
|
break
|
|
|
|
|
time.sleep(0.1)
|
2014-01-06 20:04:53 +00:00
|
|
|
|
2014-02-19 22:29:37 +00:00
|
|
|
|
2014-09-27 03:30:31 +00:00
|
|
|
def download_artifacts(session):
|
|
|
|
|
response = session.get(
|
2014-02-20 15:48:46 +00:00
|
|
|
"{0}/lastBuild/api/json/".format(JENKINS_URL),
|
|
|
|
|
headers={
|
|
|
|
|
"Accept": "application/json"
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
response.raise_for_status()
|
|
|
|
|
assert not response.json()["building"]
|
|
|
|
|
assert response.json()["result"] == "SUCCESS"
|
2014-02-20 17:07:53 +00:00
|
|
|
|
|
|
|
|
paths = []
|
|
|
|
|
|
2015-05-29 04:23:26 +00:00
|
|
|
last_build_number = response.json()["number"]
|
2014-02-20 15:48:46 +00:00
|
|
|
for run in response.json()["runs"]:
|
2015-05-29 04:23:26 +00:00
|
|
|
if run["number"] != last_build_number:
|
|
|
|
|
print(
|
|
|
|
|
"Skipping {0} as it is not from the latest build ({1})".format(
|
|
|
|
|
run["url"], last_build_number
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
continue
|
|
|
|
|
|
2014-09-27 03:30:31 +00:00
|
|
|
response = session.get(
|
2014-02-20 15:48:46 +00:00
|
|
|
run["url"] + "api/json/",
|
|
|
|
|
headers={
|
|
|
|
|
"Accept": "application/json",
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
response.raise_for_status()
|
|
|
|
|
for artifact in response.json()["artifacts"]:
|
2014-09-27 03:30:31 +00:00
|
|
|
response = session.get(
|
2014-05-04 01:48:03 +00:00
|
|
|
"{0}artifact/{1}".format(run["url"], artifact["relativePath"])
|
2014-02-20 15:48:46 +00:00
|
|
|
)
|
|
|
|
|
out_path = os.path.join(
|
|
|
|
|
os.path.dirname(__file__),
|
|
|
|
|
"dist",
|
|
|
|
|
artifact["fileName"],
|
|
|
|
|
)
|
|
|
|
|
with open(out_path, "wb") as f:
|
|
|
|
|
f.write(response.content)
|
2014-02-20 17:07:53 +00:00
|
|
|
paths.append(out_path)
|
|
|
|
|
return paths
|
2014-02-20 15:48:46 +00:00
|
|
|
|
|
|
|
|
|
2014-01-06 20:04:53 +00:00
|
|
|
@invoke.task
|
|
|
|
|
def release(version):
|
|
|
|
|
"""
|
|
|
|
|
``version`` should be a string like '0.4' or '1.0'.
|
|
|
|
|
"""
|
2014-07-10 02:14:24 +00:00
|
|
|
invoke.run("git tag -s {0} -m '{0} release'".format(version))
|
2014-01-06 23:28:59 +00:00
|
|
|
invoke.run("git push --tags")
|
2014-01-06 20:04:53 +00:00
|
|
|
|
2014-01-07 19:06:51 +00:00
|
|
|
invoke.run("python setup.py sdist")
|
2014-03-24 23:05:53 +00:00
|
|
|
invoke.run("cd vectors/ && python setup.py sdist bdist_wheel")
|
2014-03-14 20:03:12 +00:00
|
|
|
|
|
|
|
|
invoke.run(
|
|
|
|
|
"twine upload -s dist/cryptography-{0}* "
|
2014-03-24 23:05:53 +00:00
|
|
|
"vectors/dist/cryptography_vectors-{0}*".format(version)
|
2014-03-14 20:03:12 +00:00
|
|
|
)
|
2014-02-19 22:01:06 +00:00
|
|
|
|
2014-09-27 03:30:31 +00:00
|
|
|
session = requests.Session()
|
|
|
|
|
|
2014-09-28 16:00:49 +00:00
|
|
|
# This tells the CDN to delete the cached response for the URL. We do this
|
|
|
|
|
# so that the Jenkins builders will see the new sdist immediately when they
|
|
|
|
|
# go to build the wheels.
|
2014-09-27 03:31:19 +00:00
|
|
|
response = session.request(
|
|
|
|
|
"PURGE", "https://pypi.python.org/simple/cryptography/"
|
|
|
|
|
)
|
2014-09-27 03:30:31 +00:00
|
|
|
response.raise_for_status()
|
|
|
|
|
|
2014-06-20 20:32:02 +00:00
|
|
|
username = getpass.getpass("Input the GitHub/Jenkins username: ")
|
2014-02-21 00:10:53 +00:00
|
|
|
token = getpass.getpass("Input the Jenkins token: ")
|
2014-09-27 03:30:31 +00:00
|
|
|
response = session.post(
|
2014-02-20 00:44:06 +00:00
|
|
|
"{0}/build".format(JENKINS_URL),
|
2014-06-20 20:32:02 +00:00
|
|
|
auth=requests.auth.HTTPBasicAuth(
|
|
|
|
|
username, token
|
|
|
|
|
),
|
2014-02-19 22:01:06 +00:00
|
|
|
params={
|
|
|
|
|
"cause": "Building wheels for {0}".format(version)
|
|
|
|
|
}
|
|
|
|
|
)
|
2014-02-19 22:29:37 +00:00
|
|
|
response.raise_for_status()
|
2014-09-27 03:30:31 +00:00
|
|
|
wait_for_build_completed(session)
|
|
|
|
|
paths = download_artifacts(session)
|
2014-02-20 17:07:53 +00:00
|
|
|
invoke.run("twine upload {0}".format(" ".join(paths)))
|