Skip to content

Commit 77787e5

Browse files
committed
fix
1 parent 65122cc commit 77787e5

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

scripts/bump-version.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
# Run `npm version` on all projects in the repo, keeping them synced
3+
#
4+
# Usage: bump-version [patch|minor|major] (optional message)
5+
#
6+
# Must be in a clean git checkout and creates a new git branch.
7+
# Sample Usage:
8+
# ./scripts/bump-version minor "Update minor version to allow new feature"
9+
10+
set -euo pipefail
11+
12+
increment_type="${1:-patch}"
13+
detail="${2:-autobump}"
14+
15+
: "${BUMP_EXPECTED_BRANCH:=main}"
16+
17+
if [[ $BUMP_EXPECTED_BRANCH != $(git rev-parse --abbrev-ref HEAD) ]]; then
18+
echo "Please run this command on the main branch"
19+
exit 1
20+
elif [[ $(git status --porcelain) ]]; then
21+
echo "Please run this command on an unmodified checkout"
22+
exit 1
23+
fi
24+
25+
packages=(lib cli web-app)
26+
old_version=$(cd "${packages[0]}" && node -p "require('./package.json').version")
27+
echo npm --no-git-tag-version version "${increment_type}"
28+
(cd "${packages[0]}" && npm --no-git-tag-version version "${increment_type}")
29+
new_version=$(cd "${packages[0]}" && node -p "require('./package.json').version")
30+
31+
for x in "${packages[@]:1}"; do
32+
(
33+
cd "${x}"
34+
npm --no-git-tag-version version "${new_version}"
35+
)
36+
done
37+
38+
# multiplatform `sed -i`: https://unix.stackexchange.com/a/92907
39+
case $(sed --help 2>&1) in
40+
*GNU*) sed_i() { sed -i "$@"; } ;;
41+
*) sed_i() { sed -i '' "$@"; } ;;
42+
esac
43+
44+
if ! sed_i "s/version=${old_version}/version=${new_version}/" "Makefile"; then
45+
echo "Unable to change version in makefile"
46+
exit 1
47+
fi
48+
49+
if ! sed_i "s/export const version = '[^']\{1,\}';\$/export const version = \'${new_version}\';/" lib/src/version.ts; then
50+
echo "Unable to change version in version files"
51+
exit 1
52+
fi
53+
54+
if ! scripts/check-version-is.sh "${new_version}"; then
55+
echo "bump version script fail"
56+
exit 1
57+
fi
58+
59+
if ! make all; then
60+
echo "Unable to bump package locks"
61+
exit 2
62+
fi
63+
64+
commit_message="🆙 ${new_version} ${increment_type} ${detail}"
65+
git checkout -b "feature/bump-${increment_type}-from-${old_version}-to-${new_version}"
66+
git add .
67+
git commit -m "${commit_message}"

0 commit comments

Comments
 (0)