-
Notifications
You must be signed in to change notification settings - Fork 0
/
release
executable file
·69 lines (53 loc) · 1.81 KB
/
release
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
#!/bin/bash
set -euo pipefail
# If you have a PGP key set up for commit signing, do a one-off signing of an
# empty string to make sure gpg-agent has the key in memory
preauth_pgp_signature() {
if [[ $(git config --get user.signingkey 2> /dev/null) != '' ]] ; then
echo '' | gpg --sign > /dev/null
fi
}
run() {
release_type=${1:-other}
if [[ $release_type != 'major' ]] &&
[[ $release_type != 'minor' ]] &&
[[ $release_type != 'patch' ]]
then
echo 'Usage: release [major|minor|patch]'
exit 1
fi
if [[ $(git rev-parse --abbrev-ref HEAD) != 'main' ]] ; then
echo 'Cannot release from a branch other than main'
exit 1
fi
if [[ $(git describe --exact-match --tags HEAD 2> /dev/null) ]] ; then
echo 'Current commit is already a tag commit; not releasing it again'
exit 1
fi
if [[ $(git status --porcelain) != '' ]] ; then
echo 'Cannot release with uncommitted changes'
exit 1
fi
preauth_pgp_signature
git fetch origin --tags
git pull --ff-only origin main
npm version $release_type
git push origin main --follow-tags
git checkout -B production
git pull --ff-only origin production
git merge --ff-only main
git push origin production
git checkout main
local recent_tags=$(git for-each-ref --sort=-creatordate --format '%(refname:lstrip=2)' refs/tags | head -n 2)
local previous_tag=$(echo "$recent_tags" | tail -n 1)
local this_tag=$(echo "$recent_tags" | head -n 1)
if [[ "$previous_tag" != '' && $this_tag != '' ]]; then
echo "ℹ️ Changes in this release (please share a changelog with the team):"
echo
echo $(git show-ref -s --abbrev $previous_tag)...$(git show-ref -s --abbrev $this_tag) $this_tag
echo
git --no-pager log --pretty=tformat:'- %ad (%an) %s' --date=short $previous_tag..$this_tag^
echo
fi
}
run "$@"