Python scripts and YAML config samples to make deployment to Bintray from Travis CI and AppVeyor easier.
Last active
April 4, 2018 04:02
-
-
Save mbdevpl/cdbc3dab3ae1941870dcaa5bb1b358bc to your computer and use it in GitHub Desktop.
Bintray deployment for Travis CI and AppVeyor
This file contains hidden or 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
after_test: | |
- pip install version_query | |
- for /f %%i in ('python -m version_query -p .') do set VERSION=%%i | |
- set PLATFORM=windows-something-something | |
- wget https://gist.githubusercontent.com/mbdevpl/cdbc3dab3ae1941870dcaa5bb1b358bc/raw/appveyor_bintray_packager.py | |
- python appveyor_bintray_packager.py %VERSION% %PLATFORM% pattern1 pattern2 pattern3 | |
artifacts: | |
- path: '*-bintray.zip' | |
deploy: | |
- provider: BinTray | |
username: $(APPVEYOR_ACCOUNT_NAME) | |
api_key: | |
secure: cMLbWadS24XyCD5RU3XM+2GrgqtTfoBgKwkQXyDyVa/3QOF1rXheHki+BRXP5tLo | |
subject: $(APPVEYOR_ACCOUNT_NAME) | |
repo: pkgs | |
package: $(APPVEYOR_PROJECT_NAME) | |
version: $(VERSION) | |
publish: true | |
override: true | |
explode: true | |
artifact: /.*-bintray\.zip/ |
This file contains hidden or 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
#!/usr/bin/env python3 | |
import os | |
import pathlib | |
import sys | |
import zipfile | |
def prepare_bintray_archive(default_version, platform, *artifact_patterns): | |
"""Generate the Bintray archive for AppVeyor deployment.""" | |
tag = os.environ.get('APPVEYOR_REPO_TAG_NAME', None) | |
if tag: | |
version = tag[1:] if tag.startswith('v') else tag | |
elif '+' in default_version: | |
version = default_version | |
else: | |
version = '{}+{}'.format(default_version, os.environ['APPVEYOR_REPO_COMMIT'][:8]) | |
package = os.environ['APPVEYOR_PROJECT_NAME'] | |
zip_path = '{}-v{}-{}-bintray.zip'.format(package, version, platform) | |
archive_dir = pathlib.Path('{}-v{}'.format(package, version), platform) | |
with zipfile.ZipFile(zip_path, 'w' if sys.version_info < (3, 5) else 'x') as zip_file: | |
for artifact_pattern in artifact_patterns: | |
for pth in pathlib.Path('.').glob(artifact_pattern): | |
if pth.is_file(): | |
zip_file.write(str(pth), str(archive_dir.joinpath(pth.name))) | |
if __name__ == '__main__': | |
prepare_bintray_archive(*sys.argv[1:]) |
This file contains hidden or 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
before_deploy: | |
- pip3 install -U --user version_query || pip3 install -U version_query | |
- wget https://gist.githubusercontent.com/mbdevpl/cdbc3dab3ae1941870dcaa5bb1b358bc/raw/travis_bintray_descriptor_gen.py | |
- python3 travis_bintray_descriptor_gen.py "$(python3 -m version_query -p .)" "platform" "pattern1" "pattern2" "pattern3" | |
- cat ".bintray.json" | |
deploy: | |
- provider: bintray | |
file: ".bintray.json" | |
user: "bintray_username" | |
key: | |
secure: "blahblah" | |
on: | |
all_branches: true | |
skip_cleanup: true |
This file contains hidden or 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
#!/usr/bin/env python3 | |
import json | |
import os | |
import pathlib | |
import sys | |
def generate_bintray_descriptor(default_version, platform, *artifact_patterns): | |
"""Generate the Bintray descriptor file for Travis CI deployment.""" | |
tag = os.environ.get('TRAVIS_TAG', None) | |
if tag: | |
version = tag[1:] if tag.startswith('v') else tag | |
elif '+' in default_version: | |
version = default_version | |
else: | |
version = '{}+{}'.format(default_version, os.environ['TRAVIS_COMMIT'][:8]) | |
subject, _, package = os.environ['TRAVIS_REPO_SLUG'].partition('/') | |
upload_path = pathlib.Path('{}-v{}'.format(package, version), platform) | |
files = [] | |
for artifact_pattern in artifact_patterns: | |
files += [ | |
{'includePattern': str(pth), 'uploadPattern': str(upload_path.joinpath(pth.name))} | |
for pth in pathlib.Path('.').glob(artifact_pattern) if pth.is_file()] | |
data = { | |
'package': {'subject': subject, 'repo': 'pkgs', 'name': package}, | |
'version': { | |
'name': version, 'desc': '', 'released': '', | |
'vcs_tag': tag if tag else os.environ['TRAVIS_COMMIT'], | |
'attributes': [], 'gpgSign': False}, | |
'files': files, | |
'publish': True} | |
with open('.bintray.json', 'w') as desc_file: | |
json.dump(data, desc_file, indent='\t') | |
if __name__ == '__main__': | |
generate_bintray_descriptor(*sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment