From 71a7f38a88fb0e7611a21fb4a8a2751473825f1e Mon Sep 17 00:00:00 2001 From: scribblemaniac Date: Tue, 4 Dec 2018 01:14:19 -0700 Subject: [PATCH 1/2] Upload internal PR builds for macOS and Linux --- .travis.yml | 15 ++++++++++++- util/pr-build-upload.py | 48 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100755 util/pr-build-upload.py diff --git a/.travis.yml b/.travis.yml index a3940869cc..c08c9f9ff6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,7 +49,7 @@ addons: - python3-pip before_install: - - | + - | if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; ver=$(python -V 2>&1 | sed 's/.* \([0-9]\).\([0-9]\).*/\1\2/'); @@ -150,6 +150,19 @@ after_success: fi; echo "Operation done"; fi' + # Upload internal pull request to google drive + - 'if [ \( "$TRAVIS_PULL_REQUEST_SLUG" == "pencil2d/pencil" ]; then + echo "Initiate deployment on Google Drive"; + cd "$TRAVIS_BUILD_DIR/util"; + if [ "$TRAVIS_OS_NAME" == "linux" ]; then + mv "$TRAVIS_BUILD_DIR/build/pencil2d-linux-$(date +"%Y-%m-%d").zip" "$TRAVIS_BUILD_DIR/build/pencil2d-linux-pr-$TRAVIS_PULL_REQUEST.zip" + python3 pr-build-upload.py "$LINUX_PR_PARENT" "$TRAVIS_BUILD_DIR/build/pencil2d-linux-pr-$TRAVIS_PULL_REQUEST.zip"; + fi; + if [ "$TRAVIS_OS_NAME" == "osx" ]; then + mv "$TRAVIS_BUILD_DIR/build/pencil2d-mac-$(date +"%Y-%m-%d").zip" "$TRAVIS_BUILD_DIR/build/pencil2d-mac-pr-$TRAVIS_PULL_REQUEST.zip" + python3 pr-build-upload.py "$OSX_PR_PARENT" "$TRAVIS_BUILD_DIR/build/pencil2d-mac--pr-$TRAVIS_PULL_REQUEST.zip"; + fi; + fi' # Deploy doxygen documentation to github pages - 'if [ "$TRAVIS_BRANCH" == "master" -a "$TRAVIS_OS_NAME" == "linux" ]; then diff --git a/util/pr-build-upload.py b/util/pr-build-upload.py new file mode 100755 index 0000000000..110ada6232 --- /dev/null +++ b/util/pr-build-upload.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 + +# This script is used to upload nightly builds to Google Drive. +# To use it, a service account with access to the target directory in Google +# Drive is required and the environment variable GOOGLE_PRIVATE_KEY must +# contain the private key of the service account in JSON format. + +# Google Drive API v3 Reference: +# https://developers.google.com/resources/api-libraries/documentation/drive/v3/python/latest/index.html + +import json +import os +import sys +import datetime + +from apiclient import discovery +from apiclient.http import MediaFileUpload +from httplib2 import Http +from oauth2client.service_account import ServiceAccountCredentials + +private_key = os.getenv('GOOGLE_PRIVATE_KEY') +if private_key == None: + print("Error: Private key not set") + sys.exit(1) + +if len(sys.argv) != 3: + print("Usage: %s [parent] [file]" % sys.argv[0]) + sys.exit(1) +[parent, file] = sys.argv[1:] + +# Build google drive service +scopes = ['https://www.googleapis.com/auth/drive'] +keyfile_dict = json.loads(private_key) +credentials = ServiceAccountCredentials.from_json_keyfile_dict(keyfile_dict, scopes=scopes) +http = credentials.authorize(Http()) +drive_service = discovery.build('drive', 'v3', http=http) + +# Check if file already exits (ie. there is a previous build for this PR) +response = drive_service.files().list(q="name = '%s'" % os.path.basename(file), spaces='drive').execute() +files = response.get("files") +media = MediaFileUpload(file) +if files: + # Upload pull request build as revision + response = drive_service.files().update(fileId=files[0].get("id"), media_body=media).execute() +else: + # Upload pull request build as new file + file_metadata = { 'name' : os.path.basename(file), 'parents': [parent] } + response = drive_service.files().create(body=file_metadata, media_body=media).execute() From 767fb41ec4c0d99de83a5da53c4181ed719f22fc Mon Sep 17 00:00:00 2001 From: scribblemaniac Date: Wed, 5 Dec 2018 20:33:09 -0700 Subject: [PATCH 2/2] Upload internal PR builds for Windows --- appveyor.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index cd5c870e1f..0ee270e269 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -86,6 +86,12 @@ after_build: echo "deploying to google drive" & cd %APPVEYOR_BUILD_FOLDER%\util & call %PYTHON%\\python.exe nightly-build-upload.py "%WIN32_NIGHTLY_PARENT%" "%APPVEYOR_BUILD_FOLDER%\build\pencil2d-win32-%date:~-4,4%"-"%date:~-10,2%"-"%date:~7,2%.zip" & + echo "32 Bit deployed" ) + if %APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME=="pencil2d/pencil" ( + echo "deploying to google drive" & + cd %APPVEYOR_BUILD_FOLDER%\util & + move /y "%APPVEYOR_BUILD_FOLDER%\build\pencil2d-win32-%date:~-4,4%"-"%date:~-10,2%"-"%date:~7,2%.zip" "%APPVEYOR_BUILD_FOLDER%\build\pencil2d-win32-pr-%APPVEYOR_PULL_REQUEST_NUMBER%.zip" & + call %PYTHON%\\python.exe pr-build-upload.py "%WIN32_NIGHTLY_PARENT%" "%APPVEYOR_BUILD_FOLDER%\build\pencil2d-win32-pr-%APPVEYOR_PULL_REQUEST_NUMBER%.zip" & echo "32 Bit deployed" ) ) - if %PLATFORM_%==amd64 ( @@ -112,4 +118,10 @@ after_build: echo "deploying to google drive" & cd %APPVEYOR_BUILD_FOLDER%\util & call %PYTHON%\\python.exe nightly-build-upload.py "%WIN64_NIGHTLY_PARENT%" "%APPVEYOR_BUILD_FOLDER%\build\pencil2d-win64-%date:~-4,4%"-"%date:~-10,2%"-"%date:~7,2%.zip" & + echo "64 Bit Deployed" ) + if %APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME=="pencil2d/pencil" ( + echo "deploying to google drive" & + cd %APPVEYOR_BUILD_FOLDER%\util & + move /y "%APPVEYOR_BUILD_FOLDER%\build\pencil2d-win64-%date:~-4,4%"-"%date:~-10,2%"-"%date:~7,2%.zip" "%APPVEYOR_BUILD_FOLDER%\build\pencil2d-win64-pr-%APPVEYOR_PULL_REQUEST_NUMBER%.zip" & + call %PYTHON%\\python.exe pr-build-upload.py "%WIN64_NIGHTLY_PARENT%" "%APPVEYOR_BUILD_FOLDER%\build\pencil2d-win64-pr-%APPVEYOR_PULL_REQUEST_NUMBER%.zip" & echo "64 Bit Deployed" ) )