forked from apache/bahir-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-doc.sh
executable file
·187 lines (153 loc) · 6.47 KB
/
update-doc.sh
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to you under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
function exit_with_usage {
cat << EOF
USAGE: update-doc.sh [spark] [flink]
This script generates the documentation for the individual Bahir (Spark) and
Bahir-Flink modules from the contents of the respective module's README.md
files as found in the Bahir and Bahir-Flink source repositories.
bahir (source repo) bahir-website
. └─site
. └─docs
. └─spark
├─sql-streaming-mqtt └─current
│ └─README.md ─────> ├─spark-sql-streaming-mqtt.md
├─streaming-akka │
│ └─README.md ─────> ├─spark-streaming-akka.md
├─streaming-mqtt │
│ └─README.md ─────> ├─spark-streaming-mqtt.md
├─streaming-twitter │
│ └─README.md ─────> ├─spark-streaming-twitter.md
└─streaming-zeromq │
└─README.md ─────> └─spark-streaming-zeromq.md
bahir-flink (source repo) bahir-website
. └─site
. └─docs
. └─flink
├─sql-streaming-mqtt └─current
│ └─README.md ─────> ├─flink-streaming-activemq.md
├─streaming-akka │
│ └─README.md ─────> ├─flink-streaming-akka.md
├─streaming-mqtt │
│ └─README.md ─────> ├─flink-streaming-flume.md
├─streaming-twitter │
│ └─README.md ─────> ├─flink-streaming-netty.md
└─streaming-zeromq │
└─README.md ─────> └─flink-streaming-redis.md
Page header with license text comes from the respective template files
under:
site/docs/spark/templates
site/docs/flink/templates
EOF
exit 1
}
if [[ "$@" =~ "-h" ]]; then
exit_with_usage
fi
REPOS="${@:-'spark flink'}"
set -e
BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SPARK_WEBSITE_TEMPLATES_DIR=site/docs/spark/templates
SPARK_WEBSITE_DOC_DIR=site/docs/spark/current
SPARK_REPO_NAME=bahir
SPARK_BAHIR_SOURCE_DIR=target/$SPARK_REPO_NAME
FLINK_WEBSITE_TEMPLATES_DIR=site/docs/flink/templates
FLINK_WEBSITE_DOC_DIR=site/docs/flink/current
FLINK_REPO_NAME=bahir-flink
FLINK_BAHIR_SOURCE_DIR=target/$FLINK_REPO_NAME
function checkout_code {
# Checkout code
cd "$BASE_DIR" # make sure we're in the base dir
rm -rf target
mkdir target
cd target
git clone "https://git-wip-us.apache.org/repos/asf/$1.git" --quiet
cd "$1"
git checkout "$GIT_REF"
git_hash=$(git rev-parse --short HEAD)
echo "Checked out $1 git hash $git_hash"
git clean -d -f -x
cd "$BASE_DIR" # return to base dir
}
function update_docs {
WEBSITE_TEMPLATES_DIR=$1
WEBSITE_DOC_DIR=$2
SOURCE_DIR=$3
shift 3
[ ! -d "$WEBSITE_DOC_DIR" ] && mkdir "$WEBSITE_DOC_DIR"
echo "Updating documents ..."
while [ $# -ne 0 ]; do
echo " $WEBSITE_DOC_DIR/$1.md <-- $SOURCE_DIR/$2/README.md"
rm -f "$WEBSITE_DOC_DIR/$1.md"
cp "$WEBSITE_TEMPLATES_DIR/$1.template" "$WEBSITE_DOC_DIR/$1.md"
cat "$SOURCE_DIR/$2/README.md" >> "$WEBSITE_DOC_DIR/$1.md"
shift 2
done
}
function check_version_strings {
if grep -q -r "[0-9]-SNAPSHOT" "$1"/*.md ; then
echo
echo "TODO: Replace '...-SNAPSHOT' version strings:"
echo
grep -r -n "[0-9]-SNAPSHOT" "$1"/*.md | sed 's/^/ /' | grep --color "[0-9.]*-SNAPSHOT"
echo
echo "i.e. to replace '2.1.0-SNAPSHOT' with '2.0.2' run the following command:"
echo
echo " perl -i -pe 's/2.1.0-SNAPSHOT/2.0.2/g' $1/*.md"
echo
else
echo
echo "Generated files:"
echo
ls "$1"/*.md | xargs -n1 | sed -e 's|'"$(pwd -P)"/'||g'
fi
}
function update_spark {
echo
echo "================= Updating Apache Spark Extension documents ================="
echo
checkout_code $SPARK_REPO_NAME
update_docs "$SPARK_WEBSITE_TEMPLATES_DIR" \
"$SPARK_WEBSITE_DOC_DIR" "$SPARK_BAHIR_SOURCE_DIR" \
spark-sql-cloudant sql-cloudant \
spark-sql-streaming-akka sql-streaming-akka \
spark-sql-streaming-mqtt sql-streaming-mqtt \
spark-streaming-akka streaming-akka \
spark-streaming-mqtt streaming-mqtt \
spark-streaming-pubsub streaming-pubsub \
spark-streaming-twitter streaming-twitter \
spark-streaming-zeromq streaming-zeromq
check_version_strings "$SPARK_WEBSITE_DOC_DIR"
}
function update_flink {
echo
echo "================= Updating Apache Flink Extension documents ================="
echo
checkout_code $FLINK_REPO_NAME
update_docs "$FLINK_WEBSITE_TEMPLATES_DIR" \
"$FLINK_WEBSITE_DOC_DIR" "$FLINK_BAHIR_SOURCE_DIR" \
flink-streaming-activemq flink-connector-activemq \
flink-streaming-akka flink-connector-akka \
flink-streaming-flume flink-connector-flume \
flink-streaming-netty flink-connector-netty \
flink-streaming-redis flink-connector-redis
check_version_strings "$FLINK_WEBSITE_DOC_DIR"
}
[[ "$REPOS" =~ "spark" ]] && update_spark
[[ "$REPOS" =~ "flink" ]] && update_flink
set +e