Add proper argument parser and upload latest to non-changing location

pull/1/head
Matthew D. Scholefield 2017-11-13 15:50:08 -06:00
parent fe1a90db1c
commit b0a9c94e83
1 changed files with 53 additions and 17 deletions

View File

@ -1,13 +1,26 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Usage: upload_file FILE REMOTE_PATH # Usage: upload_file FILE REMOTE_PATH
upload_file() { upload_s3() {
file="$1" file="$1"
remote_url="s3://$2" remote_url="s3://$2"
eval cfg_file="~/.s3cfg.mycroft-artifact-writer" 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 # Usage: find_type stable|unstable
find_type() { find_type() {
[ "$1" = "stable" ] && echo "release" || echo "daily" [ "$1" = "stable" ] && echo "release" || echo "daily"
@ -22,26 +35,49 @@ find_arch() {
python3 -c 'import platform; print(platform.machine())' python3 -c 'import platform; print(platform.machine())'
} }
# Usage: check_args "$@" # Usage: show_usage $0
check_args() { show_usage() {
if [ $# != 1 ]; then echo "Usage: $1 stable|unstable [git|s3]"
echo "Usage: $1 stable|unstable"
exit 1 exit 1
fi }
# 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 set -e
check_args "$@" parse_args "$@"
type="$(find_type $@)" type="$(find_type $build_type)"
version="$(find_version $@)" version="$(find_version $build_type)"
arch="$(find_arch)" arch="$(find_arch)"
sudo pip3 install pyinstaller sudo pip3 install pyinstaller
pyinstaller -y precise.stream.spec pyinstaller -y precise.stream.spec
echo $version > latest 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