Last active
December 18, 2023 19:19
-
-
Save Fania/75b149e1de8068a55565d27e4dfa1449 to your computer and use it in GitHub Desktop.
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 | |
PATH="/usr/local/bin:${PATH}" | |
echo "Patching version numbers..." | |
# -o only matching | |
# -P Perl Regex | |
# -E Extended Regex | |
match=$(git grep -oP 'magic-v\d+\.\d+\.\d+' sw.js) | |
match2=$(git grep -oP '"version": "\d+\.\d+\.\d+"' package.json) | |
match3=$(git grep -oP 'Magic Squares Version \d+\.\d+\.\d+' server.js) | |
echo "match ${match}" | |
echo "match2 ${match2}" | |
echo "match3 ${match3}" | |
regex="([0-9]+).([0-9]+).([0-9]+)" | |
if [[ ${match} =~ ${regex} ]]; then | |
major="${BASH_REMATCH[1]}" | |
minor="${BASH_REMATCH[2]}" | |
patch="${BASH_REMATCH[3]}" | |
fi | |
# only increment patch version automatically | |
# major and minor versions need to be done manually | |
old="'magic-v${major}.${minor}.${patch}'" | |
new="'magic-v${major}.${minor}.$((${patch} + 1))'" | |
old2="\"version\": \"${major}.${minor}.${patch}\"" | |
new2="\"version\": \"${major}.${minor}.$((${patch} + 1))\"" | |
old3="'Magic Squares Version ${major}.${minor}.${patch}'" | |
new3="'Magic Squares Version ${major}.${minor}.$((${patch} + 1))'" | |
# replace old version with patch increment version | |
# in service worker file, home.js, server.js, and package.json files | |
echo "old ${old}" | |
echo "new ${new}" | |
# sed -i'' -e 's/hello/bye/g' jkl.txt | |
sed -Ei '' "s/${old}/${new}/g" sw.js | |
sed -Ei '' "s/${old}/${new}/g" meta/js/home.js | |
sed -Ei '' "s/${old2}/${new2}/g" package.json | |
sed -Ei '' "s/${old3}/${new3}/g" server.js | |
git add . | |
# echo "Bump cache from ${old} to ${new}" |
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/bash | |
match=$(grep -oP 'magic-v\d+.\d+.\d+' sw.js) | |
match2=$(grep -oP "version": "\d+.\d+.\d+" package.json) | |
match3=$(grep -oP 'Magic Squares Version \d+.\d+.\d+' server.js) | |
regex="([0-9]+).([0-9]+).([0-9]+)" | |
if [[ $match =~ $regex ]]; then | |
major="${BASH_REMATCH[1]}" | |
minor="${BASH_REMATCH[2]}" | |
patch="${BASH_REMATCH[3]}" | |
fi | |
# only increment patch version automatically | |
# major and minor versions need to be done manually | |
old="'magic-v$major.$minor.$patch'" | |
new="'magic-v$major.$minor.$(($patch + 1))'" | |
old2="\"version\": \"$major.$minor.$patch\"" | |
new2="\"version\": \"$major.$minor.$(($patch + 1))\"" | |
old3="'Magic Squares Version $major.$minor.$patch'" | |
new3="'Magic Squares Version $major.$minor.$(($patch + 1))'" | |
# replace old version with patch increment version | |
# in service worker file, home.js, server.js, and package.json files | |
sed -i "s/${old}/${new}/g" sw.js | |
sed -i "s/${old}/${new}/g" meta/js/home.js | |
sed -i "s/${old2}/${new2}/g" package.json | |
sed -i "s/${old3}/${new3}/g" server.js | |
git add . | |
# echo "Bump cache from ${old} to ${new}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment