Last active
June 7, 2022 12:18
-
-
Save carloscabo/4b02b968a85c0a709a1c34025c459ba9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
script_name=`basename "$0"` | |
branch_name="$(git symbolic-ref HEAD 2>/dev/null)" || | |
branch_name="(unnamed branch)" # detached HEAD | |
branch_name=${branch_name##refs/heads/} | |
if [ -z "$1" ] | |
then | |
echo "You must provide a version string, for instance:" | |
echo "./$script_name v1.34.9-beta" | |
exit | |
fi | |
if [ ! -e README.md ] | |
then | |
echo "There is no README.md!" | |
exit | |
fi | |
if grep -Fq "img.shields.io/badge/version" README.md | |
then | |
echo "$1 in branch: $branch_name" | |
echo $1 > version.txt | |
version="${1//-/--}" # Badge URL need to escape hyphens as double hyphens | |
sed -E "s:(badge\/version-)(.*)(-blue|-brightgreen|-green|-yellowgreen|-yellow|-orange|-red|-lightgrey):\1$version\3:g" README.md > README.tmp | |
rm README.md | |
mv README.tmp README.md | |
git add README.md | |
git add version.txt | |
git commit -m "Update to version $1" | |
git push origin $branch_name | |
git tag -a $1 -m '' | |
git push origin --tags | |
echo "DONE!" | |
else | |
# Badge URL not found | |
echo "Badge code not found in README.md, you must add this:" | |
echo "![version](https://img.shields.io/badge/version-X.X.3-blue)" | |
exit | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Creates a version.txt file, updates READ.md badge and tags a new version.