This repository has been archived by the owner on Mar 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
release.sh
executable file
·97 lines (77 loc) · 2.51 KB
/
release.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
#!/usr/bin/env bash
# This script makes everything ready for release. It doesn't push any changes, but makes everything ready and outputs a command
# for you to push changes to the repository.
#
# USAGE:
# cd okctl
# ./release.sh
#
# For nicer git diff, install https://github.com/dandavison/delta
function get_next_version() {
VERSION="$1"
VERSION="${VERSION#[vV]}"
VERSION_MAJOR="${VERSION%%\.*}"
VERSION_MINOR="${VERSION#*.}"
VERSION_MINOR="${VERSION_MINOR%.*}"
VERSION_PATCH="${VERSION##*.}"
(( NEXT_PATCH=VERSION_PATCH+1 ))
echo "$VERSION_MAJOR.$VERSION_MINOR.$NEXT_PATCH"
}
if [[ $(pwd) != */okctl* ]]; then
echo ERROR: You must be in an okctl repository
exit 1
fi
if [[ -n $(git status --porcelain) ]]; then
echo Dirty git status. Clean up before retrying.
exit 1
fi
if ! command -v bat &> /dev/null
then
echo 'bat' could not be found. Install before retrying.
exit
fi
git checkout master
git pull --rebase
CURRENT_VERSION_RAW=$(git tag | sort -V | tail -1 | cut -c2-30)
RELEASE_VERSION_RAW=$(get_next_version "$CURRENT_VERSION_RAW")
RELEASE_VERSION="v$RELEASE_VERSION_RAW"
NEXT_VERSION_RAW=$(get_next_version "$RELEASE_VERSION_RAW")
echo
echo CURRENT_VERSION_RAW: $CURRENT_VERSION_RAW
echo RELEASE_VERSION_RAW: $RELEASE_VERSION_RAW
echo NEXT_VERSION_RAW: $NEXT_VERSION_RAW
echo
cat <<EOF > docs/release_notes/$NEXT_VERSION_RAW.md
# Release $NEXT_VERSION_RAW
## Features
## Bugfixes
## Changes
## Other
EOF
(bat docs/release_notes/$RELEASE_VERSION_RAW.md || cat docs/release_notes/$RELEASE_VERSION_RAW.md)
git add docs/release_notes/$NEXT_VERSION_RAW.md
git diff --cached
git commit -m "✅ Add changelog file for $NEXT_VERSION_RAW"
git tag $RELEASE_VERSION
if [[ $? != 0 ]]; then
echo "Git tag failed"
exit 1
fi
echo
echo ---------------------------------------------------------------------
echo "* Verify that docs/release_notes/$RELEASE_VERSION_RAW.md looks ok"
echo "* Verify that git log looks OK:"
echo
git log --graph --pretty=format:'%Cred%h%Creset |%Cblue%>(12)%cr%Creset | %s%C(auto)%d%Creset %C(dim italic)%an%Creset' --abbrev-commit -2
echo
echo ""
echo "Running dry run of git push"
echo "git push --dry-run --atomic origin master $RELEASE_VERSION"
git push --dry-run --atomic origin master $RELEASE_VERSION
echo
echo "To release, run"
echo "git push --atomic origin master $RELEASE_VERSION"
echo
echo "Or abort with:"
echo "git tag -d $RELEASE_VERSION && git reset --hard origin/master"
echo ---------------------------------------------------------------------