From b0a9c94e83cb7ede90f89729ce29d682dc66ba04 Mon Sep 17 00:00:00 2001 From: "Matthew D. Scholefield" Date: Mon, 13 Nov 2017 15:50:08 -0600 Subject: [PATCH] Add proper argument parser and upload latest to non-changing location --- publish.sh | 70 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/publish.sh b/publish.sh index 38d537a..66fd5dc 100755 --- a/publish.sh +++ b/publish.sh @@ -1,47 +1,83 @@ #!/usr/bin/env bash # Usage: upload_file FILE REMOTE_PATH -upload_file() { - file="$1" - remote_url="s3://$2" +upload_s3() { + file="$1" + remote_url="s3://$2" eval cfg_file="~/.s3cfg.mycroft-artifact-writer" - [ -f "$cfg_file" ] && s3cmd put $1 $remote_url --acl-public -c ~/.s3cfg.mycroft-artifact-writer || echo "Could not find $cfg_file. Skipping upload." + [ -f "$cfg_file" ] && s3cmd put $1 $remote_url --acl-public -c ~/.s3cfg.mycroft-artifact-writer || echo "Could not find $cfg_file. Skipping upload." +} + +# Usage: upload_git FILE GIT_FOLDER +upload_git() { + [ -d 'precise-data' ] || git clone git@github.com:MycroftAI/precise-data.git + cd precise-data + git fetch + git checkout origin/dist + mv ../$1 $2 + git add $2 + git commit --amend --no-edit + git push --force origin HEAD:dist + cd .. } # Usage: find_type stable|unstable find_type() { - [ "$1" = "stable" ] && echo "release" || echo "daily" + [ "$1" = "stable" ] && echo "release" || echo "daily" } # Usage: find_version stable|unstable find_version() { - [ "$1" = "stable" ] && git describe --abbrev=0 || date +%s + [ "$1" = "stable" ] && git describe --abbrev=0 || date +%s } find_arch() { python3 -c 'import platform; print(platform.machine())' } -# Usage: check_args "$@" -check_args() { - if [ $# != 1 ]; then - echo "Usage: $1 stable|unstable" - exit 1 - fi +# Usage: show_usage $0 +show_usage() { + echo "Usage: $1 stable|unstable [git|s3]" + exit 1 +} + +# Usage: parse_args "$@" +parse_args() { + build_type="error" + upload_type="s3" + + while [ $# -gt 0 ]; do + case "$1" in + stable|unstable) + build_type="$1";; + git|s3) + upload_type="$1";; + *) + show_usage + esac + shift + done + [ "$build_type" != "error" ] || show_usage } set -e -check_args "$@" +parse_args "$@" -type="$(find_type $@)" -version="$(find_version $@)" +type="$(find_type $build_type)" +version="$(find_version $build_type)" arch="$(find_arch)" sudo pip3 install pyinstaller pyinstaller -y precise.stream.spec echo $version > latest -upload_file dist/precise-stream bootstrap.mycroft.ai/artifacts/static/$type/$arch/$version/ -upload_file latest bootstrap.mycroft.ai/artifacts/static/$type/$arch/ + +if [ "$upload_type" = "git" ]; then + upload_git dist/precise-stream $arch/ +else + upload_s3 dist/precise-stream bootstrap.mycroft.ai/artifacts/static/$type/$arch/$version/ + upload_s3 dist/precise-stream bootstrap.mycroft.ai/artifacts/static/$type/$arch/ # Replace latest version + upload_s3 latest bootstrap.mycroft.ai/artifacts/static/$type/$arch/ +fi