forked from mondu-ai/magento2-checkout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
releaser.sh
executable file
·59 lines (48 loc) · 1.57 KB
/
releaser.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
helpFunction() {
echo ""
echo "Usage: $0 -v version"
echo "\t-v Version of the plugin"
exit 1 # Exit script after printing help
}
while getopts "v:o:c:" opt; do
case "$opt" in
v) version="$OPTARG" ;;
o) old_version="$OPTARG" ;;
c) changes="$OPTARG" ;;
?) helpFunction ;; # Print helpFunction in case parameter is non-existent
esac
done
if ! echo $version | grep -Eq "^[0-9]+\.[0-9]+\.[0-9]+$"; then
echo "Invalid version: ${version}"
echo "Please specify a semantic version with no prefix (e.g. X.X.X)."
exit 1
fi
if ! echo $old_version | grep -Eq "^[0-9]+\.[0-9]+\.[0-9]+$"; then
echo "Invalid old version: ${old_version}"
echo "Please specify a semantic version with no prefix (e.g. X.X.X)."
exit 1
fi
if [[ $changes == "keep" ]]; then
echo "Changes will be commited and pushed"
else
echo "Changes won't be commited and pushed"
fi
OLD_TAG_SED_DOT="${old_version//./\\.}"
NEW_TAG_SED_DOT="${version//./\\.}"
files_to_update="composer.json etc/module.xml"
for file in $files_to_update; do
echo "Updating semver occurrences in $file"
sed -i '' "s/${OLD_TAG_SED_DOT}/${NEW_TAG_SED_DOT}/g" $file
if [[ $changes == "keep" ]]; then
echo "Adding ${file} for new commit"
git add $file
fi
done
if [[ $changes == "keep" ]]; then
echo "Pushing changes to default branch on remote"
default_branch=$(git remote show origin | sed -n "/HEAD branch/s/.*: //p")
git commit -m "Updated semver in compose.json etc/module.xml"
git push origin "${default_branch}" -f
fi
echo "Done"