From 8e074518dc6f14e5dd1e6b38c6260d551d628f4a Mon Sep 17 00:00:00 2001 From: Gregg Anderson Date: Mon, 29 Apr 2019 11:30:10 -0600 Subject: [PATCH 1/2] chore(cdn_publish.sh): only publish to CDN for gravit-ui-web changes ISSUES CLOSED: #235 --- .gitignore | 3 +++ scripts/cdn_publish.sh | 46 ++++++++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 226aac69..08a9644c 100644 --- a/.gitignore +++ b/.gitignore @@ -85,3 +85,6 @@ typings/ # DynamoDB Local files .dynamodb/ + +# Mac system files +.DS_Store diff --git a/scripts/cdn_publish.sh b/scripts/cdn_publish.sh index 9edeb2c7..96f3a053 100755 --- a/scripts/cdn_publish.sh +++ b/scripts/cdn_publish.sh @@ -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"] +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*'` +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+="
  • `expr $thisVersion : '.*\(v[0-9].*\)'`
  • " -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+="
  • `expr $thisVersion : '.*\(v[0-9].*\)'`
  • " + 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 \ No newline at end of file From e41bb361ba1922e03548badbeba631600520bcb3 Mon Sep 17 00:00:00 2001 From: Gregg Anderson Date: Tue, 30 Apr 2019 14:38:29 -0600 Subject: [PATCH 2/2] chore(cdn_publish.sh): make requested pull request changes --- .gitignore | 3 --- scripts/cdn_publish.sh | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 08a9644c..226aac69 100644 --- a/.gitignore +++ b/.gitignore @@ -85,6 +85,3 @@ typings/ # DynamoDB Local files .dynamodb/ - -# Mac system files -.DS_Store diff --git a/scripts/cdn_publish.sh b/scripts/cdn_publish.sh index 96f3a053..b0719808 100755 --- a/scripts/cdn_publish.sh +++ b/scripts/cdn_publish.sh @@ -2,10 +2,10 @@ cdnGravityDir="gravity-ui-web" cdnDir="cdn-dist" -if [ ! -z "$TRAVIS_COMMIT_RANGE"] +if [ ! -z "$TRAVIS_COMMIT_RANGE" ] 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*'` + cdnChanges=`git diff --pretty="format:" --name-only ${TRAVIS_COMMIT_RANGE/.../..} | grep -E '^packages/gravity-ui-web/*'` fi if [ ! -z "$cdnChanges" ]