Created
June 2, 2024 10:11
-
-
Save lvnam96/e57a2f047e527bb59b517d0cadca5b91 to your computer and use it in GitHub Desktop.
Automate repreated task "bump version" at Diijam @nam-diijam
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
# add this to .zshrc or .bashrc | |
alias bump-version="bash <path to script>/diijam-git-bump-version.sh" |
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
#! /usr/bin/bash | |
# [For git worklow at diijam.vn only] Auto add file changes & commit to bump version of current working branch | |
# Author: nobody | |
# ---------------------------- | |
echo "Git username: $(git config user.name)" | |
echo "" | |
# NOTE: VERSION file contains only version name, so `cat` command is enough instead of doing a while loop reading file content | |
VERSION=$(cat ./VERSION) | |
################## | |
### VALIDATION ### | |
################## | |
FILES_CHANGED=$(git diff --name-only) | |
if [[ ! $FILES_CHANGED =~ .*"VERSION".* ]]; then | |
echo "VERSION file does not change!" | |
exit 1 | |
fi | |
if [ "v$VERSION" != "$(git branch --show-current)" ]; then | |
echo "Current branch is not a versioning branch!" | |
exit 1 | |
fi | |
if [ $1 ]; then | |
ver=$1 | |
else | |
read -p "Enter version you want to bump (for validation): " v | |
ver=$v | |
fi | |
if [ "$ver" != "$VERSION" ]; then | |
echo "Versions mismatch!" | |
exit 1 | |
fi | |
################## | |
### MAIN TASKS ### | |
################## | |
echo "" | |
echo "Commiting .env* & VERSION files..." | |
git add -p .env* VERSION | |
git commit -m "ci: bump version \`$VERSION\`" | |
git push origin v$VERSION | |
git tag $VERSION | |
git push origin $VERSION | |
################## | |
#### SUB TASKS ### | |
################## | |
echo "" | |
read -p "Do you want to checkout branch \`develop\`? (y/N) " ANS | |
if [ "$ANS" == "y" ]; then | |
echo "Checking out branch \`develop\`..." | |
git stash -m "Changes from lastest branch \`v$VERSION\`" | |
git checkout develop | |
echo "" | |
read -p "Do you want to delete branch \`v$VERSION\`? (y/N) " ANS | |
if [ "$ANS" == "y" ]; then | |
echo "Deleting branch \`v$VERSION\`..." | |
git branch --delete v$VERSION | |
fi | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment