qbit_manage/scripts/pre-commit/increase_version.sh
2023-06-04 15:43:13 -04:00

41 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
staged_changes=$(git diff-index --cached HEAD | wc -l | awk '{print $1}')
# Check if there are any changes staged for commit
if [ "$staged_changes" -eq 0 ]; then
echo "There are no changes staged for commit. Skipping version update."
exit 0
fi
# Check if the VERSION file is staged for modification
if git diff --cached --name-only | grep -q "VERSION"; then
echo "The VERSION file is already modified. Skipping version update."
exit 0
fi
# Read the current version from the VERSION file
current_version=$(cat VERSION)
echo "Current version: $current_version"
# Check if "develop" is not present in the version string
if [[ $current_version != *"develop"* ]]; then
echo "The word 'develop' is not present in the version string."
exit 0
fi
# Get the version number from the HEAD commit
current_version=$(git show HEAD:VERSION 2>/dev/null)
# Extract the version number after "develop"
version_number=$(echo "$current_version" | grep -oP '(?<=develop)\d+')
# Increment the version number
new_version_number=$((version_number + 1))
# Replace the old version number with the new one
new_version=$(echo "$current_version" | sed "s/develop$version_number/develop$new_version_number/")
# Update the VERSION file
echo "$new_version" > VERSION
echo "Version updated to: $new_version"