-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbump.sh
More file actions
55 lines (46 loc) · 1.48 KB
/
bump.sh
File metadata and controls
55 lines (46 loc) · 1.48 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
#!/usr/bin/env sh
set -e
if [ ! -f build.info ]; then
cat <<EOF > build.info
Build: 0
Version Major: 1
Version Minor: 0
Version Patch: 0
# Optional: a custom beta name (will override MAJOR.MINOR.PATCH)
# Beta Name: ...-beta
EOF
fi
MAJOR=$(grep "^Version Major:" build.info | awk '{print $3}')
MINOR=$(grep "^Version Minor:" build.info | awk '{print $3}')
PATCH=$(grep "^Version Patch:" build.info | awk '{print $3}')
BUILD_NUM=$(grep "^Build:" build.info | awk '{print $2}')
BETA_NAME=$(grep -E "^Beta Name:" build.info || true)
if [ -n "$BETA_NAME" ]; then
BETA_NAME="${BETA_NAME#*: }"
fi
NEW_BUILD=$((BUILD_NUM + 1))
if sed --version >/dev/null 2>&1; then
sed -i "s/^Build: .*/Build: ${NEW_BUILD}/" build.info
else
i '' "s/^Build: .*/Build: ${NEW_BUILD}/" build.info
fi
SEMVER="${MAJOR}.${MINOR}.${PATCH}"
if [ -n "$BETA_NAME" ]; then
VERSION="${BETA_NAME}"
else
VERSION="${SEMVER}"
fi
MINOR_PAD=$(printf "%02d" "${MINOR}")
PATCH_PAD=$(printf "%02d" "${PATCH}")
BUILD_PAD=$(printf "%04d" "${NEW_BUILD}")
VERSION_CODE="${MAJOR}${MINOR_PAD}${PATCH_PAD}${BUILD_PAD}"
if sed --version >/dev/null 2>&1; then
SED_INPLACE="sed -i"
else
SED_INPLACE="sed -i ''"
fi
$SED_INPLACE "s/^\(\s*\"version\"\s*:\s*\"\)[^\"]*\(\".*\)$/\1${VERSION}\2/" package.json
$SED_INPLACE "s/^\(\s*\"versionCode\"\s*:\s*\"\)[^\"]*\(\".*\)$/\1${VERSION_CODE}\2/" package.json
$SED_INPLACE "s/\*\*[^*]\+\*\*/**${VERSION}**/" README.md
echo "${VERSION}" > VERSION
echo "✅ Version bumped to ${VERSION} (code ${VERSION_CODE})"