forked from ddnexus/pagy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump.sh
executable file
·71 lines (55 loc) · 1.79 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
#!/usr/bin/env bash
set -e
# Ensure that the ci-cache is up-to-date
./e2e/ci-cache.sh
# Exit if the working tree is dirty
test -n "$(git status --porcelain)" && echo "Working tree dirty!" && exit 1
# Set the root path
ROOT="$(cd -P -- "$(dirname -- "$0")" && printf '%s\n' "$(pwd -P)")"
# Prompt for the new version
old_vers=$(ruby -Ilib -rpagy -e 'puts Pagy::VERSION')
echo "Current Pagy::VERSION: $old_vers"
read -rp 'Enter the new version> ' new_vers
# Check the new version
[[ -z $new_vers ]] && echo 'Missing new version!' && exit 1
num=$(echo "$new_vers" | grep -o '\.' | wc -l)
[[ $num == 2 ]] || (echo 'Incomplete semantic version!' && exit 1)
# Bump version in files
esc_old_vers=${old_vers//./\\.}
esc_new_vers=${new_vers//./\\.}
function bump(){
sed -i "0,/$esc_old_vers/{s/$esc_old_vers/$esc_new_vers/}" "$1"
}
bump "$ROOT/retype.yml"
bump "$ROOT/.github/.env"
bump "$ROOT/lib/pagy.rb"
bump "$ROOT/lib/config/pagy.rb"
bump "$ROOT/src/pagy.ts"
# Bumps docs example
esc_old_minor_vers=${esc_old_vers%\\*}
esc_new_minor_vers=${esc_new_vers%\\*}
sed -i "0,/$esc_old_minor_vers/{s/$esc_old_minor_vers/$esc_new_minor_vers/}" "$ROOT/quick-start.md"
cd "$ROOT/src"
pnpm run build
cd "$ROOT"
# Update CHANGELOG
changelog=$(cat <<-LOG
<hr>
## Version $new_vers
$(git log --format="- %s%b" "$old_vers"..HEAD)
LOG
)
CHANGELOG="$ROOT/CHANGELOG.md"
TMPFILE=$(mktemp)
awk -v l="$changelog" '{sub(/<hr>/, l); print}' "$CHANGELOG" > "$TMPFILE"
mv "$TMPFILE" "$CHANGELOG"
# Run test to check the consistency across files
bundle exec ruby -Itest test/pagy_test.rb --name "/pagy::Version match(#|::)/"
# Show diff
git diff -U0 --word-diff=color
# Optional commit
read -rp 'Do you want to commit the changes? (y/n)> ' input
if [[ $input = y ]] || [[ $input = Y ]]; then
git add -A
git commit -m "Version $new_vers"
fi