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