Skip to content

Instantly share code, notes, and snippets.

@ppezier
Forked from pete-otaqui/bumpversion.sh
Last active October 24, 2018 16:02
Show Gist options
  • Save ppezier/c83afb4b368efad79315cb995f0b5507 to your computer and use it in GitHub Desktop.
Save ppezier/c83afb4b368efad79315cb995f0b5507 to your computer and use it in GitHub Desktop.
Bump a software project's VERSION, add the CHANGES, and tag with GIT
#!/bin/bash
# Thanks to @pete-otaqui for the initial gist:
# https://gist.github.com/pete-otaqui/4188238
# Original version modified & translated by Patrick Pézier
# 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"
# More information about semantic versioning:
# https://semver.org/
# this script will display the current version, automatically
# suggest a "minor" version update, and ask for input to use
# the suggestion, or a newly entered value.
# once the new version number is determined, the script will
# pull a list of changes from git history, prepend this to
# a file called CHANGELOG.txt (under the title of the new
# version number) and create a GIT tag.
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 "Version actuelle : $BASE_STRING"
V_MINOR=$((V_MINOR + 1))
V_PATCH=0
SUGGESTED_VERSION="$V_MAJOR.$V_MINOR.$V_PATCH"
read -p "Saisir un nouveau numéro de version [$SUGGESTED_VERSION]: " INPUT_STRING
if [ "$INPUT_STRING" = "" ]; then
INPUT_STRING=$SUGGESTED_VERSION
fi
echo "La nouvelle version sera $INPUT_STRING"
echo $INPUT_STRING > VERSION
echo "Version $INPUT_STRING :" > tmpfile
git log --pretty=format:" - %s" "v$BASE_STRING"...HEAD >> tmpfile
echo "" >> tmpfile
echo "" >> tmpfile
cat CHANGELOG.txt >> tmpfile
mv tmpfile CHANGELOG.txt
git add CHANGELOG.txt VERSION
git commit -m "Version montée à $INPUT_STRING"
git tag -a -m "Étiquetage (tag) de la version $INPUT_STRING" "v$INPUT_STRING"
git push origin --tags
else
echo "Fichier VERSION introuvable"
read -p "Créer un fichier de version et démarrer de zéro ? [o]" RESPONSE
if [ "$RESPONSE" = "" ]; then RESPONSE="o"; fi
if [ "$RESPONSE" = "O" ]; then RESPONSE="o"; fi
if [ "$RESPONSE" = "Oui" ]; then RESPONSE="o"; fi
if [ "$RESPONSE" = "oui" ]; then RESPONSE="o"; fi
if [ "$RESPONSE" = "OUI" ]; then RESPONSE="o"; fi
if [ "$RESPONSE" = "o" ]; then
echo "0.1.0" > VERSION
echo "Version 0.1.0" > CHANGELOG.txt
git log --pretty=format:" - %s" >> CHANGELOG.txt
echo "" >> CHANGELOG.txt
echo "" >> CHANGELOG.txt
git add VERSION CHANGELOG.txt
git commit -m "Ajout des fichiers VERSION et CHANGELOG.txt, Version montée à v0.1.0"
git tag -a -m "Étiquetage (tag) de la version 0.1.0" "v0.1.0"
git push origin --tags
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment