|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #!/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
-
- bump_type="${1:-}"
- check_bump_type_is_defined ${bump_type}
- check_branch_is_master
- 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 build {
- pushd packages/lesspass-web-extension/
- yarn install
- yarn upgrade --latest
- yarn build
- popd
- }
-
-
- function commit_and_push {
- git add .
- git commit --message="Auto build for lesspass-web-extension"
- git push
- }
-
- current_version=$( grep -Po '(?<="version": ")[^"]*' packages/lesspass-web-extension/package.json )
- echo "Current lesspass-web-extension version is ${current_version}"
- new_version=$( increment_version ${current_version} ${bump_type} )
- echo "New lesspass-web-extension version is ${new_version}"
- latest_lesspass_pure_version=$( yarn info -s lesspass-pure version )
- echo "Latest lesspass-pure version is ${latest_lesspass_pure_version}"
- sed -i -E "s/\"lesspass-pure\": \"([0-9]+)\.([0-9]+)\.([0-9]+)\"/\"lesspass-pure\": \"${latest_lesspass_pure_version}\"/g" packages/lesspass-web-extension/package.json
- sed -i -E "s/\"version\": \"([0-9]+)\.([0-9]+)\.([0-9]+)\"/\"version\": \"${new_version}\"/g" packages/lesspass-web-extension/package.json
- sed -i -E "s/\"version\": \"([0-9]+)\.([0-9]+)\.([0-9]+)\"/\"version\": \"${new_version}\"/g" packages/lesspass-web-extension/extension/manifest.json
- build
- commit_and_push
|