Compare commits

...

1 Commits

@ -28,6 +28,3 @@ steps:
from_secret: SECRET_REGISTRY_USERNAME from_secret: SECRET_REGISTRY_USERNAME
password: password:
from_secret: SECRET_REGISTRY_PASSWORD from_secret: SECRET_REGISTRY_PASSWORD
when:
branch:
- master

@ -1,5 +1,5 @@
FROM debian:bookworm FROM debian:bookworm
LABEL author="Maxime Batista" LABEL author="Alexandre Agostinho"
RUN apt update && apt -y install sshpass rsync doxygen nodejs npm xdot xdotool wget RUN apt update && apt -y install sshpass rsync doxygen nodejs npm xdot xdotool wget

@ -17,27 +17,22 @@ steps:
- name: docs - name: docs
path: /docs path: /docs
commands: commands:
- /entrypoint.sh <arguments> - /entrypoint.sh
environment:
GENERATOR: doxygen
DOCUMENTATION_PLACE: ./Documentation/doxygen
DESTINATION:
REMOVE_MODE: 0
``` ```
`entrypoint.sh` `entrypoint.sh` r
This command generates the documentation and deploys it on your CodeDoc space This command generates the documentation and deploys it on your CodeDoc space
### Arguments ### Environment variables:
- `GENERATOR="[docusaurus|doxygen|mdbook|swagger]"` -- generator to use. - **required**
- `-b --branch [branch]` pattern of branch names to deploy - `DOCUMENTATION_PLACE="[dir]"` -- location of the documentation sources root - **required**
- `-l --loc [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**, <u>cannot be absolute !!</u>
- `-t --type [docusaurus|doxygen|mdbook|swagger]` type of documentation generator to use. - **required** - `REMOVE_MODE=[0|1|2]` -- 0: disable, 1: for this type of documentation only, 2: all your documentations (/!\ use this command with caution!) - **optional**
- `-d --dest [dir]` path to where to put the documentation outputs in your repository's CodeDoc space - **optional <u>!! cannot be absolute !!</u>**
### Examples :
```
/entrypoint.sh -l ./documentation/api/api-swagger.yml -t swagger -d api_documentation
/entrypoint.sh -l ./documentation/app -t docusaurus -d application_documentation
/entrypoint.sh -b main -l ./documentation/doxygen/ -t doxygen -d sourcecode_documentation
/entrypoint.sh -l ./doc -t mdbook -d book
```
--- ---

@ -2,76 +2,88 @@
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
-l --loc [dir] location of the documentation sources root - required environment variables:
-b --branch [branch] pattern of branch names to deploy - optional GENERATOR="[docusaurus|doxygen|mdbook|swagger]" -- generator to use. - required
-t --type [docusaurus|doxygen|mdbook|swagger] type of documentation generator to use. - required DOCUMENTATION_PLACE="[dir]" -- location of the documentation sources root - required
-d --dest [dir] path to where to put the documentation outputs in your repository's CodeDoc space - optional !! cannot be absolute !! 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 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_SCRIPT" ] || [ ! "$DOC_DIR" ] || echo "$DEST" | grep -E -q "^[\/].*"; then if [ ! "$GENERATOR" ] || [ ! "$DOCUMENTATION_PLACE" ] || echo "$DESTINATION" | 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 "/")
if [[ -n $BRANCH && ! $DRONE_BRANCH =~ $BRANCH ]]; then export GENERATION_PATH="/docs/$GENERATOR"
echo "ignoring deploy step since current branch doesn't match $BRANCH" export RELATIVE_DOC_PATH=$(echo "$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$DESTINATION/" | tr -s "/")
exit
fi
. "$GENERATOR_SCRIPT"
generate "$DOC_DIR" # generates doc using the wanted generator
SERVER_TARGET="/usr/share/nginx/html/$RELATIVE_PATH"
update_nginx_server() {
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 "$GEN_PATH" root@nginx:"$SERVER_TARGET" # --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
}
echo "documentation generated and deployed at https://codefirst.iut.uca.fr/documentation/${RELATIVE_PATH}index.html" compute_remove
compute_doc_generation

@ -1,8 +1,8 @@
GEN_PATH="/docs/docusaurus" # == DOCUSORUS GENERATOR ==
generate() { generate() {
(cd "$1" && npm install && npm run build) (cd "$1" && npm install && npm run build)
mkdir -p $GEN_PATH mkdir -p $GENERATION_PATH
mv build/* $GEN_PATH mv build/* $GENERATION_PATH
} }

@ -1,4 +1,4 @@
GEN_PATH="/docs/doxygen" # == DOXYGEN GENERATOR ==
generate() { generate() {
@ -7,7 +7,7 @@ generate() {
exit 1 exit 1
fi fi
mkdir -p $GEN_PATH mkdir -p $GENERATION_PATH
cd "$1" cd "$1"
(cat Doxyfile; echo -e "\nOUTPUT_DIRECTORY = \nHTML_OUTPUT = $GEN_PATH") | doxygen - (cat Doxyfile; echo -e "\nOUTPUT_DIRECTORY = \nHTML_OUTPUT = $GENERATION_PATH") | doxygen -
} }

@ -1,4 +1,4 @@
GEN_PATH="/docs/book" # == MDBOOK GENERATOR ==
generate() { generate() {
@ -7,6 +7,6 @@ generate() {
exit 1 exit 1
fi fi
mkdir -p $GEN_PATH mkdir -p $GENERATION_PATH
mdbook build "$1" -d $GEN_PATH mdbook build "$1" -d $GENERATION_PATH
} }

@ -1,23 +1,23 @@
GEN_PATH="/docs/swagger" # == SWAGGER GENERATOR ==
generate() { generate() {
if [[ ! "$1" ]]; then if [[ ! "$1" ]]; then
echo "missing swagger config file ($1)" >&2 echo "missing swagger config file ($1)" >&2
fi fi
mkdir -p $GEN_PATH mkdir -p $GENERATION_PATH
cat <<EOF > $GEN_PATH/CLICKME.html cat <<EOF > $GENERATION_PATH/CLICKME.html
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta http-equiv="Refresh" content="0; url=/swagger?url=/documentation/${RELATIVE_PATH}swagger/$1" /> <meta http-equiv="Refresh" content="0; url=/swagger?url=/documentation/${RELATIVE_DOC_PATH}swagger/$1" />
</head> </head>
<body> <body>
<p>Suivez <a href="swagger?url=/swagger?url=/documentation/${RELATIVE_PATH}swagger/$1">ce lien</a>.</p> <p>Suivez <a href="swagger?url=/swagger?url=/documentation/${RELATIVE_DOC_PATH}swagger/$1">ce lien</a>.</p>
</body> </body>
</html> </html>
EOF EOF
mv "$1" $GEN_PATH mv "$1" $GENERATION_PATH
} }

@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -eu
export DRONE_REPO_NAME=SAE-2.01
export DRONE_REPO_OWNER=alexandre.agostinho
export DRONE_BRANCH=dev
export GENERATOR=doxygen
export DOCUMENTATION_PLACE=./
export DESTINATION=""
export REMOVE_MODE=
. ../entrypoint.sh
Loading…
Cancel
Save