forked from pinterest/ktlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.announce
executable file
·44 lines (28 loc) · 1.49 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
#!/bin/bash -e
# settings.servers.github.privateKey
if [ "$GITHUB_TOKEN" == "" ]; then exit 1; fi
# project.version
if [ "$VERSION" == "" ]; then exit 1; fi
PREVIOUS_VERSION=$(cat CHANGELOG.md | grep -oP "## \[\d+[.]\d+[.]\d+\]" | awk '{gsub(/\[|\]/,"",$2); print $2}' | awk 'NR == 2')
if [ "$VERSION" == "$PREVIOUS_VERSION" ]; then 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
read -p "commit & push (y/n)? " -n 1 -r; echo; if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; 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
read -p "commit & push (y/n)? " -n 1 -r; echo; if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi
(cd $CHECKOUT_DIR && git commit -m "$COMMIT_MESSAGE" index.html && git push origin master)