Backport tox checkers from master
[csit.git] / resources / libraries / bash / entry / check / doc_verify.sh
1 # Copyright (c) 2020 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 set -xeuo pipefail
15
16 # This file should be executed from tox, as the assumend working directory
17 # is different from where this file is located.
18 # This file does not have executable flag nor shebang,
19 # to dissuade non-tox callers.
20
21 # "set -eu" handles failures from the following two lines.
22 BASH_CHECKS_DIR="$(dirname $(readlink -e "${BASH_SOURCE[0]}"))"
23 BASH_FUNCTION_DIR="$(readlink -e "${BASH_CHECKS_DIR}/../../function")"
24 source "${BASH_FUNCTION_DIR}/common.sh" || {
25     echo "Source failed." >&2
26     exit 1
27 }
28
29 common_dirs || die
30 log_file="$(pwd)/doc_verify.log" || die
31
32 # Pre-cleanup.
33 rm -f "${log_file}" || die
34 rm -f "${DOC_GEN_DIR}/csit.docs.tar.gz" || die
35 rm -rf "${DOC_GEN_DIR}/_build" || die
36
37 # Documentation generation.
38 # Here we do store only stderr to file while stdout (inlcuding Xtrace) is
39 # printed to console. This way we can track increased errors in future.
40 # We do not need to do trap as the env will be closed after tox finished the
41 # task.
42 exec 3>&1 || die
43 export BASH_XTRACEFD="3" || die
44
45 pushd "${DOC_GEN_DIR}" || die
46 source ./run_doc.sh ${GERRIT_BRANCH:-local} 2> ${log_file} || true
47 popd || die
48
49 if [[ ! -f "${log_file}" ]] || [[ -s "${log_file}" ]]; then
50     # Output file not exists or is non empty.
51     warn
52     warn "Doc verify checker: FAIL"
53     exit 1
54 fi
55
56 warn
57 warn "Doc verify checker: PASS"