From a0a7682a944f831d2e5102b6a0930def99fce3b7 Mon Sep 17 00:00:00 2001 From: clfreville2 Date: Thu, 2 Feb 2023 13:25:19 +0100 Subject: [PATCH] Conditionally deploy based on the current branch [CI SKIP] --- README.md | 3 ++- entrypoint.sh | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 602197c..6f0d4c9 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ 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|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 !!** @@ -27,7 +28,7 @@ Usage 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 -l ./src/Doxyfile -t doxygen -d sourcecode_documentation +/entrypoint.sh -b main -l ./src/Doxyfile -t doxygen -d sourcecode_documentation ``` ### How to add a custom documentation generator ? diff --git a/entrypoint.sh b/entrypoint.sh index f46c548..4c9ee61 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,14 +10,20 @@ help() { usage: $0 -l --loc [dir] location of the documentation sources root - required -t --type [docusaurus|doxygen|swagger] type of documentation generator to use. - required + -b --branch [branch] pattern of branch names to deploy - optional -d --dest [dir] path to where to put the documentation outputs in your repository's CodeDoc space - optional !! cannot be absolute !! EOF exit 1 } +BRANCH="" DEST="" while [ "$1" ]; do case "$1" in + "-b" | "--branch") + BRANCH="$2" + shift 1 + ;; "-d" | "--dest") DEST="$2" shift 1 @@ -53,6 +59,11 @@ RELATIVE_PATH=$(echo "$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$DEST/" | tr -s "/") . "$GENERATOR_SCRIPT" generate "$DOC_DIR" # generates doc using the wanted generator +if [[ -n $BRANCH && ! $DRONE_BRANCH =~ $BRANCH ]]; then + echo "ignoring deploy step since current branch doesn't match $BRANCH" + exit +fi + SERVER_TARGET="/usr/share/nginx/html/$RELATIVE_PATH" # launches rsync in archive, verbose and compression mode