forked from rime/squirrel
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbump_version
More file actions
executable file
·92 lines (75 loc) · 2.17 KB
/
bump_version
File metadata and controls
executable file
·92 lines (75 loc) · 2.17 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
set -e
cd "$(dirname $0)/.."
source package/common.sh
app_version="$(get_app_version)"
echo "current app version: ${app_version}"
invalid_args() {
echo "Usage: $(basename $0) <new_version>|major|minor|patch"
exit 1
}
version_pattern='([0-9]+)\.([0-9]+)\.([0-9]+)'
old_version=$app_version
new_version=$1
if [[ $old_version =~ $version_pattern ]]; then
old_major=${BASH_REMATCH[1]}
old_minor=${BASH_REMATCH[2]}
old_patch=${BASH_REMATCH[3]}
else
invalid_args
fi
new_major=$old_major
new_minor=$old_minor
new_patch=$old_patch
if [[ $new_version =~ $version_pattern ]]; then
new_major=${BASH_REMATCH[1]}
new_minor=${BASH_REMATCH[2]}
new_patch=${BASH_REMATCH[3]}
elif [[ $new_version = 'major' ]]; then
((++new_major))
new_minor=0
new_patch=0
elif [[ $new_version = 'minor' ]]; then
((++new_minor))
new_patch=0
elif [[ $new_version = 'patch' ]]; then
((++new_patch))
else
invalid_args
fi
old_version="${old_major}.${old_minor}.${old_patch}"
new_version="${new_major}.${new_minor}.${new_patch}"
echo "updating ${old_version} => ${new_version}"
# deprecated
edit_info_plist_file() {
local file="$1"
if [[ $OSTYPE =~ darwin ]]; then
L_BOUND='[[:<:]]'
R_BOUND='[[:>:]]'
else
L_BOUND='\<'
R_BOUND='\>'
fi
SEP='\([,.]\)'
local version_pattern="${L_BOUND}${old_major}${SEP}${old_minor}${SEP}${old_patch}${R_BOUND}"
local replacement=${new_major}'\1'${new_minor}'\2'${new_patch}
sed -i '' "s/${version_pattern}/${replacement}/g" "${file}"
}
update_changelog() {
local version="$1"
clog --from-latest-tag \
--changelog CHANGELOG.md \
--repository https://github.com/rime/squirrel \
--setversion "${version}"
}
bump_version "${new_version}"
update_changelog "${new_version}"
${VISUAL:-${EDITOR:-vim}} CHANGELOG.md
match_line "## ${new_version} " CHANGELOG.md || (
echo >&2 "CHANGELOG.md has no changes for version ${new_version}."
exit 1
)
release_message="chore(release): ${new_version} :tada:"
release_tag="${new_version}"
git commit --all --message "${release_message}"
git tag --annotate "${release_tag}" --message "${release_message}"