forked from pinterest/ktlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.announce
executable file
·57 lines (40 loc) · 1.71 KB
/
.announce
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
#!/bin/bash -e
# settings.servers.github.privateKey
if [ "$GITHUB_TOKEN" == "" ]; then exit 1; fi
# project.version
if [ "$VERSION" == "" ]; then exit 1; fi
if [ "$1" = "-y" ]; then
AUTOACCEPT=true
else
AUTOACCEPT=false
fi
PREVIOUS_VERSION=$(cat CHANGELOG.md | grep -E "## \[\d+[.]\d+[.]\d+\]" | awk '{gsub(/\[|\]/,"",$2); print $2}' | awk 'NR == 2')
if [ "$VERSION" == "$PREVIOUS_VERSION" ]; then
echo "VERSION $VERSION equal to PREVIOUS_VERSION $PREVIOUS_VERSION"
exit 1
fi
echo "Announcing $PREVIOUS_VERSION -> $VERSION"
COMMIT_MESSAGE="Updated refs to latest ($VERSION) release"
if [ "$(git status --porcelain=v1 README.md)" != "" ]; then
echo "To proceed, README.md must not contain uncommitted changes"
exit 1
fi
escape_for_sed() { echo $1 | sed -e 's/[]\/$*.^|[]/\\&/g'; }
# update readme.md
sed -i "" "s/$(escape_for_sed $PREVIOUS_VERSION)/$(escape_for_sed $VERSION)/g" README.md
git --no-pager diff README.md
# ask for user confirmation
if [[ "$AUTOACCEPT" = false ]]; then
read -p "commit & push (y/n)? " -n 1 -r; echo; if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi
fi
git commit -m "$COMMIT_MESSAGE" README.md && git push origin master
# update ktlint.github.io
CHECKOUT_DIR=$(mktemp -d /tmp/ktlint.github.io.XXXXXX)
git clone https://${GITHUB_TOKEN}@github.com/ktlint/ktlint.github.io.git $CHECKOUT_DIR
sed -i "" "s/$(escape_for_sed $PREVIOUS_VERSION)/$(escape_for_sed $VERSION)/g" $CHECKOUT_DIR/index.html
(cd $CHECKOUT_DIR && git --no-pager diff index.html)
# ask for user confirmation
if [[ "$AUTOACCEPT" = false ]]; then
read -p "commit & push (y/n)? " -n 1 -r; echo; if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi
fi
(cd $CHECKOUT_DIR && git commit -m "$COMMIT_MESSAGE" index.html && git push origin master)