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
# assume we are called from the project home
project_home=$PWD

Vincent Hatakeyama
committed
project_name_from_home=$(basename $project_home)
project_name=${DOC_PROJECT_NAME:-${CI_PROJECT_NAME:-${DRONE_REPO_NAME:-$project_name_from_home}}}
languages=(${LANGUAGES:-en})
format=html
out_dir=${project_home}/_build/$format
error=0
autoload colors && colors
for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do
eval $COLOR='$fg_no_bold[${(L)COLOR}]'
eval BOLD_$COLOR='$fg_bold[${(L)COLOR}]'
done
eval RESET='$reset_color'
pushd $project_home

Vincent Hatakeyama
committed
if type "python3" > /dev/null;
then

Vincent Hatakeyama
committed
odoo_modules="$(python3 -B -c "import configparser ; c = configparser.ConfigParser() ; c.read('${project_home}/setup.cfg') ; print (c.has_option('odoo_scripts', 'modules') and ' '.join(c.get('odoo_scripts', 'modules').split()) or '')")"

Vincent Hatakeyama
committed
else

Vincent Hatakeyama
committed
odoo_modules="$(python2 -B -c "import ConfigParser ; c = ConfigParser.SafeConfigParser() ; c.read('${project_home}/setup.cfg') ; print (c.has_option('odoo_scripts', 'modules') and ' '.join(c.get('odoo_scripts', 'modules').split()) or '')")"

Vincent Hatakeyama
committed
fi
# 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
for module_path in $(eval echo $odoo_modules) ;

Vincent Hatakeyama
committed
do
if [[ -d "$module_path" ]] ; then
echo ""
echo "${YELLOW}INFO${RESET} - Documentation for ${BOLD_WHITE}$module_path${RESET}"
pushd $module_path
module=$(basename $module_path)

Vincent Hatakeyama
committed
has_doc=""
if [ -e ".git" ]; then
branch="$(git rev-parse --abbrev-ref HEAD)"
elif [ -e ".hg" ]; then
branch="$(hg identify --branch)"
else
echo "${RED}WARN${RESET} - Branch name not found"
branch="default"
fi
for doc_dir in doc docs ; do
if [[ -d $doc_dir && -e $doc_dir/Makefile ]]; then
echo "${YELLOW}INFO ${RESET} - Branch name: $branch"
has_doc=True
echo ${YELLOW}INFO ${RESET} - 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
echo "${YELLOW}INFO ${RESET} - found _build/$format/$language/, copying from there"
cp --archive --recursive "_build/$format/$language/." "$dest_dir"
else
# this is only because some modules Makefile is not up to date
echo "${YELLOW}INFO ${RESET} - no _build/$format/$language/ found, copying from _build/$format/"
cp --archive --recursive "_build/$format/." "$dest_dir"
fi
echo ${RED}ERROR${RESET} - 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 "${YELLOW}INFO ${RESET} - running autotodo again from different path $superproject_modules_doc/$module for ${project_home}/${module_path}"
pushd "$superproject_modules_doc/$module"
./autotodo.py $(realpath --relative-to="." "${project_home}/${module_path}") .py TODO,FIXME,XXX
popd
fi
# TODO translation will not work when copying like that.
fi
done
if [[ -z "$has_doc" ]] ; then
echo ${RED}WARN${RESET} - Missing documentation for $module_path
fi
popd
fi
done
# Generate super project documentation
echo ""
echo "${YELLOW}INFO ${RESET} - ${WHITE_BOLD}Super project${RESET} documentation generation"

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

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

Vincent Hatakeyama
committed
fi

Vincent Hatakeyama
committed
echo "${YELLOW}INFO ${RESET} - 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
echo "${YELLOW}INFO ${RESET} - Documentation generation done for $doc_dir (superproject), copy to $dest_dir"
mkdir -p $dest_dir
cp --recursive --archive _build/$format/$language/. $dest_dir
echo "${RED}FATAL${RESET} - Documentation generation failed for $doc_dir (superproject)"
fi
done
popd

Vincent Hatakeyama
committed
fi
if [[ $module_error -gt 0 ]]; then
echo "${RED}ERROR${RESET} - $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
[[ ! -e ${doc_dir}/_build/warnings.out ]] && 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" >> metrics
exit $error