Skip to content

Instantly share code, notes, and snippets.

@wonzbak
Last active June 5, 2017 14:30
Show Gist options
  • Save wonzbak/e895ad3815ecc228ba859746297bac1e to your computer and use it in GitHub Desktop.
Save wonzbak/e895ad3815ecc228ba859746297bac1e to your computer and use it in GitHub Desktop.
bash script to prepare release with git
#!/bin/bash
CHANGELOG_FILENAME="CHANGELOG.rst"
LASTTAG=$(git tag| sort -V | tail -1)
echo "Last tag $LASTTAG"
TMPFILE=$(mktemp)
TODAY=$(date +%Y-%m-%d)
read -p "new tag : " NEWTAG
TAG_TITLE="$NEWTAG ($TODAY)"
TAG_TITLE_LENGTH=${#TAG_TITLE}
# file title
head -n 3 $CHANGELOG_FILENAME >> $TMPFILE
# version title
echo $TAG_TITLE >> $TMPFILE
printf '=%.0s' `seq 1 $TAG_TITLE_LENGTH` >> $TMPFILE # print '-' x $TAG_TITLE_LENGTH
echo -e "\n" >> $TMPFILE
# list of commit started with '-'
git log $LASTTAG..HEAD --pretty=format:"%h %s (%an)" | sed 's/^/- /' >> $TMPFILE
echo >> $TMPFILE
# add history file (without title document)
tail -n +3 $CHANGELOG_FILENAME >> $TMPFILE # remove 3 first line
cp $TMPFILE $CHANGELOG_FILENAME
rm $TMPFILE
git diff
read -p "edit change log ? [YN]: " yn
case $yn in
[Yy]* ) vim $CHANGELOG_FILENAME ;;
esac
git add $CHANGELOG_FILENAME
sed -i "s/$LASTTAG/$NEWTAG/g" app/config/version.yml
git add app/config/version.yml
git diff
read -p "commit & tag ? [YN]: " yn
case $yn in
[Yy]* ) git add app/config/version ; git commit -m"version $NEWTAG" ; git tag $NEWTAG ;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment