Created
February 10, 2015 17:09
-
-
Save iconara/a2f818c785a22cbd341d to your computer and use it in GitHub Desktop.
Jara without Puck
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
#!/bin/bash | |
if [[ ! -d .git ]]; then | |
echo 'You must run this command from the root of the repository' 1>&2 | |
exit 1 | |
fi | |
environment=${1:-staging} | |
name=$(basename $PWD | tr - _) | |
if [[ $environment = 'production' ]]; then | |
branch='master' | |
else | |
branch=$environment | |
fi | |
date_stamp=$(date +"%Y%m%d%H%M%S") | |
commit_sha=$(git rev-parse $branch | cut -b 1-8) | |
remote_sha=$(git rev-parse origin/$branch) | |
if [[ $commit_sha != $remote_sha ]]; then | |
echo "$branch and origin/$branch are not in sync, did you forget to push?" 1>&2 | |
exit 1 | |
fi | |
artifact_name="$name-$environment-$date_stamp-$commit_sha.tgz" | |
local_path=build/$environment/$artifact_name | |
mkdir -p $(dirname $local_path) | |
git archive --format=tar $commit_sha | gzip > $local_path | |
existing=$(aws s3 ls s3://burt-artifacts/$environment/$name/ | grep $commit_sha) | |
if [[ -z $existing ]]; then | |
aws s3 cp $local_path s3://burt-artifacts/$environment/$name/$(basename $local_path) | |
else | |
existing=$(echo $existing | cut -d' ' -f 4) | |
echo "An artifact for $commit_sha already exists: s3://burt-artifacts/$environment/$name/$existing" 1>&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment