Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
[ci] Automatically upload debuggable object to github releases. (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
pengdev authored Jun 1, 2020
1 parent 60e5d8c commit 6f7073a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,11 @@ jobs:
make run-android-upload-to-artifactory
fi
fi
- run:
name: upload debuggable objects to release tag
command: |
if [[ $CIRCLE_TAG == android-v* ]]; then
export GITHUB_TOKEN=${DANGER_GITHUB_API_TOKEN}
python3 scripts/upload-to-github-release.py --file MapboxGLAndroidSDK/build/intermediates/cmake/release/debuggable-objects.tar.gz --release $CIRCLE_TAG --project mapbox-gl-native-android
fi
- generate-api-javadoc
37 changes: 37 additions & 0 deletions scripts/upload-to-github-release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python
import argparse
import os
import requests
import re

###
### Script input
###
parser = argparse.ArgumentParser(description='Script to upload debuggable objects to the github release. (Note: Valid GITHUB_TOKEN must exist in the environment variable).')
parser.add_argument('-d', '--dryrun', help= 'Request for the upload url without uploading to github.', action='store_true')
requiredNamed = parser.add_argument_group('required named arguments')
requiredNamed.add_argument('-f', '--file', help= 'Provide the path to the file to be uploaded.', required=True)
requiredNamed.add_argument('-p', '--project', help= 'Provide the Mapbox git project name.', required=True)
requiredNamed.add_argument('-r', '--release', help= 'Provide the release tag which the file is uploaded to.', required=True)

args = parser.parse_args()
filePath = os.path.abspath(args.file)
release = args.release
project = args.project
isLocal = args.dryrun

# request for upload url
fileName = os.path.basename(filePath)
githubRelease = requests.get(f"https://api.github.com/repos/mapbox/{project}/releases/tags/{release}")
if githubRelease.status_code == 200:
uploadUrl = re.sub("[\{].*?[\}]", "", githubRelease.json()["upload_url"])
print(f"Github upload Url: {uploadUrl}?name={fileName}")
if not isLocal:
# upload file to github release
print("Uploading..")
with open(filePath, 'rb') as f:
headers = {'content-type': 'application/octet-stream', 'authorization': f"token {os.environ.get('GITHUB_TOKEN')}"}
r = requests.post(f"{uploadUrl}?name={fileName}", headers=headers , files={fileName: f})
print(f"Upload response: {r.text}")
else:
print(f"### request for upload url failed: {githubRelease.text}")

0 comments on commit 6f7073a

Please sign in to comment.