Skip to content

Instantly share code, notes, and snippets.

@damiancipolat
Created April 30, 2020 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damiancipolat/d2c3fc196b25a93d7b440b7d685ed451 to your computer and use it in GitHub Desktop.
Save damiancipolat/d2c3fc196b25a93d7b440b7d685ed451 to your computer and use it in GitHub Desktop.
Bash script to control the package.json version in js projects
#!/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