#!/usr/bin/env bash RED='\033[0;31m' NOCOLOR='\033[0m' function print_error { echo -e "${RED}$1${NOCOLOR}" } function check_current_directory_is_root { if [ ! -f README.md ]; then print_error "You seems to be in the wrong directory" print_error "Execute this script from the root of lesspass with ./bin/${0##*/}" exit 1 fi } function check_repository_is_clean { git remote update git add . git status git diff-index --quiet HEAD if [ $? == 1 ] then print_error "Git repository not clean. Aborting." exit 1 fi if [ $(git rev-parse HEAD) != $(git rev-parse @{u}) ] then print_error "Git branch diverged. Aborting." exit 1 fi } function check_branch_is_master { BRANCH_NAME=$(git branch | grep \* | cut -d ' ' -f2) if [ $BRANCH_NAME != "master" ] then print_error "Current branch is not master. Aborting." exit 1 fi } function check_bump_type_is_defined { bump_type="${1}" if [ "${bump_type}" != "major" ] && [ "${bump_type}" != "minor" ] && [ "${bump_type}" != "patch" ] then print_error "Error: No bump type specified (major, minor, patch). Aborting." exit 1 fi } set +o errexit check_branch_is_master bump_type="${1:-}" check_bump_type_is_defined ${bump_type} check_current_directory_is_root check_repository_is_clean set -o errexit set -o pipefail set -o nounset function increment_version { IFS='.' read -a versions <<< "${1}" major=${versions[0]} minor=${versions[1]} patch=${versions[2]} case "${2}" in "major") major=$((major + 1)) minor=0 patch=0 ;; "minor") minor=$((minor + 1)) patch=0 ;; "patch") patch=$((patch + 1)) ;; esac new_version="$major.$minor.$patch" echo ${new_version} } function replace_versions_in_files { sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" package.json sed -i "s/__version__ = \"${1}\"/__version__ = \"${2}\"/g" cli/lesspass/version.py sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" mobile/package.json sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" mobile/src/version.json sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass/package.json sed -i "s/\"lesspass-entropy\": \"${1}\"/\"lesspass-entropy\": \"${2}\"/g" packages/lesspass/package.json sed -i "s/\"lesspass-fingerprint\": \"${1}\"/\"lesspass-fingerprint\": \"${2}\"/g" packages/lesspass/package.json sed -i "s/\"lesspass-render-password\": \"${1}\"/\"lesspass-render-password\": \"${2}\"/g" packages/lesspass/package.json sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-crypto/package.json sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-entropy/package.json sed -i "s/\"lesspass-crypto\": \"${1}\"/\"lesspass-crypto\": \"${2}\"/g" packages/lesspass-entropy/package.json sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-fingerprint/package.json sed -i "s/\"lesspass-crypto\": \"${1}\"/\"lesspass-crypto\": \"${2}\"/g" packages/lesspass-fingerprint/package.json sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-pure/package.json sed -i "s/\"lesspass\": \"${1}\"/\"lesspass\": \"${2}\"/g" packages/lesspass-pure/package.json sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-render-password/package.json sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-site/package.json sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-web-extension/package.json sed -i "s/\"lesspass-pure\": \"${1}\"/\"lesspass-pure\": \"${2}\"/g" packages/lesspass-web-extension/package.json sed -i "s/\"version\": \"${1}\"/\"version\": \"${2}\"/g" packages/lesspass-web-extension/extension/manifest.json } function build_web_extensions { yarn install yarn workspace lesspass-pure run build rm -rf packages/lesspass-web-extension/extension/dist mkdir packages/lesspass-web-extension/extension/dist cp -r packages/lesspass-pure/dist/. packages/lesspass-web-extension/extension/dist/ } function build_mobile_app { pushd mobile/android/ ./gradlew bundleRelease popd } function tag { git add . git commit --message="LessPass version ${1}" git tag "${1}" } current_version=$( grep -Po '(?<="version": ")[^"]*' package.json ) new_version=$( increment_version ${current_version} ${bump_type} ) replace_versions_in_files ${current_version} ${new_version} build_web_extensions build_mobile_app tag ${new_version}