Skip to content

Instantly share code, notes, and snippets.

@stephanebruckert
Last active March 19, 2021 15:07
Show Gist options
  • Save stephanebruckert/34de35069c59af7a1f5fc7c52609ce2e to your computer and use it in GitHub Desktop.
Save stephanebruckert/34de35069c59af7a1f5fc7c52609ce2e to your computer and use it in GitHub Desktop.
Automatically force-tag v1 and v1.0 when creating v1.0.0 (as done in the docker registry)
#!/bin/bash
echo "Make sure:
- you understand the content of this script before running it.
It can be dangerous as it aims to simplify overriding major and minor versions for the latest tag.
- you are currently on the commit you want to tag, so don't forget to pull.
"
read -p "SemVer version: " version
for run in {1..3}; # once for each of patch, minor and major
do
read -r -p "Going to create $version, are you sure? [Y/n]" response
if [[ $response =~ ^(yes|y|Y ) ]] || [[ -z $response ]]; then
if [ "$run" -eq "1" ]; then
force=""
else
# only force minor and major
force="-f"
fi
git tag $version $force
echo "Created $version"
else
echo "Cancelled creating $version"
exit
fi
version=${version%.*}
done
read -r -p "Going to force push all branches and tags, are you sure? [Y/n]" response
if [[ $response =~ ^(yes|y|Y ) ]] || [[ -z $response ]]; then
git push
git push --tags -f
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment