2018-12-13 16:09:59 +03:00
|
|
|
#!/bin/bash
|
2019-12-26 01:59:26 +03:00
|
|
|
set -o pipefail -o errexit
|
2018-12-13 16:09:59 +03:00
|
|
|
|
|
|
|
# Error handling
|
|
|
|
handle_error() {
|
2019-12-26 01:59:26 +03:00
|
|
|
read -n1 -r -p "FAILED: line $1, exit code $2. Press any key to exit..." _
|
2018-12-13 16:09:59 +03:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
trap 'handle_error $LINENO $?' ERR
|
|
|
|
|
|
|
|
# Ask for ref if not provided
|
2019-12-26 01:59:26 +03:00
|
|
|
if [[ -z "$WEB_REF" ]]; then
|
|
|
|
read -rp "Input a git ref (commit hash, branch name, tag name, 'master'): " input
|
|
|
|
WEB_REF="$input"
|
2018-12-13 16:09:59 +03:00
|
|
|
fi
|
|
|
|
|
2018-12-16 17:14:48 +03:00
|
|
|
# Ask if the result will be uploaded to github releases
|
|
|
|
if [[ -z $UPLOAD_VAULT ]]; then
|
2019-12-26 01:59:26 +03:00
|
|
|
read -rp "Upload the result to GitHub Releases? (y/n): " input
|
|
|
|
UPLOAD_VAULT="$input"
|
2018-12-16 17:14:48 +03:00
|
|
|
fi
|
|
|
|
|
2018-12-13 16:09:59 +03:00
|
|
|
# If a patch was not provided, try to choose one
|
|
|
|
if [[ -z $PATCH_NAME ]]; then
|
|
|
|
# If a patch with the same name as the ref exists, use it
|
2019-12-26 01:59:26 +03:00
|
|
|
if [ -f "patches/$WEB_REF.patch" ]; then
|
2018-12-13 16:09:59 +03:00
|
|
|
echo "Patch file found, using that"
|
2019-12-26 01:59:26 +03:00
|
|
|
PATCH_NAME="$WEB_REF.patch"
|
2018-12-13 16:09:59 +03:00
|
|
|
else
|
|
|
|
echo "Patch file not found, using latest"
|
|
|
|
# If not, use the latest one
|
2019-12-26 01:59:26 +03:00
|
|
|
PATCH_NAME="$(find patches -printf "%f\\n" | sort -V | tail -n1)"
|
2018-12-13 16:09:59 +03:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-12-26 01:59:26 +03:00
|
|
|
echo "Building git ref: $WEB_REF"
|
|
|
|
echo "Using patch: $PATCH_NAME"
|
2018-12-13 16:09:59 +03:00
|
|
|
|
2018-12-16 17:14:48 +03:00
|
|
|
VAULT_FOLDER=web-vault
|
|
|
|
OUTPUT_FOLDER=builds
|
2019-12-26 01:59:26 +03:00
|
|
|
OUTPUT_NAME="$OUTPUT_FOLDER/bw_web_$WEB_REF.tar.gz"
|
|
|
|
OUTPUT_MSG="$OUTPUT_NAME.text"
|
|
|
|
|
|
|
|
mkdir -p "$OUTPUT_FOLDER"
|
2018-12-16 17:14:48 +03:00
|
|
|
|
2018-12-13 16:09:59 +03:00
|
|
|
# If this is the first time, clone the project
|
2019-12-26 01:59:26 +03:00
|
|
|
if [ ! -d "$VAULT_FOLDER" ]; then
|
|
|
|
git clone --recursive https://github.com/bitwarden/web.git "$VAULT_FOLDER"
|
2018-12-13 16:09:59 +03:00
|
|
|
fi
|
|
|
|
|
2018-12-16 17:14:48 +03:00
|
|
|
cd $VAULT_FOLDER
|
2018-12-13 16:09:59 +03:00
|
|
|
|
|
|
|
# Clean
|
2019-12-26 01:59:26 +03:00
|
|
|
git checkout -f
|
2018-12-13 16:09:59 +03:00
|
|
|
|
|
|
|
# Update branch
|
|
|
|
git fetch --tags
|
|
|
|
git pull origin master
|
|
|
|
|
|
|
|
# Checkput the branch we want
|
2019-12-26 01:59:26 +03:00
|
|
|
git checkout "$WEB_REF"
|
|
|
|
git submodule update --recursive --init
|
2018-12-13 16:09:59 +03:00
|
|
|
|
|
|
|
## How to create patches
|
2019-04-03 16:44:07 +03:00
|
|
|
# git --no-pager diff --no-color --minimal > changes.patch
|
2018-12-13 16:09:59 +03:00
|
|
|
## How to apply patches
|
|
|
|
# git apply changes.patch
|
|
|
|
|
2019-12-26 01:59:26 +03:00
|
|
|
git apply "../patches/$PATCH_NAME"
|
2018-12-13 16:09:59 +03:00
|
|
|
|
|
|
|
# Build
|
|
|
|
npm install
|
|
|
|
npm run dist
|
|
|
|
|
|
|
|
# Delete debugging map files, optional
|
2019-02-27 19:24:25 +03:00
|
|
|
#find build -name "*.map" -delete
|
2018-12-13 16:09:59 +03:00
|
|
|
|
|
|
|
# Prepare the final archives
|
2020-02-22 17:25:07 +03:00
|
|
|
mv build web-vault
|
|
|
|
tar -czvf "../$OUTPUT_NAME" web-vault --owner=0 --group=0
|
2018-12-16 17:14:48 +03:00
|
|
|
|
2020-02-20 13:17:23 +03:00
|
|
|
cd ..
|
2018-12-16 17:14:48 +03:00
|
|
|
|
|
|
|
if [[ $UPLOAD_VAULT =~ ^[Yy]$ ]]
|
|
|
|
then
|
2019-12-26 01:59:26 +03:00
|
|
|
sed "s/<VERSION>/$WEB_REF/g" release_template.md > "$OUTPUT_MSG"
|
2018-12-16 17:14:48 +03:00
|
|
|
# Install from here: https://hub.github.com/
|
2019-12-26 01:59:26 +03:00
|
|
|
hub release create -o -a "$OUTPUT_NAME" -F "$OUTPUT_MSG $WEB_REF"
|
2018-12-16 17:14:48 +03:00
|
|
|
fi
|