Last active
July 1, 2019 13:46
-
-
Save gmoretti/cf29e785e36053bf04c8897cf1c4942d to your computer and use it in GitHub Desktop.
Deploys to AWS the changed files between the last two tags matching a regex
This file contains 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 | |
# Consider using a alias to this script | |
# alias statics="sh /path/to/script/tag_diff_deploy.sh" | |
set -e | |
echo "This should run inside a GIT repo." | |
echo "Have you tagged last package?" | |
#AWS CLI is required | |
#For credentials it will use the ones in ~/.aws folder (a first login to the bucket would set it ). | |
#If not these parameterscould be used | |
#AWS_ACCESS_KEY_ID= | |
#AWS_SECRET_ACCESS_KEY= | |
STATIC_ROOT_FOLDER="static/" | |
TAG_REGEX="TAG_1.*" | |
S3_BUCKET="aws-static-deploy-test" | |
TAGS=() | |
for i in $( git tag -l --sort=refname "${TAG_REGEX}" | tail -2 ); do | |
TAGS+=( "$i" ) | |
done | |
echo "Checking difference between tags:" | |
echo "${TAGS[0]}" | |
echo "${TAGS[1]}" | |
FILES=() | |
for i in $( git diff ${TAGS[0]} ${TAGS[1]} --name-only | grep ${STATIC_ROOT_FOLDER} ); do | |
FILES+=( "$i" ) | |
done | |
echo "Files to be deployed..." | |
printf '%s\n' "${FILES[@]}" | |
CMDS=() | |
for i in "${FILES[@]}"; do | |
CMDS+=("--include=$i""*") | |
done | |
#echo "${CMDS[@]}" | |
echo "${CMDS[@]}" | xargs aws s3 sync . s3://${S3_BUCKET} --dryrun --delete --exclude "*" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modified from https://www.lambrospetrou.com/articles/aws-s3-sync-git-status/
Thanks @lambrospetrou