jrnl/.build/generate_changelog.sh
Jonathan Wren 919ab7902d Rename master branch to release (#985)
It's not our main branch anyway, and "release" makes it more clear what
it's for. There's an industry-wide trend to move away from terms that
invoke master/slave relationships in order to make members of
marginalized populations slightly less uncomfortable.
2020-06-20 14:11:03 -07:00

64 lines
2.1 KiB
Bash
Executable file

#!/usr/bin/env bash
BRANCH=$TRAVIS_BRANCH
if [[ $TRAVIS_BRANCH == $TRAVIS_TAG ]]; then
BRANCH='release'
fi
# Check if branch has been updated since this build started
# This tends to happen if multiple things have been merged in at the same time.
if [[ -z $TRAVIS_TAG ]]; then
git fetch origin
if [[ $(git rev-parse "origin/${BRANCH}") != $TRAVIS_COMMIT ]]; then
echo "${BRANCH} has been updated since build started. Aborting changelog."
exit 0
fi
fi
FILENAME='CHANGELOG.md'
# get the latest git tags
releases="$(git tag --sort=-creatordate | grep -Ev '(alpha|beta|rc)')"
release_latest=$(printf '%s' "$releases" | awk 'NR==1')
release_secondlatest=$(printf '%s' "$releases" | awk 'NR==2')
echo "release_latest: ${release_latest}"
echo "release_secondlatest: ${release_secondlatest}"
# delete generated line (or it will be added multiple times)
sed -i '/This Changelog was automatically generated by/d' "$FILENAME"
# delete trailing empty lines
sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba' "$FILENAME"
# determine correct tag to go back to
if [[ $TRAVIS_TAG == $release_latest ]]; then
echo "release build"
gittag=${release_secondlatest}
elif [[ ! -z $TRAVIS_TAG ]]; then
echo "beta elease"
gittag=${release_latest}
else
echo "merge into release or develop"
gittag=${release_latest}
fi
echo "gittag: ${gittag}"
# find the line the tag starts on, and subtract 1
tagline=$(grep -n "^## \[\?$gittag\]\?" "$FILENAME" | awk '{print $1}' FS=':' | head -1)
echo "tagline: ${tagline}"
[[ ! -z $tagline ]] && sed -i "1,$(expr $tagline - 1)d" "$FILENAME"
# generate the changelog
docker run -it --rm -v "$(pwd)":/usr/local/src/your-app ferrarimarco/github-changelog-generator -t $GITHUB_TOKEN --since-tag $gittag
# Put back our link (instead of the broken one)
sed -i 's!https://pypi.org/project/jrnl/HEAD/!https://github.com/jrnl-org/jrnl/!' "$FILENAME"
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 "Update changelog [ci skip]"
git push https://${GITHUB_TOKEN}@github.com/jrnl-org/jrnl.git $BRANCH