Skip to content

Instantly share code, notes, and snippets.

@mraspaud
Last active March 17, 2023 13:46
Show Gist options
  • Save mraspaud/2cb27fa43f1d2457a0671abc343d210a to your computer and use it in GitHub Desktop.
Save mraspaud/2cb27fa43f1d2457a0671abc343d210a to your computer and use it in GitHub Desktop.
For making pytroll releases
#!/bin/bash
set -x
# exit when any command fails
set -e
git version
gh version
main_branch=main
git stash
git checkout $main_branch
git pull
#pytest .
last_tag=$(git tag | sort -V | tail -1)
repo=$(git config --get remote.upstream.url | sed -r 's/.*(\@|\/\/)(.*)(\:|\/)([^:\/]*)\/([^\/\.]*)\.git/\4\/\5/')
loghub $repo --token $LOGHUB_TOKEN -st $last_tag -plg bug "Bugs fixed" -plg enhancement "Features added" -plg documentation "Documentation changes" -plg backwards-incompatibility "Backward incompatible changes" -plg refactor "Refactoring" -plg cleanup "Clean ups"
read -p "Last tag was $last_tag. What version number should this release have (no v)? " newversion
release_description=$(tail -n +4 CHANGELOG.temp)
echo -en '\n' >> CHANGELOG.temp
echo -en '\n' >> CHANGELOG.temp
cat CHANGELOG.temp CHANGELOG.md > CHANGELOG.new
sed "s:<RELEASE_VERSION>:$newversion:g" CHANGELOG.new > CHANGELOG.md
release_title=$(head -1 CHANGELOG.md | cut -c4-)
rm CHANGELOG.temp
rm CHANGELOG.new
git add CHANGELOG.md
tag=v$newversion
git commit -m "Update changelog for $tag"
git tag -a $tag -m "Version $newversion"
while true; do
read -p "Do you want to push the tag and make a draft release? (y/n) " yn
case $yn in
[yY] ) echo "ok, we will proceed";
break;;
[nN] ) echo "exiting...";
set +x;
exit;;
* ) echo "invalid response";;
esac
done
git push --follow-tags
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/$repo/releases \
-f target_commitish="$main_branch" -f tag_name="$tag"\
-f name="$release_title" \
-f body="$release_description" \
-F draft=true \
-F prerelease=false \
-F generate_release_notes=false
set +x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment