playwright/browser_patches/upload.sh

79 lines
2.4 KiB
Bash
Raw Normal View History

2019-11-19 05:18:28 +03:00
#!/bin/bash
set -e
set +x
2019-11-20 03:08:27 +03:00
trap "cd $(pwd -P)" EXIT
2019-11-19 05:18:28 +03:00
cd "$(dirname "$0")"
if [[ ($1 == '--help') || ($1 == '-h') ]]; then
echo "usage: $(basename "$0") [BLOB-PATH] [--check|ZIP-PATH]"
2019-11-19 05:18:28 +03:00
echo
echo "Upload ZIP-PATH to BLOB-PATH in 'builds' container."
2019-11-19 05:18:28 +03:00
echo
2019-11-22 02:25:46 +03:00
echo "--check pass |--check| as a second parameter instead of a zip-path to check for"
2022-02-01 22:09:41 +03:00
echo " existence of BLOB-PATH"
2019-11-22 02:25:46 +03:00
echo
2019-11-19 05:18:28 +03:00
echo "NOTE: \$AZ_ACCOUNT_KEY (azure account name) and \$AZ_ACCOUNT_NAME (azure account name)"
echo "env variables are required to upload builds to CDN."
exit 0
fi
if [[ (-z $AZ_ACCOUNT_KEY) || (-z $AZ_ACCOUNT_NAME) ]]; then
echo "ERROR: Either \$AZ_ACCOUNT_KEY or \$AZ_ACCOUNT_NAME environment variable is missing."
echo " 'Azure Account Name' and 'Azure Account Key' secrets that are required"
echo " to upload builds ot Azure CDN."
exit 1
fi
if [[ $# < 2 ]]; then
echo "not enought arguments!"
echo "try '$(basename "$0") --help' for more information"
exit 1
fi
BLOB_PATH="$1"
ZIP_PATH="$2"
if [[ ("$2" == '--check') ]]; then
EXISTS=$(az storage blob exists -c builds --account-key "$AZ_ACCOUNT_KEY" --account-name "$AZ_ACCOUNT_NAME" -n "$BLOB_PATH" --query "exists")
2019-11-22 02:25:46 +03:00
if [[ $EXISTS == "true" ]]; then
exit 0
else
exit 1
fi
fi
GENERATE_MD5_HASH=$(cat <<EOF
const crypto = require('crypto');
const fs = require('fs');
const buffer = fs.readFileSync(process.argv[1]);
console.log(crypto.createHash('md5').update(buffer).digest('base64'));
EOF
)
MD5_HASH=$(node -e "${GENERATE_MD5_HASH}" "${ZIP_PATH}")
echo "MD5 hash: ${MD5_HASH}"
if ! [[ -f $ZIP_PATH ]]; then
echo "ERROR: ${ZIP_PATH} does not exist"
2019-11-19 05:18:28 +03:00
exit 1
fi
if [[ "${ZIP_PATH}" != *.zip && "${ZIP_PATH}" != *.gz ]]; then
echo "ERROR: ${ZIP_PATH} is not an archive (must have a .zip or .gz extension)"
exit 1
fi
2019-11-23 04:16:47 +03:00
if [[ $(uname) == MINGW* ]]; then
# Convert POSIX path to MSYS
WIN_PATH=$({ cd $(dirname "$ZIP_PATH") && pwd -W; } | sed 's|/|\\|g')
WIN_PATH="${WIN_PATH}\\$(basename "$ZIP_PATH")"
az storage blob upload -c builds --account-key "$AZ_ACCOUNT_KEY" --account-name "$AZ_ACCOUNT_NAME" -f "$WIN_PATH" -n "$BLOB_PATH" --content-md5 "${MD5_HASH}"
2019-11-23 04:16:47 +03:00
else
az storage blob upload -c builds --account-key "$AZ_ACCOUNT_KEY" --account-name "$AZ_ACCOUNT_NAME" -f "$ZIP_PATH" -n "$BLOB_PATH" --content-md5 "${MD5_HASH}"
2019-11-23 04:16:47 +03:00
fi
echo "UPLOAD SUCCESSFUL!"
echo "-- SRC: $ZIP_PATH"
echo "-- SIZE: $(du -h "$ZIP_PATH" | awk '{print $1}')"
echo "-- DST: $BLOB_PATH"
2019-11-19 05:18:28 +03:00