Last active
April 13, 2017 00:48
-
-
Save samjonester/0c9a328ab1922e0ade6c6c5d9df1271d to your computer and use it in GitHub Desktop.
Make File Stuff
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 | |
# works with a file called VERSION in the current directory, | |
# the contents of which should be a semantic version number | |
# such as "1.2.3" | |
NOW="$(date +'%B %d, %Y')" | |
RED="\033[1;31m" | |
GREEN="\033[0;32m" | |
YELLOW="\033[1;33m" | |
BLUE="\033[1;34m" | |
CYAN="\033[1;36m" | |
WHITE="\033[1;37m" | |
RESET="\033[0m" | |
LATEST_HASH=`git log --pretty=format:'%h' -n 1` | |
WARNING_FLAG="${YELLOW}!" | |
NOTICE_FLAG="${CYAN}❯" | |
PUSHING_MSG="${NOTICE_FLAG} Pushing new version to the ${WHITE}origin${CYAN}..." | |
if [ -f VERSION ]; then | |
BASE_STRING=`cat VERSION` | |
BASE_LIST=(`echo $BASE_STRING | tr '.' ' '`) | |
V_MAJOR=${BASE_LIST[0]} | |
V_MINOR=${BASE_LIST[1]} | |
V_PATCH=${BASE_LIST[2]} | |
echo -e "${NOTICE_FLAG} Current version: ${WHITE}$BASE_STRING" | |
echo -e "${NOTICE_FLAG} Latest commit hash: ${WHITE}$LATEST_HASH" | |
if [[ $1 -eq '--patch' ]]; then | |
NEW_VERSION="$V_MAJOR.$V_MINOR.$((V_PATCH + 1))" | |
elif [[ $1 -eq '--minor' ]]; then | |
NEW_VERSION="$V_MAJOR.$((V_MINOR + 1)).$V_PATCH" | |
elif [[ $1 -eq '--major' ]]; then | |
NEW_VERSION="$((V_MAJOR + 1)).$V_MINOR.$V_PATCH" | |
else | |
NEW_VERSION="$V_MAJOR.$V_MINOR.$((V_PATCH + 1))" | |
fi | |
echo -e "${NOTICE_FLAG} Bumping to: ${GREEN}$NEW_VERSION" | |
echo $NEW_VERSION > VERSION | |
git add -- VERSION | |
git commit -m "${NEW_VERSION}" -- VERSION | |
git tag -a -m "${NEW_VERSION}" "v$NEW_VERSION" | |
git push origin --follow-tags | |
else | |
echo -e "${WARNING_FLAG} Could not find a VERSION file." | |
exit 1; | |
fi | |
echo -e "${NOTICE_FLAG} Finished." |
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
VERSION ?= $(shell cat VERSION) | |
.PHONY: help version clean bump release | |
.DEFAULT_GOAL := help | |
build: ## build the app | |
do stuff | |
clean: ## clean artifacts | |
rm -rf build | |
release: bump ## bump the VERSION file, git tags, and push github | |
make push -e VERSION=$(shell cat VERSION) | |
version: | |
cat VERSION | |
bump: | |
script/bump --patch | |
help: | |
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment