2021-07-25 18:53:14 +03:00
|
|
|
#!/usr/bin/env 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
|
2020-03-01 02:34:55 +03:00
|
|
|
if [[ -z "$VAULT_VERSION" ]]; then
|
2019-12-26 01:59:26 +03:00
|
|
|
read -rp "Input a git ref (commit hash, branch name, tag name, 'master'): " input
|
2020-03-01 02:34:55 +03:00
|
|
|
VAULT_VERSION="$input"
|
2018-12-13 16:09:59 +03:00
|
|
|
fi
|
|
|
|
|
2018-12-16 17:14:48 +03:00
|
|
|
VAULT_FOLDER=web-vault
|
|
|
|
OUTPUT_FOLDER=builds
|
2020-03-01 02:34:55 +03:00
|
|
|
OUTPUT_NAME="$OUTPUT_FOLDER/bw_web_$VAULT_VERSION.tar.gz"
|
2019-12-26 01:59:26 +03:00
|
|
|
|
|
|
|
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
|
2021-07-25 18:53:14 +03:00
|
|
|
git clone 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
|
2021-07-25 18:53:14 +03:00
|
|
|
git fetch --tags --all
|
2018-12-13 16:09:59 +03:00
|
|
|
git pull origin master
|
|
|
|
|
|
|
|
# Checkput the branch we want
|
2020-03-01 02:34:55 +03:00
|
|
|
git checkout "$VAULT_VERSION"
|
2019-12-26 01:59:26 +03:00
|
|
|
git submodule update --recursive --init
|
2018-12-13 16:09:59 +03:00
|
|
|
|
|
|
|
## How to create patches
|
2021-03-14 19:56:01 +03:00
|
|
|
# git --no-pager diff --submodule=diff --no-color --minimal > changes.patch
|
2018-12-13 16:09:59 +03:00
|
|
|
## How to apply patches
|
|
|
|
# git apply changes.patch
|
2020-03-01 02:34:55 +03:00
|
|
|
. ../apply_patches.sh
|
2018-12-13 16:09:59 +03:00
|
|
|
|
|
|
|
# Build
|
2022-02-23 16:20:20 +03:00
|
|
|
npm ci
|
|
|
|
# npm audit fix || true
|
2021-10-27 23:31:31 +03:00
|
|
|
npm run dist:oss:selfhost
|
2018-12-13 16:09:59 +03:00
|
|
|
|
|
|
|
# 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
|
|
|
|
2021-04-04 16:58:06 +03:00
|
|
|
# Create bwrs-version.json with the latest tag from the remote repo.
|
|
|
|
printf '{"version":"%s"}' \
|
2021-07-25 18:53:14 +03:00
|
|
|
"$(git -c 'versionsort.suffix=-' ls-remote --tags --sort='v:refname' https://github.com/dani-garcia/bw_web_builds.git 'v*' | tail -n1 | sed -E 's#.*?refs/tags/v##')" \
|
2022-01-01 16:03:08 +03:00
|
|
|
> build/vw-version.json
|
2021-04-04 16:58:06 +03:00
|
|
|
|
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
|
2021-07-25 18:53:14 +03:00
|
|
|
mv web-vault build
|