From 9b268395f26ba02f0cb73fe93f56e54a03beb53e Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 1 May 2021 19:54:48 +0300 Subject: [PATCH] Bintray is no longer available for us. --- .travis.yml | 42 +++++++-------- appveyor.yml | 29 +++++------ scripts/deploy.py | 129 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+), 39 deletions(-) create mode 100644 scripts/deploy.py diff --git a/.travis.yml b/.travis.yml index dda0880d7..e005f8fcb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,7 @@ language: cpp +env: + global: + - secure: Zo+BbyV3sgNmKHwWvn7cCt3leXCLGbE9rSrAYoCrl22OEDZjPj7KeGzQ/59xLosE5v8PA5MV8KceH7aQB9GoIbDt6sHLw5mws13VXmy5HWtM7yhk2RpNnn1gTZIfEz33QGYuPG1geapTcZtZfaVKFU04PMkvk3f7zxA1HuS6zGRgzrNv1AmcpuOGH4LIGxbk3Z1S6xGcUMj/z9calyLlmPTOfbDLJWChU11FMVmvdTzyeDLE0oQZ5IkmsowluCfDHARfIijeRuPiuU8RzJptYEIzcWvpQ6gfDb4qDWndA9BgPDkN2aTmPL5/TA/S9zfs8BKjo07sg0TaVbTboPisyS/gGDf3SBYxlAS9B95KKdRzGGD41ZYe+cHod5tgWUt5gO/Obq2MPY/GltSwuq5KEsR+R/pKVLby/k7+R5oCO8avXJPL5HBgn46ZehEzpw0I8LFQ/ed+dLqykrxaSiA2/zHAkHSeVZptzegoCF5xeDf6T/rJFNqxr1BV3kVLPiXW90z0m63Hv2K6rz8LmBUNTQcR/mrLpkpdbQ8UQ/et30o7CE2GcJLLzUDNcjxYfA1fe66oR9L+euqyBtZc8dNuzy1iIaUOLazGWYkdlUpiYnGvWrxv6BUwzAJYpiXjWELtcTVUGMjMBpkvAmwV1FjZN45isX2iHGz5XhoVDrjbE5c= jobs: include: - stage: main test @@ -9,10 +12,10 @@ jobs: - DEPLOY=false - CCACHE_CPP2=yes - RUN_TESTS=true - cache: - ccache: true - directories: - - "$HOME/.sonar/cache" + cache: + ccache: true + directories: + - "$HOME/.sonar/cache" - os: linux dist: bionic compiler: clang @@ -21,9 +24,9 @@ jobs: - CCACHE_CPP2=yes - RUN_TESTS=true cache: - ccache: true - directories: - - "$HOME/.sonar/cache" + ccache: true + directories: + - "$HOME/.sonar/cache" - os: osx compiler: clang env: @@ -32,8 +35,8 @@ jobs: osx_image: xcode11 cache: directories: - - $HOME/Library/Caches/Homebrew - - /usr/local/Homebrew + - "$HOME/Library/Caches/Homebrew" + - "/usr/local/Homebrew" - os: osx compiler: clang env: @@ -42,8 +45,8 @@ jobs: osx_image: xcode8 cache: directories: - - $HOME/Library/Caches/Homebrew - - /usr/local/Homebrew + - "$HOME/Library/Caches/Homebrew" + - "/usr/local/Homebrew" before_cache: - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then brew cleanup; fi # Credit https://discourse.brew.sh/t/best-practice-for-homebrew-on-travis-brew-update-is-5min-to-build-time/5215/9 @@ -80,6 +83,9 @@ before_install: brew link qt --force; chmod -R 755 /usr/local/opt/qt/* fi + brew install python3; + python3 --version; + pip install dropbox; fi before_script: - | @@ -129,23 +135,15 @@ notifications: - dismine@gmail.com on_success: change on_failure: always -before_deploy: +after_success: - | if [[ "$DEPLOY" == "true" ]]; then ../scripts/macfixqtdylibrpath.py $TRAVIS_BUILD_DIR/build/src/app/valentina/bin/Valentina.app; if [[ "$LEGACY" = false ]]; then tar -C $TRAVIS_BUILD_DIR/build/src/app/valentina/bin --exclude "*.DS_Store" -cvzf valentina-osx-${TRAVIS_COMMIT}.tar.gz Valentina.app/; + python3 $TRAVIS_BUILD_DIR/scripts/deploy.py upload $ACCESS_TOKEN $TRAVIS_BUILD_DIR/build/src/app/valentina/bin/valentina-osx-${TRAVIS_COMMIT}.tar.gz "0.7.x/Mac OS X/valentina-osx-${TRAVIS_COMMIT}.tar.gz"; else tar -C $TRAVIS_BUILD_DIR/build/src/app/valentina/bin --exclude "*.DS_Store" -cvzf valentina-osx-${TRAVIS_COMMIT}-legacy.tar.gz Valentina.app/; + python3 $TRAVIS_BUILD_DIR/scripts/deploy.py upload $ACCESS_TOKEN $TRAVIS_BUILD_DIR/build/src/app/valentina/bin/valentina-osx-${TRAVIS_COMMIT}-legacy.tar.gz "0.7.x/Mac OS X/valentina-osx-${TRAVIS_COMMIT}-legacy.tar.gz"; fi fi -deploy: - provider: bintray - skip_cleanup: true - file: "../share/bintray.json" - user: dismine - key: - secure: q9rcswyUyOqHAnxL0FLEQ8tdFkE21kNlv/TUpZgk0MbcsWRhBWaKJVv5kz6ABkjeLMB7c7eS7KfYRui0RFBKHI7ZnpzHBZN4f1aGd/rf9m5qaZdKFFBlpz4tXPHvXOVyXRwOReqFj7brAz6NB+oqJN8HFA4Q1y039yZOaHt28JkwYSDqS5lRvbwegYS8kaJupGZcm8NaNeB8tuXuZ/8DIQpZdVKmBUwpgpPAewCEqYP4z9DUpsmMZ5h63g7mJKm9di91cQr65eS24io6m1ZfAx8M6kTaKwyR5nz8a8bnqR48AAnbNoM8Xj1sgJqnT40DZKPCNr7KL3JSNRglKNgHVMFBOj0v9F5YxsDs8twWuqFVbywB+lNSHDyvGVgmS2+EdwKLQT0YBxYfIL1nh34ed7GffZZmBcAJGfxo8ieAMRgyylSyQIHJ0ZBl6X6DzOvLpvFlcva9yhqZfkx3P/Dgarqklnj3DdvzTDW2vxCT4yVLpMySlBXW2I3s7m8xpOjZbM7eZfMZkwjd/e8IYp8jxdQnxlzNe15mzxSXnZjLz3Rwi1qzhJZyZf4OGVxuQuR9oW+c5q55OOY5hImtZELlJyu1K0zKTd85g0D+WwKj4J30J0QWl1pxZlln59Q5cMmpyQ7sc8zN1WPoWAEyavwPrf4028TpEJqaUw/0cQGg9I4= - on: - all_branches: true - condition: "$DEPLOY = true" diff --git a/appveyor.yml b/appveyor.yml index ca4c6877a..01e4340a4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -37,12 +37,15 @@ clone_depth: 1 # clone entire repository history if not de shallow_clone: false # default is "false" environment: + ACCESS_TOKEN: + secure: RUhnEHqaR8KhalOMWwZZOoO342Ja50QV4KpEWdm9g3pG+jG7i6aJqUmeKF1l5VN6dzksk1u+yN6pOLnU8oGcaVQ6v+1dpKK1oZvF0tyHhNE= matrix: - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 QT5: Qt\5.15\mingw81_32 QT_VERSION: Qt5.15 QMAKE_GENERATOR: "MinGW Makefiles" MINGW_PATH: C:\Qt\Tools\mingw810_32\bin + PYTHON: "C:\\Python38" PLATFORM: x86 DEPLOY: true - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 @@ -50,6 +53,7 @@ environment: QT_VERSION: Qt5.6 QMAKE_GENERATOR: "MinGW Makefiles" MINGW_PATH: C:\Qt\Tools\mingw492_32\bin + PYTHON: "C:\\Python38" PLATFORM: x86 DEPLOY: true - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 @@ -191,6 +195,8 @@ init: - if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" if "%QMAKE_GENERATOR%"=="NMake Makefiles JOM" if "%PLATFORM%"=="x64" call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64 - if "%QMAKE_GENERATOR%" == "MinGW Makefiles" set PATH=%MINGW_PATH%;%PATH% - if "%QMAKE_GENERATOR%" == "NMake Makefiles JOM" set PATH=C:\Qt\Tools\QtCreator\bin;%PATH% + - if "%DEPLOY%" == "true" "%PYTHON%\\python -m pip install dropbox" + - if "%DEPLOY%" == "true" set PATH="%PYTHON%\\Scripts\\;%PATH%" - set PATH=C:\projects\valentina\build\src\libs\vpropertyexplorer\bin;C:\projects\valentina\build\src\libs\qmuparser\bin;%PATH% # Path after - path @@ -244,21 +250,10 @@ notifications: after_test: - if "%DEPLOY%" == "true" (mingw32-make install) -artifacts: - - path: build/package/valentina - name: valentina-win-$(QT_VERSION)-$(APPVEYOR_REPO_BRANCH)-$(APPVEYOR_REPO_COMMIT) +# scripts to run before deployment +before_deploy: + - if "%DEPLOY%" == "true" (%PYTHON%\\python ..\scripts\deploy.py pack ./package/valentina/ ./package/valentina-win-$(PLATFORM)-$(QT_VERSION)-$(APPVEYOR_REPO_BRANCH)-$(APPVEYOR_REPO_COMMIT).zip) -deploy: -- provider: BinTray - username: dismine - api_key: - secure: dlVBgPG66AfYTbgi9EQFaK4lZeF77H6/aiuKlmCWP02/i85HLtCMnlOkyWJR5XCu - subject: dismine - repo: Valentina - package: valentina-win_auto-upload - publish: true - override: true - version: 0.7.46 - on: - DEPLOY: true - artifact: valentina-win-$(QT_VERSION)-$(APPVEYOR_REPO_BRANCH)-$(APPVEYOR_REPO_COMMIT) +# to run your custom scripts instead of provider deployments +deploy_script: + - if "%DEPLOY%" == "true" (%PYTHON%\\python ..\scripts\deploy.py upload $(ACCESS_TOKEN) ./package/valentina-win-$(PLATFORM)-$(QT_VERSION)-$(APPVEYOR_REPO_BRANCH)-$(APPVEYOR_REPO_COMMIT).zip /0.7.x/Windows/valentina-win-$(PLATFORM)-$(QT_VERSION)-$(APPVEYOR_REPO_BRANCH)-$(APPVEYOR_REPO_COMMIT).zip) diff --git a/scripts/deploy.py b/scripts/deploy.py new file mode 100644 index 000000000..a66fae704 --- /dev/null +++ b/scripts/deploy.py @@ -0,0 +1,129 @@ +import argparse +import os +import pathlib +import shutil +import sys + +import dropbox +from dropbox import DropboxOAuth2FlowNoRedirect +from dropbox.exceptions import ApiError, AuthError +from dropbox.files import WriteMode + +APP_KEY = "v33m5tjz020h7uy" + + +def run_auth(): + """ + Use to generate a refresh token + """ + auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, use_pkce=True, token_access_type='offline') + + authorize_url = auth_flow.start() + print("1. Go to: " + authorize_url) + print("2. Click \"Allow\" (you might have to log in first).") + print("3. Copy the authorization code.") + auth_code = input("Enter the authorization code here: ").strip() + + try: + oauth_result = auth_flow.finish(auth_code) + except Exception as e: + print('Error: %s' % (e,)) + exit(1) + + print("Refresh token: %s" % oauth_result.refresh_token) + + +def run_pack(source, destination): + """ + Pack folder. Automatically fills arguments for shutil.make_archive. + :param source: path to source root directory. Example: '/path/to/folder/' + :param destination: path to resulting zip archive. The path must include a format suffix. + Example: '/path/to/folder.zip' + """ + base = os.path.basename(destination) + name = base.split('.')[0] + + formats = { + ".zip": "zip", + ".tar.xz": "xztar" + } + suffix = ''.join(pathlib.Path(base).suffixes) + format = formats.get(suffix, None) + archive_from = pathlib.Path(source).parent + archive_to = os.path.basename(source.strip(os.sep)) + print(source, destination, archive_from) + shutil.make_archive(name, format, archive_from, archive_to) + shutil.move('%s%s' % (name, suffix), destination) + + +def run_upload(refresh_token, file, path): + with dropbox.Dropbox(oauth2_refresh_token=refresh_token, app_key=APP_KEY) as dbx: + # Check that the access token is valid + try: + dbx.users_get_current_account() + except AuthError: + sys.exit("ERROR: Invalid access token; try re-generating an " + "access token from the app console on the web.") + + print("Uploading " + file + " to Dropbox as " + path + "...") + try: + with open(file, "rb") as f: + dbx.files_upload(f.read(), path, mode=WriteMode('overwrite')) + except ApiError as err: + # This checks for the specific error where a user doesn't have + # enough Dropbox space quota to upload this file + if (err.error.is_path() and + err.error.get_path().reason.is_insufficient_space()): + sys.exit("ERROR: Cannot deploy; insufficient space.") + elif err.user_message_text: + print(err.user_message_text) + sys.exit() + else: + print(err) + sys.exit() + print("Successfully uploaded") + + +def parse_args(args=None): + parser = argparse.ArgumentParser(prog='app') + cmds = parser.add_subparsers(help='commands') + + def cmd(name, **kw): + p = cmds.add_parser(name, **kw) + p.set_defaults(cmd=name) + p.arg = lambda *a, **kw: p.add_argument(*a, **kw) and p + p.exe = lambda f: p.set_defaults(exe=f) and p + + # global options + # p.arg('-s', '--settings', help='application settings') + return p + + cmd('auth', help='Authorize application') \ + .exe(lambda _: ( + run_auth() + )) + + cmd('pack', help='Compress folder') \ + .arg('source', type=str, help='Path to folder or file') \ + .arg('destination', type=str, help='Path to resulting zip archive') \ + .exe(lambda a: ( + run_pack(a.source, a.destination) + )) + + cmd('upload', help='Upload file with override') \ + .arg('refresh_token', type=str, help='Refresh token') \ + .arg('file', type=str, help='Path to file') \ + .arg('path', type=str, help='Path on disk') \ + .exe(lambda a: ( + run_upload(a.refresh_token, a.file, a.path) + )) + + args = parser.parse_args(args) + if not hasattr(args, 'exe'): + parser.print_usage() + else: + args.exe(args) + + +if __name__ == '__main__': + parse_args()