2018-05-14 01:50:11 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# required environment variables:
|
|
|
|
# AWS_ACCESS_KEY_ID
|
|
|
|
# AWS_SECRET_ACCESS_KEY
|
|
|
|
# AWS_DEFAULT_REGION
|
2018-05-25 16:43:04 +02:00
|
|
|
AWS_S3_BUCKET="matthiaskretschmann.com"
|
|
|
|
AWS_S3_BUCKET_BETA="beta.matthiaskretschmann.com"
|
2018-12-02 00:10:05 +01:00
|
|
|
SITEMAP_URL="https%3A%2F%2Fmatthiaskretschmann.com%2Fsitemap.xml"
|
2018-05-14 01:50:11 +02:00
|
|
|
#
|
|
|
|
set -e;
|
|
|
|
|
2018-05-25 16:43:04 +02:00
|
|
|
function s3sync {
|
2018-12-02 00:10:05 +01:00
|
|
|
aws s3 sync ./public s3://"$1" \
|
2019-10-06 16:58:15 +02:00
|
|
|
--include "*" \
|
|
|
|
--exclude "*.html" \
|
|
|
|
--exclude "sw.js" \
|
|
|
|
--exclude "*page-data.json" \
|
2019-11-09 20:26:29 +01:00
|
|
|
--exclude "*app-data.json" \
|
2019-10-06 16:58:15 +02:00
|
|
|
--exclude "chunk-map.json" \
|
|
|
|
--exclude "sitemap.xml" \
|
|
|
|
--exclude ".iconstats.json" \
|
|
|
|
--exclude "humans.txt" \
|
|
|
|
--exclude "robots.txt" \
|
2018-12-02 00:10:05 +01:00
|
|
|
--cache-control public,max-age=31536000,immutable \
|
|
|
|
--delete \
|
2018-12-07 10:31:03 +01:00
|
|
|
--acl public-read
|
2018-05-25 16:43:04 +02:00
|
|
|
|
2018-12-02 00:10:05 +01:00
|
|
|
aws s3 sync ./public s3://"$1" \
|
|
|
|
--exclude "*" \
|
|
|
|
--include "*.html" \
|
|
|
|
--include "sw.js" \
|
2019-10-06 16:58:15 +02:00
|
|
|
--include "*page-data.json" \
|
2019-11-09 20:26:29 +01:00
|
|
|
--include "*app-data.json" \
|
2018-12-07 13:36:03 +01:00
|
|
|
--include "chunk-map.json" \
|
|
|
|
--include "sitemap.xml" \
|
2018-12-07 14:05:36 +01:00
|
|
|
--include ".iconstats.json" \
|
|
|
|
--include "humans.txt" \
|
|
|
|
--include "robots.txt" \
|
2018-12-02 00:10:05 +01:00
|
|
|
--cache-control public,max-age=0,must-revalidate \
|
|
|
|
--delete \
|
2018-12-07 10:31:03 +01:00
|
|
|
--acl public-read
|
2018-05-25 16:43:04 +02:00
|
|
|
}
|
|
|
|
|
2019-03-30 13:19:02 +01:00
|
|
|
# purge full Cloudflare cache
|
|
|
|
# https://api.cloudflare.com/#zone-purge-all-files
|
|
|
|
function purge {
|
|
|
|
curl -X POST "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE/purge_cache" \
|
|
|
|
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
|
|
|
|
-H "X-Auth-Key: $CLOUDFLARE_KEY" \
|
|
|
|
-H "Content-Type: application/json" \
|
|
|
|
--data '{"purge_everything":true}'
|
|
|
|
}
|
|
|
|
|
|
|
|
# ping search engines
|
|
|
|
# returns: HTTP_STATUSCODE URL
|
|
|
|
function ping {
|
|
|
|
curl -sL -w "%{http_code} %{url_effective}\\n" \
|
|
|
|
"http://www.google.com/webmasters/tools/ping?sitemap=$SITEMAP_URL" -o /dev/null \
|
|
|
|
"http://www.bing.com/webmaster/ping.aspx?siteMap=$SITEMAP_URL" -o /dev/null
|
|
|
|
}
|
|
|
|
|
2018-05-14 01:50:11 +02:00
|
|
|
##
|
2020-07-02 19:32:37 +02:00
|
|
|
## check for pull request against main
|
2018-05-14 01:50:11 +02:00
|
|
|
##
|
2019-11-26 01:45:27 +01:00
|
|
|
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
|
2018-05-14 01:50:11 +02:00
|
|
|
|
2018-05-25 16:43:04 +02:00
|
|
|
s3sync $AWS_S3_BUCKET_BETA
|
2018-05-14 01:50:11 +02:00
|
|
|
|
|
|
|
##
|
2020-07-02 19:32:37 +02:00
|
|
|
## check for main push which is no pull request
|
2018-05-14 01:50:11 +02:00
|
|
|
##
|
2020-07-02 19:32:37 +02:00
|
|
|
elif [ "$GITHUB_REF" == "refs/heads/main" ]; then
|
2018-05-14 01:50:11 +02:00
|
|
|
|
2018-05-25 16:43:04 +02:00
|
|
|
s3sync $AWS_S3_BUCKET
|
2018-05-14 01:50:11 +02:00
|
|
|
|
2019-11-26 02:46:32 +01:00
|
|
|
# purge
|
2019-03-30 13:19:02 +01:00
|
|
|
|
|
|
|
ping
|
2018-12-02 00:10:05 +01:00
|
|
|
|
2018-05-14 01:50:11 +02:00
|
|
|
echo "---------------------------------------------"
|
|
|
|
echo " ✓ done deployment "
|
|
|
|
echo "---------------------------------------------"
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
echo "---------------------------------------------"
|
|
|
|
echo " nothing to deploy "
|
|
|
|
echo "---------------------------------------------"
|
|
|
|
|
|
|
|
fi
|