Last active
June 16, 2023 08:27
-
-
Save beyondszine/a9bac707c3e988aa4b86c4caa003eca8 to your computer and use it in GitHub Desktop.
this is to be used in actions to auto increment flutter version in pubspec.yaml file
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
# Set this to "major", "minor", or "patch" to control which part of the version is incremented. | |
# call this file with VERSION_INCREMENT as argument or if running manually, uncomment | |
# VERSION_INCREMENT="major" | |
# Check if VERSION_INCREMENT is set and non-empty | |
if [[ -z "${VERSION_INCREMENT}" ]]; then | |
echo "VERSION_INCREMENT variable is not set, exiting." | |
exit 1 | |
fi | |
CURRENT_VERSION=$(grep 'version:' pubspec.yaml | awk '{print $2}') | |
# Split the version string into version and versionCode using '+' as the delimiter. | |
IFS='+' read -ra VERSION <<< "$CURRENT_VERSION" | |
# Split the version into an array using '.' as the delimiter. | |
IFS='.' read -ra VERSION_PARTS <<< "${VERSION[0]}" | |
echo "CURRENT_VERSION: ${CURRENT_VERSION}" | |
echo "IFS value: ${IFS}" | |
echo "VERSION_PARTS: ${VERSION_PARTS[0]} ${VERSION_PARTS[1]} ${VERSION_PARTS[2]}" | |
case $VERSION_INCREMENT in | |
"major") | |
VERSION_PARTS[0]=$((VERSION_PARTS[0] + 1)) | |
VERSION_PARTS[1]=0 | |
VERSION_PARTS[2]=0 | |
;; | |
"minor") | |
VERSION_PARTS[1]=$((VERSION_PARTS[1] + 1)) | |
VERSION_PARTS[2]=0 | |
;; | |
"patch") | |
VERSION_PARTS[2]=$((VERSION_PARTS[2] + 1)) | |
;; | |
esac | |
VERSION_CODE=$((VERSION_PARTS[0]*10000 + VERSION_PARTS[1]*1000 + VERSION_PARTS[2] )) | |
NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.${VERSION_PARTS[2]}+$VERSION_CODE" | |
echo "New version: $NEW_VERSION" | |
sed -i -e "/version:/c\version: $NEW_VERSION" pubspec.yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment