You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.7 KiB
90 lines
2.7 KiB
#!/usr/bin/env bash
|
|
|
|
echo "Repository name: $DRONE_REPO_NAME"
|
|
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
|
|
|
|
help() {
|
|
cat <<EOF
|
|
usage: $0
|
|
environment variables:
|
|
GENERATOR="[docusaurus|doxygen|mdbook|swagger]" -- generator to use. - required
|
|
DOCUMENTATION_PLACE="[dir]" -- location of the documentation sources root - required
|
|
DESTINATION="[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
|
|
exit 1
|
|
}
|
|
|
|
|
|
if [ ! "$GENERATOR" ] || [ ! "$DOCUMENTATION_PLACE" ] || echo "$DESTINATION" | grep -E -q "^[\/].*"; then
|
|
echo "$0: bad usage" >&2
|
|
help
|
|
fi
|
|
|
|
|
|
export GENERATION_PATH="/docs/$GENERATOR"
|
|
export RELATIVE_DOC_PATH=$(echo "$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$DESTINATION/" | tr -s "/")
|
|
|
|
|
|
|
|
update_nginx_server() {
|
|
local SERVER_TARGET="/usr/share/nginx/html/$RELATIVE_DOC_PATH"
|
|
|
|
# launches rsync in archive, verbose and compression mode
|
|
# creates target directory ($SERVER_TARGET) on server
|
|
# then sends generated files into the server directory
|
|
# rsync -avz -I \
|
|
# --rsync-path="mkdir -p \"$SERVER_TARGET\" && rsync" \
|
|
# -e "ssh -o StrictHostKeyChecking=no" \
|
|
# --delete "$GENERATION_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
|
|
compute_doc_generation
|