Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cdn_publish.sh): only publish to CDN for gravit-ui-web changes #242

Merged
merged 2 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,6 @@ typings/

# DynamoDB Local files
.dynamodb/

# Mac system files
.DS_Store
thehammeranderson marked this conversation as resolved.
Show resolved Hide resolved
46 changes: 29 additions & 17 deletions scripts/cdn_publish.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
#!/bin/bash
cdnGravityDir="gravity-ui-web"
cdnDir="cdn-dist"
allVersions=`git tag --list --sort=-committerdate | grep -E '^(gravity-ui-web-)?v[0-9]*.[0-9]*.[0-9]*'`

# First tag in the list will be the latest one, but may be prefixed (e.g. "gravity-ui-web-v1.2.3")
version=`echo $allVersions | cut -d" " -f1`
# be sure we get only the version part and discard any prefix
version=`expr $version : '.*\(v[0-9].*\)'`
if [ ! -z "$TRAVIS_COMMIT_RANGE"]
thehammeranderson marked this conversation as resolved.
Show resolved Hide resolved
then
# TRAVIS_COMMIT_RANGE has a bug that includes commits outside the PR, so fix with known workaround that is future safe
cdnChanges=`git diff --pretty="format:" --name-only ${TRAVIS_COMMIT_RANGE/.../..} | grep -E '^packages/gravity-ui-web/src*'`
thehammeranderson marked this conversation as resolved.
Show resolved Hide resolved
dw-buildit marked this conversation as resolved.
Show resolved Hide resolved
thehammeranderson marked this conversation as resolved.
Show resolved Hide resolved
thehammeranderson marked this conversation as resolved.
Show resolved Hide resolved
fi

mkdir -p ${cdnDir}/${cdnGravityDir}/${version}
if [ ! -z "$cdnChanges" ]
then
allVersions=`git tag --list --sort=-committerdate | grep -E '^(gravity-ui-web-)?v[0-9]*.[0-9]*.[0-9]*'`

cp packages/gravity-ui-web/dist/ui-lib/* ${cdnDir}/${cdnGravityDir}/${version}
# First tag in the list will be the latest one, but may be prefixed (e.g. "gravity-ui-web-v1.2.3")
version=`echo $allVersions | cut -d" " -f1`
# be sure we get only the version part and discard any prefix
version=`expr $version : '.*\(v[0-9].*\)'`

versionList=""
for thisVersion in $allVersions; do
versionList+="<li>`expr $thisVersion : '.*\(v[0-9].*\)'`</li>"
done
mkdir -p ${cdnDir}/${cdnGravityDir}/${version}

file_contents=$(<./cdn-index.template)
echo "${file_contents//\{versionlist\}/$versionList}" > ${cdnDir}/${cdnGravityDir}/index.html
cp packages/gravity-ui-web/dist/ui-lib/* ${cdnDir}/${cdnGravityDir}/${version}

~/.local/bin/aws s3 sync ${cdnDir} s3://${CDN_BUCKET} --region=${PROD_BUCKET_REGION} --exclude "*" --include "*.html" --content-type "text/html; charset=utf-8" --cache-control "max-age=0"
~/.local/bin/aws s3 sync ${cdnDir} s3://${CDN_BUCKET} --region=${PROD_BUCKET_REGION} --exclude "*" --include "*.css" --content-type "text/css; charset=utf-8" --cache-control "max-age=3153600000, immutable"
~/.local/bin/aws s3 sync ${cdnDir} s3://${CDN_BUCKET} --region=${PROD_BUCKET_REGION} --exclude "*" --include "*.js" --content-type "application/javascript; charset=utf-8" --cache-control "max-age=3153600000, immutable"
~/.local/bin/aws s3 sync ${cdnDir} s3://${CDN_BUCKET} --region=${PROD_BUCKET_REGION} --include "*" --exclude "*.js" --exclude "*.html" --exclude "*.css" --exclude ".DS_Store" --cache-control "max-age=3153600000, immutable"
versionList=""
for thisVersion in $allVersions; do
versionList+="<li>`expr $thisVersion : '.*\(v[0-9].*\)'`</li>"
done

file_contents=$(<./cdn-index.template)
echo "${file_contents//\{versionlist\}/$versionList}" > ${cdnDir}/${cdnGravityDir}/index.html

~/.local/bin/aws s3 sync ${cdnDir} s3://${CDN_BUCKET} --region=${PROD_BUCKET_REGION} --exclude "*" --include "*.html" --content-type "text/html; charset=utf-8" --cache-control "max-age=0"
~/.local/bin/aws s3 sync ${cdnDir} s3://${CDN_BUCKET} --region=${PROD_BUCKET_REGION} --exclude "*" --include "*.css" --content-type "text/css; charset=utf-8" --cache-control "max-age=3153600000, immutable"
~/.local/bin/aws s3 sync ${cdnDir} s3://${CDN_BUCKET} --region=${PROD_BUCKET_REGION} --exclude "*" --include "*.js" --content-type "application/javascript; charset=utf-8" --cache-control "max-age=3153600000, immutable"
~/.local/bin/aws s3 sync ${cdnDir} s3://${CDN_BUCKET} --region=${PROD_BUCKET_REGION} --include "*" --exclude "*.js" --exclude "*.html" --exclude "*.css" --exclude ".DS_Store" --cache-control "max-age=3153600000, immutable"
else
echo "No CDN related changes found to publish"
fi