This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ci] Automatically upload debuggable object to github releases. (#403)
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |