diff --git a/.drone.yml b/.drone.yml index 826239a..da7b3d6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -28,6 +28,3 @@ steps: from_secret: SECRET_REGISTRY_USERNAME password: from_secret: SECRET_REGISTRY_PASSWORD - when: - branch: - - master diff --git a/Dockerfile b/Dockerfile index f941411..e6fbe4e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ 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 diff --git a/README.md b/README.md index 76d8f72..c10c44a 100644 --- a/README.md +++ b/README.md @@ -17,27 +17,22 @@ steps: - name: docs path: /docs commands: - - /entrypoint.sh + - /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 -### Arguments - -- `-b --branch [branch]` pattern of branch names to deploy -- `-l --loc [dir]` location of the documentation sources root - **required** -- `-t --type [docusaurus|doxygen|mdbook|swagger]` type of documentation generator to use. - **required** -- `-d --dest [dir]` path to where to put the documentation outputs in your repository's CodeDoc space - **optional !! cannot be absolute !!** - -### 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 -``` +### 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** --- diff --git a/entrypoint.sh b/entrypoint.sh index 3cee332..ed98994 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,77 +1,89 @@ #!/usr/bin/env bash -echo "Repository name : $DRONE_REPO_NAME" -echo "Repository owner: $DRONE_REPO_OWNER" - +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 <&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 help fi -RELATIVE_PATH=$(echo "$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$DEST/" | tr -s "/") -if [[ -n $BRANCH && ! $DRONE_BRANCH =~ $BRANCH ]]; then - echo "ignoring deploy step since current branch doesn't match $BRANCH" - exit -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() { -. "$GENERATOR_SCRIPT" -generate "$DOC_DIR" # generates doc using the wanted generator + [ $REMOVE_MODE -eq 0 ] || [ -z $REMOVE_MODE ] && return -SERVER_TARGET="/usr/share/nginx/html/$RELATIVE_PATH" + [ $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 +} -# 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 "$GEN_PATH" root@nginx:"$SERVER_TARGET" -echo "documentation generated and deployed at https://codefirst.iut.uca.fr/documentation/${RELATIVE_PATH}index.html" +compute_remove +compute_doc_generation diff --git a/generators/docusaurus.sh b/generators/docusaurus.sh index f0ceff4..30df536 100644 --- a/generators/docusaurus.sh +++ b/generators/docusaurus.sh @@ -1,8 +1,8 @@ -GEN_PATH="/docs/docusaurus" +# == DOCUSORUS GENERATOR == generate() { (cd "$1" && npm install && npm run build) - mkdir -p $GEN_PATH - mv build/* $GEN_PATH + mkdir -p $GENERATION_PATH + mv build/* $GENERATION_PATH } diff --git a/generators/doxygen.sh b/generators/doxygen.sh index cc41f79..834a079 100644 --- a/generators/doxygen.sh +++ b/generators/doxygen.sh @@ -1,4 +1,4 @@ -GEN_PATH="/docs/doxygen" +# == DOXYGEN GENERATOR == generate() { @@ -7,7 +7,7 @@ generate() { exit 1 fi - mkdir -p $GEN_PATH + mkdir -p $GENERATION_PATH cd "$1" - (cat Doxyfile; echo -e "\nOUTPUT_DIRECTORY = \nHTML_OUTPUT = $GEN_PATH") | doxygen - + (cat Doxyfile; echo -e "\nOUTPUT_DIRECTORY = \nHTML_OUTPUT = $GENERATION_PATH") | doxygen - } diff --git a/generators/mdbook.sh b/generators/mdbook.sh index 24e7e35..e0459f2 100644 --- a/generators/mdbook.sh +++ b/generators/mdbook.sh @@ -1,4 +1,4 @@ -GEN_PATH="/docs/book" +# == MDBOOK GENERATOR == generate() { @@ -7,6 +7,6 @@ generate() { exit 1 fi - mkdir -p $GEN_PATH - mdbook build "$1" -d $GEN_PATH + mkdir -p $GENERATION_PATH + mdbook build "$1" -d $GENERATION_PATH } diff --git a/generators/swagger.sh b/generators/swagger.sh index af85dd6..dbe26c0 100644 --- a/generators/swagger.sh +++ b/generators/swagger.sh @@ -1,23 +1,23 @@ -GEN_PATH="/docs/swagger" +# == SWAGGER GENERATOR == generate() { if [[ ! "$1" ]]; then echo "missing swagger config file ($1)" >&2 fi - mkdir -p $GEN_PATH + mkdir -p $GENERATION_PATH - cat < $GEN_PATH/CLICKME.html + cat < $GENERATION_PATH/CLICKME.html - + -

Suivez ce lien.

+

Suivez ce lien.

EOF - mv "$1" $GEN_PATH + mv "$1" $GENERATION_PATH } diff --git a/test/test_env_var.sh b/test/test_env_var.sh new file mode 100644 index 0000000..beee471 --- /dev/null +++ b/test/test_env_var.sh @@ -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