-
Notifications
You must be signed in to change notification settings - Fork 506
/
.announce
executable file
·116 lines (99 loc) · 3.75 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash -e
# project.version
if [ "$VERSION" == "" ]; then
echo "VERSION has not been set"
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"
DOCUMENTATION_DIR="documentation"
RELEASE_DOCS_DIR="${DOCUMENTATION_DIR}/release-latest"
SNAPSHOT_DOCS_DIR="${DOCUMENTATION_DIR}/snapshot"
if [ "$(git status --porcelain=v1 $DOCUMENTATION)" != "" ]; then
echo "ERROR: To proceed, the current branch must not contain uncommitted changes in directory '${DOCUMENTATION_DIR}'"
# ask for user confirmation
if [[ "$AUTOACCEPT" = false ]]; then
read -p "revert changes? (y/n)? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
git checkout ${DOCUMENTATION_DIR}
else
exit 1
fi
else
echo "Reverting changes in directory '${DOCUMENTATION_DIR}'"
git checkout ${DOCUMENTATION_DIR}
fi
fi
#escape_for_sed() { echo "$1" | sed -e 's/[]\/$*.^|[]/\\&/g'; }
# Make a separate branch because master branch is protected
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
# Checkout local master branch so that changes to this script can be tested without pushing the script to the remote branch
git checkout --track master -b $BRANCH
else
git checkout --track origin/master -b $BRANCH
fi
# update version number in snapshot docs
echo "Updating version numbers in (snapshot) installation documentation"
# On local machine (OSX) Use "sed -i '' ..." instead of "sed -i -e ..." as the latter creates a new file.
# On Github Action workflow the "sed -i -e ..." is required as otherwise it results in failure
# "can't read s/0.49.0/0.49.1/g: No such file or directory"
sed -i -e "s/$PREVIOUS_VERSION/$VERSION/g" ${SNAPSHOT_DOCS_DIR}/docs/install/cli.md
sed -i -e "s/$PREVIOUS_VERSION/$VERSION/g" ${SNAPSHOT_DOCS_DIR}/docs/install/integrations.md
git --no-pager diff ${DOCUMENTATION_DIR}
# ask for user confirmation before committing
if [[ "$AUTOACCEPT" = false ]]; then
read -p "Accept changes (y/n)? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
# Replace release documentation with current snapshot documentation.
echo "Replace release documentation with current snapshot documentation"
# Support removal of files which still exists in release docs but which are no longer present in snapshot docs
rm -rf ${RELEASE_DOCS_DIR}/docs/
cp -r ${SNAPSHOT_DOCS_DIR}/docs/ ${RELEASE_DOCS_DIR}/docs/
# Note that directory "${SNAPSHOT_DOCS_DIR}/overrides/" should not replace "${RELEASE_DOCS_DIR}/overrides/"
cp -r ${SNAPSHOT_DOCS_DIR}/mkdocs.yml ${RELEASE_DOCS_DIR}
# Add files which previously did not yet exists in the release docs but were present in the snapshot docs
git add --all
# Display sorted list of files changed but do not show contents as that could be a lot
git status --porcelain=v1 documentation | sort
# Commit and push changes
if [[ "$AUTOACCEPT" = false ]]; then
read -p "Commit and push changes (y/n)? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
git commit -m "Updated refs to latest ($VERSION) release"
git push origin $BRANCH