Newer
Older
#!/bin/zsh
# vim: set shiftwidth=4 softtabstop=4:
#
# This script generates documentation in all submodules.
# It needs:
# - openerp to be installed

Vincent Hatakeyama
committed
here=$(dirname $0)
source $here/common

Vincent Hatakeyama
committed
project_name=${DOC_PROJECT_NAME:-${CI_PROJECT_NAME:-${DRONE_REPO_NAME:-project_name}}}
languages=(${LANGUAGES:-en})
format=html
out_dir=${project_home}/_build/$format
error=0

Vincent Hatakeyama
committed
typeset -a odoo_modules
odoo_modules=("${(@s/ /)$(read_odoo_scripts_expandable_configuration_key modules " ")}")

Vincent Hatakeyama
committed
# set addons path
typeset -a addons_path
addons_path=()
for module_path in $odoo_modules ;
do
module_dir=$(dirname $module_path)
if (($addons_path[(Ie)$module_dir]));
then
# already in
else
addons_path+=($module_dir)
fi
unset module_dir
done
export ODOO_ADDONS_PATH=${(j:,:)addons_path}
unset addons_path

Vincent Hatakeyama
committed
# search where to copy modules documentation
for doc_dir in doc docs; do
if [[ -d "$doc_dir" ]] ; then
superproject_modules_doc=$project_home/$doc_dir/modules
[[ -d $superproject_modules_doc ]] || mkdir $superproject_modules_doc
fi
done
# Generate all modules documentation

Vincent Hatakeyama
committed
for module_path in $odoo_modules ;

Vincent Hatakeyama
committed
do
if [[ -d "$module_path" ]] ; then

Vincent Hatakeyama
committed
echo "${INFO} Documentation for ${BOLD_WHITE}$module_path${RESET}"
pushd $module_path
module=$(basename $module_path)

Vincent Hatakeyama
committed
has_doc=""
if [ -e ".git" ] || [ -e "../.git" ]; then
branch="$(git rev-parse --abbrev-ref HEAD)"
elif [ -e ".hg" ]; then
branch="$(hg identify --branch)"
else

Vincent Hatakeyama
committed
echo "${WARN} Branch name not found"
branch="default"
fi
for doc_dir in doc docs ; do
if [[ -d $doc_dir && -e $doc_dir/Makefile ]]; then

Vincent Hatakeyama
committed
echo "${INFO} Branch name: $branch"
has_doc=True

Vincent Hatakeyama
committed
echo ${INFO} Makefile found in $module_path/$doc_dir
pushd $doc_dir
# TODO read languages value from Makefile (at least available ones)
for language in $languages ; do
make $format LANGUAGE=${language} BUILDDIR=_build
if [[ $? -eq 0 ]] ; then
dest_dir=$out_dir/$module/$language/$branch
echo ${GREEN}OK${RESET} - Documentation generation done for $module_path/$doc_dir, copy to $dest_dir
if [[ -d "_build/$format/$language" ]];
then

Vincent Hatakeyama
committed
echo "${INFO} found _build/$format/$language/, copying from there"
cp --archive --recursive "_build/$format/$language/." "$dest_dir"
else

Vincent Hatakeyama
committed
# this is only because some modules Makefile are not up to date
echo "${INFO} no _build/$format/$language/ found, copying from _build/$format/"
cp --archive --recursive "_build/$format/." "$dest_dir"
fi

Vincent Hatakeyama
committed
echo ${WARN} Documentation generation failed for $module_path/$doc_dir
fi
done
popd
# copy documentation in super project
rsync --recursive --copy-links --perms --times --group --owner $doc_dir/ "$superproject_modules_doc/$module"
# generate autotodo for each module (to update pathes)
if [[ -e $doc_dir/autotodo.py ]] ; then
echo "${INFO} running autotodo again from different path $superproject_modules_doc/$module for ${module_path}"
pushd "$superproject_modules_doc/$module"
./autotodo.py $(realpath --relative-to="." "${module_path}") .py TODO,FIXME,XXX
# TODO translation will not work when copying like that.
fi
done
if [[ -z "$has_doc" ]] ; then
echo ${WARN} Missing documentation for $module_path
fi
popd
fi
done
# Generate super project documentation

Vincent Hatakeyama
committed
echo "${INFO} ${WHITE_BOLD}Super project${RESET} documentation generation"

Vincent Hatakeyama
committed
# determine branch name
if [ -n "$CI_COMMIT_HG_BRANCH" ]; then
branch="$CI_COMMIT_HG_BRANCH"
elif [ -n "$CI_COMMIT_BRANCH" ]; then
branch="$CI_COMMIT_BRANCH"

Vincent Hatakeyama
committed
elif [ -e ".git" ]; then
branch="$(git rev-parse --abbrev-ref HEAD)"
elif [ -e ".hg" ]; then
branch="$(hg id -b)"
else

Vincent Hatakeyama
committed
echo "${WARN} Super project branch name not found, using default"

Vincent Hatakeyama
committed
fi

Vincent Hatakeyama
committed
echo "${INFO} Super project branch name: $branch"

Vincent Hatakeyama
committed
for doc_dir in doc docs; do
if [[ -d "$doc_dir" ]] ; then
pushd $doc_dir
for language in $languages ; do
# create _build to output warnings into it
[[ -d _build ]] || mkdir _build/
make $format LANGUAGE=${language} BUILDDIR=_build SPHINXOPTS="-w _build/warnings.out"

Vincent Hatakeyama
committed
if [[ $? -eq 0 ]] ; then
dest_dir=$out_dir/$project_name/$language/$branch

Vincent Hatakeyama
committed
echo "${INFO} Documentation generation done for $doc_dir (superproject), copy to $dest_dir"
mkdir -p $dest_dir
cp --recursive --archive _build/$format/$language/. $dest_dir

Vincent Hatakeyama
committed
echo "${FATAL} Documentation generation failed for $doc_dir (superproject)"
fi
done
popd

Vincent Hatakeyama
committed
fi
if [[ $module_error -gt 0 ]]; then

Vincent Hatakeyama
committed
echo "${WARN} $module_error module(s) with errors"
fi
# create a metrics file
if [[ "$CI" = "true" ]]; then
echo -e "# HELP odoo_scripts_create_documentation_module_error Number of module in error.\n# TYPE odoo_scripts_create_documentation_module_error gauge\nodoo_scripts_create_documentation_module_error ${module_error}\n" > metrics
if [[ -e ${doc_dir}/_build/warnings.out ]] ; then
echo -e "# HELP odoo_scripts_create_documentation_superproject_warnings Number of warnings in superproject.\n# TYPE odoo_scripts_create_documentation_superproject_warnings gauge\nodoo_scripts_create_documentation_superproject_warnings $(grep --count WARNING ${doc_dir}/_build/warnings.out)\n# EOF\n" >> metrics
exit $error