2019-12-02 12:17:23 +00:00
|
|
|
#!/bin/bash
|
2023-11-09 10:56:14 +00:00
|
|
|
set -eEu
|
2019-12-02 12:17:23 +00:00
|
|
|
|
2020-09-28 13:07:35 +00:00
|
|
|
function upload_into_bucket() {
|
|
|
|
bucket=$1
|
|
|
|
|
|
|
|
# stylesheets
|
2021-11-03 11:04:29 +00:00
|
|
|
bin/cdn_upload_batch 'text/css' "$bucket" '.css' \
|
|
|
|
-x '.+(?<!\.css)$' &
|
2020-09-28 13:07:35 +00:00
|
|
|
|
|
|
|
# javascript files
|
2021-11-03 11:04:29 +00:00
|
|
|
bin/cdn_upload_batch 'application/javascript' "$bucket" '.js' \
|
|
|
|
-x '.+(?<!\.js)$' &
|
2020-09-28 13:07:35 +00:00
|
|
|
|
|
|
|
# the rest
|
2021-11-03 11:04:29 +00:00
|
|
|
bin/cdn_upload_batch '-' "$bucket" '-' \
|
|
|
|
-x '.+\.(css|js)$' &
|
2020-09-28 13:07:35 +00:00
|
|
|
|
2021-11-03 11:04:29 +00:00
|
|
|
wait
|
2020-09-28 13:07:35 +00:00
|
|
|
}
|
|
|
|
|
2023-11-09 10:56:14 +00:00
|
|
|
verify_upload_into_bucket() {
|
|
|
|
local bucket
|
|
|
|
local missing_from_bucket
|
|
|
|
bucket=$1
|
|
|
|
printf '\nINFO: Verifying file availability in %s.\n' "$bucket"
|
|
|
|
readarray -t missing_from_bucket < <(
|
|
|
|
comm -13 \
|
|
|
|
<(gsutil ls "${bucket}/public/**" | sed "s@${bucket}/@@" | sort) \
|
|
|
|
<(find /tmp/public /tmp/compressed -type f | sed '
|
|
|
|
# Remove absolute path prefix
|
|
|
|
s@^/tmp/@@;
|
|
|
|
# Undo the compressed/ directory separation that does not exist in the bucket
|
|
|
|
s@^compressed/@@
|
|
|
|
' | sort)
|
|
|
|
)
|
|
|
|
if [[ ${#missing_from_bucket[@]} -eq 0 ]]; then
|
|
|
|
printf 'INFO: Verification successful: all local files have been found in bucket %s.\n' \
|
|
|
|
"$bucket"
|
|
|
|
else
|
|
|
|
printf >&2 'WARN: %d local file(s) not available in bucket %s:\n' \
|
|
|
|
${#missing_from_bucket[@]} "$bucket"
|
|
|
|
printf >&2 ' - %s\n' "${missing_from_bucket[@]}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Upload to staging CDN if branch is either 'main' or 'staging-main'
|
|
|
|
if [[ "$BRANCH_NAME" == "main" ]] || [[ "$BRANCH_NAME" == "staging-main" ]]; then
|
2020-05-22 10:34:57 +00:00
|
|
|
tar --directory=/tmp/ -xf build.tar
|
2020-07-02 15:51:38 +00:00
|
|
|
|
|
|
|
# delete source maps
|
|
|
|
find /tmp/public -name '*.js.map' -delete
|
|
|
|
|
2021-11-03 11:04:29 +00:00
|
|
|
bin/compress_assets
|
|
|
|
|
2023-11-09 10:56:14 +00:00
|
|
|
upload_into_bucket "$CDN_STAG" &&
|
|
|
|
verify_upload_into_bucket "$CDN_STAG" || exit 3
|
2020-05-22 10:34:57 +00:00
|
|
|
# Only upload to production CDN if branch is
|
2023-11-09 10:56:14 +00:00
|
|
|
if [[ "$BRANCH_NAME" == "main" ]]; then
|
|
|
|
upload_into_bucket "$CDN_PROD" &&
|
|
|
|
verify_upload_into_bucket "$CDN_PROD" || exit 3
|
2019-12-02 12:17:23 +00:00
|
|
|
fi
|
|
|
|
fi
|