This repository was archived by the owner on Feb 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrelease.py
More file actions
97 lines (79 loc) · 2.81 KB
/
Copy pathrelease.py
File metadata and controls
97 lines (79 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Kubos CLI
# Copyright (C) 2017 Kubos Corporation
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
'''
This script is a REST API client for creating github releases for the kubos-cli
repo
'''
import json
import os
import requests
import sys
from uritemplate import URITemplate, expand
release_endpoint = 'https://api.github.com/repos/kubos/kubos-cli/releases'
try:
token = os.environ['GITHUB_TOKEN']
except KeyError:
print 'Error the environment variable "GITHUB_TOKEN" is not set. Aborting..'
sys.exit(1)
auth = ('username', token)
def create_release(version):
'''
Create a new tag/release in the kubos-cli repo
This function returns the URI template for uploading a release asset
'''
headers = {
'Content-type': 'application/json',
'Accept': 'application/json'
}
data = {
'tag_name': version,
'target_commitish': 'master',
'name': version,
'body': '',
'draft': False,
'prerelease': False
}
res = requests.post(release_endpoint, auth=auth,
headers=headers, data=json.dumps(data))
res.raise_for_status()
return res.json()['upload_url']
def upload_wheel(version, uri_template):
'''
upload the module wheel as a release asset
'''
print 'Uploading the wheel build...'
headers = {
'Content-type': 'application/octet-stream',
'Accept': 'application/json'
}
template = URITemplate(uri_template)
wheel_path = get_wheel_file_path()
wheel_file = os.path.basename(wheel_path)
url = template.expand(name=wheel_file, label=wheel_file)
files = {'files': open(wheel_path, 'rb')}
res = requests.post(url, auth=auth, files=files)
def get_wheel_file_path():
this_dir = os.path.dirname(os.path.abspath(__file__))
dist_dir = os.path.join(this_dir, '..', 'dist')
if os.path.isdir(dist_dir):
for _file in os.listdir(dist_dir):
# Running in a CD environment, there will only be a single wheel build in the dist/ folder
if _file.endswith('.whl'):
return os.path.join(dist_dir, _file)
print 'Unable to find the wheel build under directory %s.. Aborting.' % dist_dir
sys.exit(1)
def github_release(version):
uri_template = create_release(version)
upload_wheel(version, uri_template)