Bash script to control the package.json version in js projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -o nounset | |
set -o errexit | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[1;33m' | |
ORANGE='\033[0;33m' | |
BLUE='\033[0;34m' | |
NC='\033[0m' | |
#This is our develop branch name. | |
DEVELOP_BRANCH="origin/develop" | |
#Get the current branch name. | |
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
printf "${BLUE}* Comparing branches *${NC}\n" | |
printf "* The current branch is: ${GREEN}$CURRENT_BRANCH${NC}\n" | |
printf "* The develop branch is: ${YELLOW}$DEVELOP_BRANCH${NC}\n" | |
#Get number of differences. | |
NUM_CHANGES=$(git diff ${DEVELOP_BRANCH} -- ./package.json | grep version | wc -l) | |
printf "\n${BLUE}* Number of changes = ${NC} ${YELLOW}${NUM_CHANGES}${NC} ${BLUE}*${NC}\n\n" | |
#Check if the package.json version of the develop and the current branches are different | |
if [ "$NUM_CHANGES" != 2 ]; then | |
printf "${RED}😿 - Version has not been changed, push not available 🙀.${NC}\n" | |
printf "${RED}Please go to package.json and update the version attribute 🙏.${NC}\n\n" | |
exit 1 | |
else | |
printf "${GREEN}😎 - Version control OK!! - 😎${NC}\n" | |
printf "${GREEN}😜 Git push starting...${NC}\n" | |
printf "${GREEN}...${NC}\n\n" | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment