@ -2,88 +2,76 @@
echo " Repository name : $DRONE_REPO_NAME "
echo " Repository name : $DRONE_REPO_NAME "
echo " Repository owner: $DRONE_REPO_OWNER "
echo " Repository owner: $DRONE_REPO_OWNER "
echo
echo " Generator: $GENERATOR "
echo " Documentation place: $DOCUMENTATION_PLACE "
echo " Destination: $DESTINATION "
echo " Remove mode: $REMOVE_MODE "
echo
echo " Generating and deploying documentation for user $DRONE_REPO_OWNER and repository $DRONE_REPO_NAME "
echo " Generating and deploying documentation for user $DRONE_REPO_OWNER and repository $DRONE_REPO_NAME "
echo
help( ) {
help( ) {
cat <<EOF
cat <<EOF
usage: $0
usage: $0
environment variables:
-l --loc [ dir] location of the documentation sources root - required
GENERATOR = "[docusaurus|doxygen|mdbook|swagger]" -- generator to use. - required
-b --branch [ branch] pattern of branch names to deploy - optional
DOCUMENTATION_PLACE = "[dir]" -- location of the documentation sources root - required
-t --type [ docusaurus| doxygen| mdbook| swagger] type of documentation generator to use. - required
DESTINATION = "[dir]" -- path to where to put the documentation outputs in your repository' s CodeDoc space - optional, cannot be absolute !!
-d --dest [ dir] path to where to put the documentation outputs in your repository' s CodeDoc space - optional !! cannot be absolute !!
REMOVE_MODE = [ 0| 1| 2] -- 0: disable, 1: for this type of documentation only, 2: all your documentations ( /!\ use this command with caution!) - optional
EOF
EOF
exit 1
exit 1
}
}
BRANCH = ""
DEST = ""
while [ " $1 " ] ; do
case " $1 " in
"-b" | "--branch" )
BRANCH = " $2 "
shift 1
; ;
"-d" | "--dest" )
DEST = " $2 "
shift 1
; ;
"-l" | "--loc" )
DOC_DIR = " $2 "
shift 1
; ;
"-t" | "--type" )
GENERATOR_NAME = " $2 "
GENERATOR_SCRIPT = " /generators/ $GENERATOR_NAME .sh "
if [ ! -f " $GENERATOR_SCRIPT " ] ; then
echo " unknown generator type, please enter a valid generator ( $( ls /generators | cut -d "." -f1 | tr "\n" " " ) ) " >& 2
exit 1
fi
shift 1
; ;
*)
echo " unknown option $1 " >& 2
exit 1
; ;
esac
shift
done
if [ ! " $GENERATOR " ] || [ ! " $DOCUMENTATION_PLACE " ] || echo " $DESTINATION " | grep -E -q "^[\/].*" ; then
if [ ! " $GENERATOR _SCRIPT " ] || [ ! " $DOC _DIR " ] || echo " $DEST " | grep -E -q "^[\/].*" ; then
echo " $0 : bad usage " >& 2
echo " $0 : bad usage " >& 2
help
help
fi
fi
RELATIVE_PATH = $( echo " $DRONE_REPO_OWNER / $DRONE_REPO_NAME / $DEST / " | tr -s "/" )
export GENERATION_PATH = " /docs/ $GENERATOR "
if [ [ -n $BRANCH && ! $DRONE_BRANCH = ~ $BRANCH ] ] ; then
export RELATIVE_DOC_PATH = $( echo " $DRONE_REPO_OWNER / $DRONE_REPO_NAME / $DESTINATION / " | tr -s "/" )
echo " ignoring deploy step since current branch doesn't match $BRANCH "
exit
fi
. " $GENERATOR_SCRIPT "
generate " $DOC_DIR " # generates doc using the wanted generator
update_nginx_server( ) {
SERVER_TARGET = " /usr/share/nginx/html/ $RELATIVE_PATH "
local SERVER_TARGET = " /usr/share/nginx/html/ $RELATIVE_DOC_PATH "
# launches rsync in archive, verbose and compression mode
# launches rsync in archive, verbose and compression mode
# creates target directory ($SERVER_TARGET) on server
# creates target directory ($SERVER_TARGET) on server
# then sends generated files into the server directory
# then sends generated files into the server directory
# rsync -avz -I \
rsync -avz -I \
# --rsync-path="mkdir -p \"$SERVER_TARGET\" && rsync" \
--rsync-path= " mkdir -p \" $SERVER_TARGET \" && rsync " \
# -e "ssh -o StrictHostKeyChecking=no" \
-e "ssh -o StrictHostKeyChecking=no" \
# --delete "$GENERATION_PATH" root@nginx:"$SERVER_TARGET"
--delete " $GEN_PATH " root@nginx:" $SERVER_TARGET "
echo
echo " GENERATION_PATH: $GENERATION_PATH "
echo " RELATIVE_DOC_PATH: $RELATIVE_DOC_PATH "
echo " SERVER_TARGET: $SERVER_TARGET "
}
compute_remove( ) {
[ $REMOVE_MODE -eq 0 ] || [ -z $REMOVE_MODE ] && return
[ $REMOVE_MODE -eq 1 ] && ( rm -Rf " $GENERATION_PATH " ; mkdir -p " $GENERATION_PATH " )
[ $REMOVE_MODE -eq 2 ] && ( rm -Rf "/docs" ; mkdir -p "/docs" )
[ $REMOVE_MODE -lt 0 ] || [ $REMOVE_MODE -gt 2 ] && \
( echo " unknown remove mode ' $REMOVE_MODE ', exiting... " >& 2; exit 2)
update_nginx_server
echo "remove ok"
exit 0
}
compute_doc_generation( ) {
local GENERATOR_SCRIPT = " /generators/ $GENERATOR .sh "
if [ ! -f " $GENERATOR_SCRIPT " ] ; then
echo " unknown generator type, please enter a valid generator ( $( ls /generators | cut -d "." -f1 | tr "\n" " " ) ) " >& 2
exit 1
fi
. " $GENERATOR_SCRIPT "
generate " $DOCUMENTATION_PLACE "
update_nginx_server
echo " documentation generated and deployed at https://codefirst.iut.uca.fr/documentation/ ${ RELATIVE_DOC_PATH } ${ GENERATOR } / "
exit 0
}
compute_remove
echo " documentation generated and deployed at https://codefirst.iut.uca.fr/documentation/ ${ RELATIVE_PATH } index.html "
compute_doc_generation