Skip to content
Snippets Groups Projects
create_documentation 6.89 KiB
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's avatar
Vincent Hatakeyama committed
# Version 20.6.0
source $here/odoo_scripts_common
project_name=${DOC_PROJECT_NAME:-${CI_PROJECT_NAME:-${DRONE_REPO_NAME:-project_name}}}

format=html
out_dir=${project_home}/_build/$format

module_error=0
# Remark: when running the CI, the configuration values from modules might be empty.
# (they are moved in odoo_modules instead)
odoo_modules=("${(@s/ /)$(read_odoo_scripts_expandable_configuration_key modules " ")}")

pushd $project_home

# 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
# Add odoo_modules copied by docker_build_copy and only path available in CI
if [[ -d odoo_modules ]] && [[ -z "$(find odoo_modules -maxdepth 0 -type d -empty 2>/dev/null)" ]]; then
    addons_path+=($(readlink -f odoo_modules))
    typeset -a dirs
    dirs=(odoo_modules/*/)
    dirs=("${dirs[@]%/}")
    for dir in $dirs; do
    odoo_modules+=($(readlink -f $dir))
    done
    unset dirs
fi
export ODOO_ADDONS_PATH=${(j:,:)addons_path}
unset addons_path
# 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
# Generate all modules documentation
    if [[ -d "$module_path" ]] ; then
        echo "${INFO} Documentation for ${BOLD_WHITE}$module_path${RESET}"
        pushd $module_path
        module=$(basename $module_path)
            if [[ -d $doc_dir && -e $doc_dir/Makefile ]]; then
                if [ -e ".git" ] || [ -e "../.git" ]; then
                    branch="$(git rev-parse --abbrev-ref HEAD)"
                elif [ -e ".hg" ]; then
                    branch="$(hg identify --branch)"
                else
                    echo "${WARN} Branch name not found"
                    branch="default"
                fi
                echo ${INFO} Makefile found in $module_path/$doc_dir
                # TODO read languages value from Makefile (at least available ones)
                    make $format LANGUAGE=${language} BUILDDIR=_build
                        dest_dir=$out_dir/$module/$language/$branch
                        echo ${GREEN}OK${RESET}    - Documentation generation done for $module_path/$doc_dir, copy to $dest_dir
                        mkdir -p $dest_dir
                        if [[ -d "_build/$format/$language" ]];
                        then
                            echo "${INFO} found _build/$format/$language/, copying from there"
                            cp --archive --recursive "_build/$format/$language/." "$dest_dir"
                        else
                            # 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
                        echo ${WARN} Documentation generation failed for $module_path/$doc_dir
                        ((module_error++))
                    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
# Generate super project documentation
echo "${INFO} ${WHITE_BOLD}Super project${RESET} documentation generation"
if [ -n "$CI_COMMIT_HG_BRANCH" ]; then
    branch="$CI_COMMIT_HG_BRANCH"
elif [ -n "$CI_COMMIT_BRANCH" ]; then
    branch="$CI_COMMIT_BRANCH"
elif [ -e ".git" ]; then
    branch="$(git rev-parse --abbrev-ref HEAD)"
elif [ -e ".hg" ]; then
    branch="$(hg id -b)"
else
    echo "${WARN} Super project branch name not found, using default"
    branch="default"
echo "${INFO} Super project branch name: $branch"
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"
                dest_dir=$out_dir/$project_name/$language/$branch
                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
                echo "${FATAL} Documentation generation failed for $doc_dir (superproject)"
if [[ $module_error -gt 0 ]]; then
    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
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
    for doc_dir in doc docs; do
        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
Vincent Hatakeyama's avatar
Vincent Hatakeyama committed
    done