Created
March 20, 2025 12:25
-
-
Save isuke01/83fd05f1016d396b26a4b96bdd947d21 to your computer and use it in GitHub Desktop.
Automation for git release
This file contains hidden or 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/bash | |
# Check version | |
if [ -z "$1" ]; then | |
echo "Add version as an argument! Eg: release 1.2.3" | |
exit 1 | |
fi | |
VERSION=$1 | |
# Switch to stage and pull changes | |
git checkout stage || exit 1 | |
git pull origin stage || exit 1 | |
# Check if main has commits that are not on stage | |
if git rev-list --left-right stage...main | grep "^>"; then | |
echo "❌ Warning: main is ahead stage!" | |
read -p "Are you sure to proceed? (y/n) " CONFIRM | |
if [ "$CONFIRM" != "y" ]; then | |
echo "Canceled." | |
exit 1 | |
fi | |
fi | |
# Merge stage into main without auto commit | |
git checkout main || exit 1 | |
git pull origin main || exit 1 | |
# Merge stage into main without auto commit | |
git merge stage --no-commit || exit 1 | |
# Create a release tag | |
git tag -a "$VERSION" -m "Release $VERSION" || exit 1 | |
# Push changes | |
git push origin main --follow-tags || exit 1 | |
echo "✅ Release $VERSION has been deployed!" | |
# 1. Add script to bin globally: | |
# sudo mv release.sh /usr/local/bin/release | |
# sudo chmod +x /usr/local/bin/release | |
# Usage: release 1.2.3 | |
# 2. Second option: Alis in .bashrc or .zshrc | |
# BASH: | |
# echo 'alias release="bash /path/to/release.sh"' >> ~/.bashrc | |
# source ~/.bashrc | |
# ZSH: | |
# echo 'alias release="bash /path/to/release.sh"' >> ~/.zshrc | |
# source ~/.zshrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment