-
Notifications
You must be signed in to change notification settings - Fork 158
/
bump.sh
executable file
·167 lines (140 loc) · 3.78 KB
/
bump.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
# General bump flow:
#
# Read version from main VERSION file (located at root)
# Bump RUST and JAVASCRIPT files (see listing above) according to command line args: major/minor/patch/set
# Bump the main VERSION file
# Commit added files
# Create version tag (e.g. v1.0.1)
# Push commit to main
# Push tag to main
#
# Usage: bump.sh [TYPE]
#
# TYPE options:
# major
# minor
# patch
# set (just sets all versions to the current VERSION file version)
# verify (checks if all versions match)
set -e
if [ "$#" -ne 1 ]; then
echo "Usage: $0 {major|minor|patch|set|verify}"
exit 1
fi
VERSION=$(cat VERSION)
TYPE=$1
RUST=(
"Cargo.toml"
"quadratic-connection/Cargo.toml"
"quadratic-core/Cargo.toml"
"quadratic-files/Cargo.toml"
"quadratic-multiplayer/Cargo.toml"
"quadratic-rust-client/Cargo.toml"
"quadratic-rust-shared/Cargo.toml"
)
JAVASCRIPT=(
"package.json"
"quadratic-api/package.json"
"quadratic-client/package.json"
"quadratic-shared/package.json"
)
if [[ -z "$VERSION" ]]; then
echo "Version file is empty. Please set a version in the VERSION file. (e.g. 1.0.0)"
exit 1
fi
if [[ ! "$TYPE" =~ ^(major|minor|patch|set|verify)$ ]]; then
echo "Invalid bump type: $TYPE"
echo "Usage: $0 {major|minor|patch|set|verify}"
exit 1
fi
# bump semver version: major, minor, patch, set
bump_version() {
local version=$1
local type=$2
local major=$(echo "$version" | cut -d. -f1)
local minor=$(echo "$version" | cut -d. -f2)
local patch=$(echo "$version" | cut -d. -f3)
local set=$version
case $type in
major)
major=$((major + 1))
minor=0
patch=0
;;
minor)
minor=$((minor + 1))
patch=0
;;
patch)
patch=$((patch + 1))
;;
set)
;;
esac
echo "$major.$minor.$patch"
}
verify_versions() {
local expected_version=$(cat VERSION)
local mismatch=false
for file in ${JAVASCRIPT[@]}; do
if [ ! -f "$file" ]; then
echo "Error: $file not found"
exit 1
fi
local version=$(jq -r .version "$file")
if [ "$version" != "$expected_version" ]; then
echo "Version mismatch in $file: Expected $expected_version, found $version"
mismatch=true
fi
done
for file in ${RUST[@]}; do
if [ ! -f "$file" ]; then
echo "Error: $file not found"
exit 1
fi
local version=$(grep '^version' "$file" | sed 's/version = "\(.*\)"/\1/')
if [ "$version" != "$expected_version" ]; then
echo "Version mismatch in $file: Expected $expected_version, found $version"
mismatch=true
fi
done
if [ "$mismatch" = false ]; then
echo "All versions match: $expected_version"
else
echo "Version mismatch detected. Please review the above output."
exit 1
fi
}
if [ "$TYPE" = "verify" ]; then
verify_versions
exit 0
fi
NEW_VERSION=$(bump_version "$VERSION" "$TYPE")
# bump package.json files
for file in ${JAVASCRIPT[@]}; do
if [ ! -f "$file" ]; then
echo "Error: $file not found"
exit 1
fi
PACKAGE_JSON_VERSION=$(jq -r .version "$file")
echo "Current $file version is $PACKAGE_JSON_VERSION"
jq --arg new_version "$NEW_VERSION" '.version = $new_version' "$file" > tmp.json && mv tmp.json "$file"
echo "Updated $file version to $NEW_VERSION"
done
# bump Cargo.toml files
for file in ${RUST[@]}; do
if [ ! -f "$file" ]; then
echo "Error: $file not found"
exit 1
fi
CARGO_TOML_VERSION=$(grep '^version' "$file" | sed 's/version = "\(.*\)"/\1/')
echo "Current $file version is $CARGO_TOML_VERSION"
sed -i.bak "s/^version = \".*\"/version = \"$NEW_VERSION\"/" "$file" && rm "${file}.bak"
echo "Updated $file version to $NEW_VERSION"
done
# update the main VERSION file
echo $NEW_VERSION > VERSION
# After updating all versions
verify_versions
echo "Version bump to $NEW_VERSION complete!"