update changelog script to handle different scenarios (#724)

This commit is contained in:
Jonathan Wren 2020-01-14 21:31:04 -08:00
parent e6a9a0e3cd
commit 3fc3233a44

View file

@ -3,12 +3,12 @@
FILENAME='CHANGELOG.md' FILENAME='CHANGELOG.md'
# get the latest git tags # get the latest git tags
gittags="$(git tag --sort=-creatordate | grep -Ev '(alpha|beta|rc)')" releases="$(git tag --sort=-creatordate | grep -Ev '(alpha|beta|rc)')"
gittag_latest=$(printf '%s' "$gittags" | awk 'NR==1') release_latest=$(printf '%s' "$releases" | awk 'NR==1')
gittag_secondlatest=$(printf '%s' "$gittags" | awk 'NR==2') release_secondlatest=$(printf '%s' "$releases" | awk 'NR==2')
echo "gittag_latest: ${gittag_latest}" echo "release_latest: ${release_latest}"
echo "gittag_secondlatest: ${gittag_secondlatest}" echo "release_secondlatest: ${release_secondlatest}"
# delete generated line (or it will be added multiple times) # delete generated line (or it will be added multiple times)
sed -i '/This Changelog was automatically generated by/d' "$FILENAME" sed -i '/This Changelog was automatically generated by/d' "$FILENAME"
@ -17,24 +17,38 @@ sed -i '/This Changelog was automatically generated by/d' "$FILENAME"
sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' "$FILENAME" sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' "$FILENAME"
# determine correct tag to go back to # determine correct tag to go back to
# @TODO if [[ $TRAVIS_TAG == $release_latest ]]; then
if [[ ! -z $TRAVIS_TAG ]]; then
echo "release build" echo "release build"
gittag=${gittag_secondlatest} gittag=${release_secondlatest}
elif [[ ! -z $TRAVIS_TAG ]]; then
echo "beta elease"
gittag=${release_latest}
else else
echo "merge into master or develop" echo "merge into master or develop"
gittag=${gittag_latest} gittag=${release_latest}
fi fi
echo "gittag: ${gittag}" echo "gittag: ${gittag}"
# find the line the tag starts on, and subtract 1 # find the line the tag starts on, and subtract 1
tagline=$(grep -n "^## \[\?$gittag\]\?" CHANGELOG.md | awk '{print $1}' FS=':' | head -1) tagline=$(grep -n "^## \[\?$gittag\]\?" "$FILENAME" | awk '{print $1}' FS=':' | head -1)
echo "tagline: ${tagline}" echo "tagline: ${tagline}"
[[ ! -z $tagline ]] && sed -i "1,$(expr $tagline - 1)d" "$FILENAME" [[ ! -z $tagline ]] && sed -i "1,$(expr $tagline - 1)d" "$FILENAME"
# generate the changelog # generate the changelog
docker run -it --rm -v "$(pwd)":/usr/local/src/your-app ferrarimarco/github-changelog-generator -t $CHANGELOG_GITHUB_TOKEN --since-tag $gittag docker run -it --rm -v "$(pwd)":/usr/local/src/your-app ferrarimarco/github-changelog-generator -t $GITHUB_TOKEN --since-tag $gittag
# @TODO commit changes, etc # Put back our link (instead of the broken one)
git diff sed -i 's!https://pypi.org/project/jrnl/HEAD/!https://github.com/jrnl-org/jrnl/!' "$FILENAME"
BRANCH=$TRAVIS_BRANCH
if [[ $TRAVIS_BRANCH == $TRAVIS_TAG ]]; then
BRANCH='master'
fi
git config --global user.email "jrnl.bot@gmail.com"
git config --global user.name "Jrnl Bot"
git checkout $BRANCH
git add "$FILENAME"
git commit -m "Updating changelog [ci skip]"
git push https://${GITHUB_TOKEN}@github.com/jrnl-org/jrnl.git $BRANCH