Skip to content

Commit 8951419

Browse files
authored
Merge pull request #1841 from rtibbles/release_upload_fix
Fix release uploads
2 parents 027357e + f0ca194 commit 8951419

File tree

4 files changed

+34
-29
lines changed

4 files changed

+34
-29
lines changed

.buildkite/setup_and_upload_artifact.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if [ $? -ne 0 ]; then
2121
exit 1
2222
fi
2323

24-
PIP_CMD="$PIP_PATH install requests"
24+
PIP_CMD="$PIP_PATH install -r requirements/pipeline.txt"
2525
echo "Running $PIP_CMD..."
2626
$PIP_CMD
2727
if [ $? -ne 0 ]; then

.buildkite/upload_artifacts.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import requests
2424
from gcloud import storage
25+
from github3 import login
2526

2627
logging.getLogger().setLevel(logging.INFO)
2728

@@ -98,7 +99,9 @@
9899
'gz',
99100
]
100101

101-
session = requests.Session()
102+
gh = login(token=ACCESS_TOKEN)
103+
repository = gh.repository(REPO_OWNER, REPO_NAME)
104+
102105

103106
def create_status_report_html(artifacts):
104107
"""
@@ -122,22 +125,17 @@ def create_github_status(report_url):
122125
Create a github status with a link to the report URL,
123126
only do this once buildkite has been successful, so only report success here.
124127
"""
125-
url = 'https://api.github.com/repos/{owner}/{repo}/statuses/{commit}'.format(
126-
owner=REPO_OWNER,
127-
repo=REPO_NAME,
128-
commit=COMMIT
128+
status = repository.create_status(
129+
COMMIT,
130+
"success",
131+
target_url=report_url,
132+
description="Kolibri Buildkite assets",
133+
context="buildkite/kolibri/assets"
129134
)
130-
payload = {
131-
"state": "success",
132-
"target_url": report_url,
133-
"description": "Kolibri Buildkite assets",
134-
"context": "buildkite/kolibri/assets"
135-
}
136-
r = session.post(url, json=payload, headers=headers)
137-
if r.status_code == 201:
138-
logging.info('Successfully created Github status(%s).' % url)
135+
if status:
136+
logging.info('Successfully created Github status for commit %s.' % COMMIT)
139137
else:
140-
logging.info('Error encounter(%s). Now exiting!' % r.status_code)
138+
logging.info('Error encounter. Now exiting!')
141139
sys.exit(1)
142140

143141

@@ -195,6 +193,7 @@ def upload_artifacts():
195193

196194
if TAG:
197195
# Building from a tag, this is probably a release!
196+
# Have to do this with requests because github3 does not support this interface yet
198197
get_release_asset_url = requests.get("https://api.github.com/repos/{owner}/{repo}/releases/tags/{tag}".format(
199198
owner=REPO_OWNER,
200199
repo=REPO_NAME,
@@ -203,21 +202,24 @@ def upload_artifacts():
203202
if get_release_asset_url.status_code == 200:
204203
# Definitely a release!
205204
release_id = get_release_asset_url.json()['id']
206-
url = "https://api.github.com/repos/{owner}/{repo}/releases/{id}/assets".format(
207-
owner=REPO_OWNER,
208-
repo=REPO_NAME,
209-
id=release_id,
210-
)
205+
release_name = get_release_asset_url.json()['name']
206+
release = repository.release(id=release_id)
207+
logging.info("Uploading built assets to Github Release: %s" % release_name)
211208
for file_extension in file_order:
212209
artifact = artifacts[file_extension]
213-
params = {
214-
'name': artifact['name'],
215-
'label': artifact['description']
216-
}
217-
files = {
218-
'file': (artifact['name'], open(artifact['file_location'], 'rb'), artifact['content_type'])
219-
}
220-
session.post(url, params=params, files=files, headers=headers)
210+
logging.info("Uploading release asset: %s" % (artifact.get("name")))
211+
# For some reason github3 does not let us set a label at initial upload
212+
asset = release.upload_asset(
213+
content_type=artifact['content_type'],
214+
name=artifact['name'],
215+
asset=open(artifact['file_location'], 'rb')
216+
)
217+
if asset:
218+
# So do it after the initial upload instead
219+
asset.edit(artifact['name'], label=artifact['description'])
220+
logging.info("Successfully uploaded release asset: %s" % (artifact.get('name')))
221+
else:
222+
logging.error("Error uploading release asset: %s" % (artifact.get('name')))
221223

222224

223225
def main():

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ RUN apt-get install -y python2.7 python3.6 python-pip git nodejs yarn gettext py
1515
COPY . /kolibri
1616

1717
VOLUME /kolibridist/ # for mounting the whl files into other docker containers
18+
# add buildkite pipeline specific installation here:
1819
CMD cd /kolibri && pip install -r requirements/dev.txt && pip install -r requirements/build.txt && yarn install && make dist && cp /kolibri/dist/* /kolibridist/
1920

requirements/pipeline.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests==2.10.0
2+
github3.py==0.9.6

0 commit comments

Comments
 (0)