Last active
March 15, 2023 18:32
-
-
Save SiarheiPilat/581a37b04ab6d2aa88a22d0a56cf176c to your computer and use it in GitHub Desktop.
Automatically increment project version on each commit to main (on pre commit)
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
#!/bin/sh | |
# new pre commit | |
# get bundle version | |
bundle_ver=`cat ./ProjectSettings/ProjectSettings.asset | grep bundleVersion | cut -d ' ' -f 4` | |
# explanation: | |
# cat - concatenate the content of multiple files | |
# cat [option] [file] | |
# cut command is a fast way to extract parts of lines of text files | |
# -d is a delimiter | |
# -f is a field-based selection | |
# get last character | |
last_digit="${bundle_ver: -1}" | |
# increment last digit | |
incr_digit=$((last_digit+1)) | |
# replace last digit of bundle version with new digit | |
new_ver=${bundle_ver%?}$incr_digit | |
# write to project settings file | |
sed -i -e '/bundleVersion/ s/:.*/: '"$new_ver"'/' ./ProjectSettings/ProjectSettings.asset | |
# remember to git add | |
git add ./ProjectSettings/ProjectSettings.asset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment