Last active
June 11, 2017 15:02
-
-
Save gdyrrahitis/d3277df411d0e8d0e649921446421028 to your computer and use it in GitHub Desktop.
Git prepare commit hook to alter a file. Append commit id to the version.js file with a prepare-commit hook
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
# Disclaimer: Commits should have the following format | |
# <PROJNAME>: <DESCRIPTION> | |
# Example: | |
# JIRA-450: My description | |
# Following code will substring the JIRA-450 and append it as last value of the `window.version` variable, replacing the `SAMPLE` | |
# This is just a sample, it is not recommended to do such mission, versions should be handled by CI and should follow the SEMVER specification: http://semver.org/ | |
# Should add validation to ensure one is committing following the conventions | |
# Git hooks documentation https://git-scm.com/docs/githooks | |
# Get commit message | |
MESSAGE=`cat $1` | |
# Substring, get characters, starting from 1 (first) until ':' | |
MESSAGE=$( echo $MESSAGE | cut -d ':' -f 1 ) | |
# Your js contents | |
CONTENTS="window.version = '1.2.3-" | |
# Concatenating message with contents | |
CONTENTS+=$MESSAGE | |
CONTENTS+="';" | |
# Writing to file before commiting | |
cat > version.js << EOF | |
$CONTENTS |
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
window.version = '1.2.3-SAMPLE'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment