Compare commits

...

1 Commits

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

@ -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

@ -17,27 +17,22 @@ steps:
- name: docs
path: /docs
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
### 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 <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
```
### 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**, <u>cannot be absolute !!</u>
- `REMOVE_MODE=[0|1|2]` -- 0: disable, 1: for this type of documentation only, 2: all your documentations (/!\ use this command with caution!) - **optional**
---

@ -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 <<EOF
usage: $0
-l --loc [dir] location of the documentation sources root - required
-b --branch [branch] pattern of branch names to deploy - optional
-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 !!
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
}
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
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

@ -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
}

@ -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 -
}

@ -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
}

@ -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 <<EOF > $GEN_PATH/CLICKME.html
cat <<EOF > $GENERATION_PATH/CLICKME.html
<!DOCTYPE html>
<html>
<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>
<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>
</html>
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