forked from pinterest/ktlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.announce
executable file
·65 lines (50 loc) · 2.18 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
58
59
60
61
62
63
64
65
#!/bin/bash -e
# project.version
if [ "$VERSION" == "" ]; then exit 1; fi
if [ "$1" = "-y" ]; then
AUTOACCEPT=true
else
AUTOACCEPT=false
fi
PREVIOUS_VERSION=$(grep -E "## \[[0-9]+\.[0-9]+\.[0-9]+\]" CHANGELOG.md | awk '{gsub(/\[|\]/,"",$2); print $2}' | awk 'NR == 2')
if [ -z "$PREVIOUS_VERSION" ]; then
echo "Cannot find PREVIOUS_VERSION."
exit 1
fi
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 docs/install/cli.md docs/install/integrations.md)" != "" ]; then
echo "ERROR: To proceed, cli.md and integrations.md must not contain uncommitted changes"
# ask for user confirmation
if [[ "$AUTOACCEPT" = false ]]; then
read -p "revert changes? (y/n)? " -n 1 -r; echo; if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; else git checkout docs/install/cli.md docs/install/integrations.md; fi
else
echo "Reverting changes to cli.md and integrations.md"
git checkout docs/install/cli.md docs/install/integrations.md
fi
fi
escape_for_sed() { echo "$1" | sed -e 's/[]\/$*.^|[]/\\&/g'; }
# update Docs
sed -i -e "s/$PREVIOUS_VERSION/$VERSION/g" docs/install/cli.md
sed -i -e "s/$PREVIOUS_VERSION/$VERSION/g" docs/install/integrations.md
git --no-pager diff docs/install/cli.md docs/install/integrations.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
BRANCH="$VERSION-update-refs"
if [ "$(git show-ref refs/heads/$BRANCH)" != "" ]; then
echo "ERROR: Branch $BRANCH already exists."
if [[ "$AUTOACCEPT" = false ]]; then
read -p "Delete local branch? (y/n)? " -n 1 -r; echo; if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; else git branch -D $BRANCH; fi
else
echo "Deleting local branch $BRANCH"
git branch -D $BRANCH
fi
fi
# Make a separate branch because master branch is protected
git checkout --track origin/master -b $BRANCH && git commit -m "$COMMIT_MESSAGE" docs/install/cli.md docs/install/integrations.md && git push origin $BRANCH