|
| 1 | + |
| 2 | +import os |
| 3 | +import subprocess |
| 4 | + |
| 5 | +travis_secure = os.environ['TRAVIS_SECURE_ENV_VARS'] |
| 6 | +PR = os.environ['TRAVIS_PULL_REQUEST'] |
| 7 | +is_PR = ( PR != 'false' ) |
| 8 | + |
| 9 | +# If this is a PR we use the source branch name, and last commit message |
| 10 | +if is_PR: |
| 11 | + print('Fetching PR information') |
| 12 | + branch = os.environ['TRAVIS_PULL_REQUEST_BRANCH'] |
| 13 | + |
| 14 | + import requests |
| 15 | + import json |
| 16 | + r = requests.get('https://api.github.com/repos/scenerygraphics/sciview/pulls/%d/commits' % int(PR)) |
| 17 | + |
| 18 | + if r.ok: |
| 19 | + commits = json.loads(r.text or r.content) |
| 20 | + commit_message = commits[-1]['commit']['message'] |
| 21 | + print('Commit message: %s' % commit_message) |
| 22 | +else: |
| 23 | + branch = os.environ['TRAVIS_BRANCH'] |
| 24 | + commit_message = os.environ['TRAVIS_COMMIT_MESSAGE'] |
| 25 | + |
| 26 | +release_properties_exists = os.path.exists('release.properties') |
| 27 | + |
| 28 | +print('') |
| 29 | +print('') |
| 30 | +print('') |
| 31 | +print('Repo: %s' % os.environ['TRAVIS_REPO_SLUG']) |
| 32 | +print('Branch: %s' % branch) |
| 33 | +print('Release?: %s' % str(release_properties_exists)) |
| 34 | +print('Is Pull Request?: %s' % is_PR) |
| 35 | +print('Commit: %s' % commit_message) |
| 36 | + |
| 37 | +# Perform main build |
| 38 | +print('Starting build') |
| 39 | +# we now have our own version of travis-build.sh |
| 40 | +#subprocess.call(['curl', '-fsLO', 'https://raw.githubusercontent.com/scijava/scijava-scripts/master/travis-build.sh']) |
| 41 | +build_var1 = os.environ['encrypted_eb7aa63bf7ac_key'] |
| 42 | +build_var2 = os.environ['encrypted_eb7aa63bf7ac_iv'] |
| 43 | +subprocess.call(['sh', 'travis-build.sh', build_var1, build_var2]) |
| 44 | + |
| 45 | +# Setup conda environment |
| 46 | +def build_conda(): |
| 47 | + from pathlib import Path |
| 48 | + home = str(Path.home()) |
| 49 | + |
| 50 | + print('------ BUILD CONDA -----') |
| 51 | + |
| 52 | + script_name = 'Miniconda3-latest-Linux-x86_64.sh' |
| 53 | + miniconda_dir = '%s/miniconda' % home |
| 54 | + subprocess.call(['curl', '-fsLO', 'https://repo.continuum.io/miniconda/%s' % script_name]) |
| 55 | + subprocess.call(['bash', script_name, '-b', '-p', miniconda_dir]) |
| 56 | + subprocess.call(['source', '%s/etc/profile.d/conda.sh' % miniconda_dir]) |
| 57 | + subprocess.call(['hash', '-r']) |
| 58 | + subprocess.call(['conda', 'config', '--set', 'always_yes', 'yes', '--set', 'changeps1', 'no']) |
| 59 | + subprocess.call(['conda', 'update', '-q', 'conda']) |
| 60 | + # Useful for debugging any issues with conda |
| 61 | + subprocess.call(['conda', 'info', '-a']) |
| 62 | + |
| 63 | + # Replace dep1 dep2 ... with your dependencies |
| 64 | + subprocess.call(['conda', 'env', 'create', '-f', 'environment.yml']) |
| 65 | + subprocess.call(['conda', 'activate', 'sciview']) |
| 66 | +build_conda() |
| 67 | + |
| 68 | +def package_conda(): |
| 69 | + subprocess.call(['sh', 'populate_fiji.sh']) |
| 70 | + subprocess.call(['pyinstaller', '--onefile', '--add-data', 'Fiji.app/jars:jars', 'src/main/python/sciview.py']) |
| 71 | + |
| 72 | + platform = subprocess.check_output(['uname', '-s']) |
| 73 | + arch = subprocess.check_output(['uname', '-m']) |
| 74 | + |
| 75 | + if platform == 'Linux' and arch == 'x86_64': |
| 76 | + exe_name = 'sciview-linux64' |
| 77 | + elif platform == 'Linux': |
| 78 | + exe_name = 'sciview-linux32' |
| 79 | + elif platform == 'Darwin': |
| 80 | + exe_name = 'sciview-macos' |
| 81 | + elif platform.startswith('MING'): |
| 82 | + exe_name = 'sciview-win32' |
| 83 | + elif platform.startswith('MSYS_NT'): |
| 84 | + exe_name = 'sciview-win32' |
| 85 | + |
| 86 | + subprocess.call(['mv', 'dist/sciview', exe_name]) |
| 87 | +package_conda() |
| 88 | + |
| 89 | +# Update sites |
| 90 | +print('') |
| 91 | +print('') |
| 92 | +print('') |
| 93 | +print('Checking if upload to update site needed') |
| 94 | + |
| 95 | +## Unstable |
| 96 | +## Commit message trigger requires one of these conditions: |
| 97 | +## - message begin with SV_IJ_DEPLOY_UNSTABLE |
| 98 | +## - push/merge to master |
| 99 | + |
| 100 | +if ( branch == 'master' and not is_PR and travis_secure ) or \ |
| 101 | + ( '[SV_IJ_DEPLOY_UNSTABLE]' in commit_message ): |
| 102 | + |
| 103 | + print('Upload to SciView-Unstable') |
| 104 | + subprocess.call(['sh', 'sciview_deploy_unstable.sh']) |
| 105 | + |
| 106 | +## Primary |
| 107 | +## Commit message trigger requires one of these conditions: |
| 108 | +## - message begin with SV_IJ_DEPLOY_PRIMARY |
| 109 | +## - release |
| 110 | + |
| 111 | +# TODO: check branch == <pom-release-version> |
| 112 | +if ( not is_PR and travis_secure and release_properties_exists ) or \ |
| 113 | + ( '[SV_IJ_DEPLOY_PRIMARY]' in commit_message ): |
| 114 | + print('Upload to SciView') |
| 115 | + subprocess.call(['sh', 'sciview_deploy.sh']) |
| 116 | + |
0 commit comments