Skip to content

Instantly share code, notes, and snippets.

@flixr
Last active February 9, 2019 15:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flixr/4989376 to your computer and use it in GitHub Desktop.
Save flixr/4989376 to your computer and use it in GitHub Desktop.
script to automatically update doxygen and module docs for paparazzi
#!/bin/bash
PAPARAZZI_HOME="/home/pprz-docbot/paparazzi"
PAPARAZZI_DOC_REPO="/home/pprz-docbot/paparazzi.github.com"
doc_branches=(master v4.0 v4.2 v5.0 v5.2 v5.4 v5.6 v5.8 v5.10 v5.12 v5.14)
need_updates=()
error=0
begin=$(date +"%s")
echo "$(date) fetching latest code"
echo "------------------------------------------"
# go to the paparazzi repo and fetch the latest code from github
cd $PAPARAZZI_HOME
git remote update -p
# check if we need to regenerate docs for the branches to be documented
for branch in "${doc_branches[@]}"
do
echo "Checking branch $branch"
# check if local branch already exists
git show-ref --quiet --verify refs/heads/"$branch"
if (( "$?" != 0 )) ; then
echo "Docs for $branch don't exist yet..."
need_updates+=($branch)
else
# check if branch needs updates
if [ `git rev-list --max-count=1 origin/"$branch"` == `git rev-list --max-count=1 "$branch"` ];
then
echo "Docs for $branch up-to-date."
else
echo "Docs for $branch need to be regenerated..."
need_updates+=($branch)
fi
fi
echo ""
done
#
# regenerate and push docs if needed
#
if (( ${#need_updates[@]} > 0 )) ;
then
echo "------------------------------------------"
echo "$(date)"
echo "Updating docs for: "${need_updates[@]}" ..."
# reset paparazzi.github.com to current master
echo "Resetting paparazzi.github.com to current master"
cd $PAPARAZZI_DOC_REPO
git fetch
git checkout master -f
git reset --hard origin/master
git clean -fdx
cd $PAPARAZZI_HOME
for branch in "${need_updates[@]}"
do
echo "------------------------------------------"
echo "$(date) Generating docs for $branch"
echo "Checking out and resetting $branch branch"
# ok, we want to reset the local branch to the commit on github repo
# merging would be fine in most cases (would bee a feed-forward merge),
# unless someone force-pushed to the branch, so rather reset
git checkout $branch -f
git reset --hard origin/$branch
# init and update the submodules
git submodule update --init --recursive
branch_dir=$branch
# master branch is in latest dir
if [ $branch == "master" ] ; then
branch_dir="latest"
fi
output_dir="$PAPARAZZI_DOC_REPO/$branch_dir"
echo "$(date) Cleaning all docs in directory $output_dir"
# we need to remove all files in <branch_dir>, since doxygen won't delete
# docs for files that don't exist anymore
# this will result in doxygen regenerating everything and taking longer,
# so maybe only delete files older than time when doxygen was run afterwards?
rm -rf $output_dir
# clean dir with generated module docs, regenerate if available
rm -rf $PAPARAZZI_DOC_REPO/doc/manual/generated
if [ -f sw/tools/doxygen_gen/gen_modules_doc.py ] ; then
echo "------------------------------------------"
echo "$(date) Generating ducumentation for modules from xml files."
./sw/tools/doxygen_gen/gen_modules_doc.py -pv
fi
if [ -f sw/tools/doxygen_gen/gen_messages_doc.py ] ; then
echo "------------------------------------------"
echo "$(date) Generating documentation for messages from xml files."
./sw/tools/doxygen_gen/gen_messages_doc.py -pv
fi
# generate docs for master from the main dir
# will create $PAPARAZZI_DOC_REPO/$branch_dir and write all the files there
echo "$(date) running doxygen from $branch branch"
echo "------------------------------------------"
( cat Doxyfile ; echo "OUTPUT_DIRECTORY=$output_dir" ; echo "HTML_OUTPUT=./" ; echo "PROJECT_NUMBER=$(./paparazzi_version)" ; echo "QUIET=YES") | doxygen -
done
# go into the paparazzi.github.com repo
cd $PAPARAZZI_DOC_REPO
# add new files, update changed files and removed files no longer in
# the working tree
echo "------------------------------------------"
echo "$(date) Adding files..."
echo "------------------------------------------"
git add . --all
updated_branches=$(printf ", %s" "${need_updates[@]}")
message="Generated doxygen docs for "${updated_branches:2}" from cron job"
echo "------------------------------------------"
echo "$(date) Comitting and pushing..."
echo "------------------------------------------"
# finally push the newly generated docs to paparazzi.github.com
# check if last commit was only updating generated docs, if yes amend
LAST_MESSAGE="$(git log -1 --pretty=%B)"
if [[ $LAST_MESSAGE == "Generated doxygen docs for"* ]] ; then
echo "amending to last commit..."
git commit --amend --reset-author -m "$message"
else
git commit -m "$message"
fi
# force push since we might have amended
git push -f
let error+=$?
# garbage collect / repack repo
echo "------------------------------------------"
echo "$(date) Git garbage collect / repack repo"
echo "------------------------------------------"
#git reflog expire --expire=now --all
git gc --prune=all
let error+=$?
echo "------------------------------------------"
echo "$(date)"
if (( "$error" == 0 )); then
echo "Done. $message"
else
echo "Error!!!"
fi
echo "------------------------------------------"
fi
end=$(date +"%s")
elapsed=$(($end-$begin))
echo "elapsed: $(($elapsed / 3600)) hours $((($elapsed / 60) % 60)) minutes and $(($elapsed % 60)) seconds"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment