Skip to content

Commit

Permalink
Merge pull request #2601 from owncloud/migrate-docs-makefile-to-cli-s…
Browse files Browse the repository at this point in the history
…cript

Replace the Documentation Makefile with a Shell Script
  • Loading branch information
settermjd authored Nov 21, 2019
2 parents 77e5401 + df641d3 commit 66e8e25
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pipeline:
pull: true
commands:
- cd docs/
- make pdf
- bin/cli -m

cache-rebuild:
image: plugins/s3-cache:1
Expand Down
68 changes: 0 additions & 68 deletions docs/Makefile

This file was deleted.

203 changes: 203 additions & 0 deletions docs/bin/cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
#!/usr/bin/env bash

set -e
set -o noclobber
set -o errexit
set -o pipefail
set -o nounset

ACTION=
FONTS_DIRECTORY="fonts"
MANUAL_NAME="Android Client manual"
EXPORT_FILENAME_PREFIX="ownCloud_Android_App_Manual"
RELEASE_DATE=$(date +'%B %d, %Y')
STYLE="owncloud"
STYLES_DIRECTORY="resources/themes"
LANGUAGE=

ERR_UNSUPPORTED_LANGUAGE=20
ERR_UNSUPPORTED_MANUAL=21
ERR_UNSUPPORTED_ACTION=22
ERR_LINTER_NOT_AVAILABLE=23
ERR_NO_LANGUAGE_SPECIFIED=24

if [[ -z "${VERSION:-}" ]]; then
if [[ -n "${DRONE_TAG:-}" ]]; then
VERSION=${DRONE_TAG/v//}
else
[[ -n "${DRONE_BRANCH:-}" ]] && VERSION=${DRONE_BRANCH/v//} || VERSION=master
fi
fi

function usage()
{
echo "Usage: bin/cli [-c] [-h] [-m] [-l <go|xml|json|php|kotlin|yaml>]"
}

function clean_build_dir()
{
echo "Cleaning build directory..."
rm -rvf "build/"
echo "...build directory cleaned."
}

function validate_code_files()
{
case $LANGUAGE in
go)
if command -v golint &>/dev/null; then
echo "Validating go source files" && \
find ./modules/*_manual/examples -type f -name "*.go" \
-exec sh -c 'echo Linting {} && golint {} && echo' \;
else
echo "Golint is not available."
echo "Exiting."
exit $ERR_LINTER_NOT_AVAILABLE
fi
;;

json)
if command -v jsonlint &>/dev/null; then
find ./modules/*_manual/examples -type f -name "*.json" \
-exec sh -c 'echo Linting {} && jsonlint -qp {} && echo' \;
else
echo "jsonlint is not available."
echo "Exiting."
exit $ERR_LINTER_NOT_AVAILABLE
fi
;;

kotlin)
if command -v ktlint &>/dev/null; then
ktlint --reporter=plain "./modules/*_manual/**/*.kt" || true;
else
echo "ktlint is not available."
echo "Exiting."
exit $ERR_LINTER_NOT_AVAILABLE
fi
;;

php)
if command -v php &>/dev/null; then
find ./modules/*_manual/examples -type f -name "*.php" \
! -path "**/vendor/*" \
-exec php -l {} \;
else
echo "Golint is not available."
echo "Exiting."
exit $ERR_LINTER_NOT_AVAILABLE
fi
;;

xml)
if command -v xmllint &>/dev/null; then
find ./modules/*_manual/examples -type f -name "*.xml" \
-exec xmllint --noout {} \;
else
echo "xmllint is not available."
echo "Exiting."
exit $ERR_LINTER_NOT_AVAILABLE
fi
;;

yaml)
if command -v yamllint &>/dev/null; then
find ./modules/*_manual/examples -type f -name "*.yml" \
-exec sh -c 'echo Linting {} && yamllint -f parsable {} && echo' \;
else
echo "yamllint is not available."
echo "Exiting."
exit $ERR_LINTER_NOT_AVAILABLE
fi
;;

*)
echo "That language is not, currently, supported"
exit $ERR_UNSUPPORTED_LANGUAGE
;;
esac
}

function convert_antora_nav_to_asciidoc_list()
{
local filename="$1"

while read line; do
if [[ ${line} =~ \]$ ]]; then
level_offset=$(echo "$line" | awk -F"*" '{print NF-1}')
revised_line=$(echo "$line" | sed 's/xref:/include::{module_base_path}/' | sed 's/\[.*\]//g' | sed -r 's/^\*{1,} //')
echo "${revised_line}[leveloffset=+${level_offset}]"
fi
done < "${filename}"
}

function build_pdf_manual()
{
local revision="$1"
local build_directory="$(pwd)/build/server/${revision}/ROOT/"
local book_file="books/${EXPORT_FILENAME_PREFIX}.adoc"
local nav_file="modules/ROOT/nav.adoc"
local pdf_filename="$(pwd)/build/server/${revision}/ROOT/${EXPORT_FILENAME_PREFIX}.pdf"

echo "Generating PDF version '${revision}' of the ${MANUAL_NAME}, dated: ${RELEASE_DATE}"

mkdir -p "$build_directory"

asciidoctor-pdf --quiet -d book \
-a pdf-stylesdir="${STYLES_DIRECTORY}/" \
-a pdf-fontsdir="${FONTS_DIRECTORY}" \
-a pdf-style="${STYLE}" \
-a examplesdir="$(pwd)/modules/ROOT/examples/" \
-a imagesdir="$(pwd)/modules/ROOT/assets/images/" \
-a module_base_path="modules/ROOT/pages/" \
-a partialsdir="$(pwd)/modules/ROOT/pages/_partials/" \
-a revnumber="${revision}" \
-a revdate="${RELEASE_DATE}" \
--base-dir "$(pwd)" \
--out-file "${pdf_filename}" \
- < <(cat $book_file <(convert_antora_nav_to_asciidoc_list "$nav_file"))

echo "The ${MANUAL_NAME} has been converted to PDF format."
echo "It is available at: ${pdf_filename}."
}

while getopts ":hcmdl:" o; do
case "${o}" in
m)
ACTION="BUILD_MANUALS"
;;
l)
ACTION="VALIDATE"
LANGUAGE=${OPTARG}
;;
c)
ACTION="CLEAN"
;;
h|*)
ACTION="HELP"
;;
esac
done
shift $((OPTIND-1))

case "$ACTION" in
BUILD_MANUALS)
build_pdf_manual "$VERSION"
;;
CLEAN)
clean_build_dir
;;
VALIDATE)
if [[ -z $LANGUAGE ]]; then
echo "No language was specified to be validated."
echo "Use the -l option to specify one."
echo "exiting."
exit $ERR_NO_LANGUAGE_SPECIFIED
fi
validate_code_files
;;
HELP | *)
usage
exit $ERR_UNSUPPORTED_ACTION
;;
esac
2 changes: 0 additions & 2 deletions docs/books/ownCloud_Android_App_Manual.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ The ownCloud Team <[email protected]>
:toclevels: 1
:icons: font
:icon-set: octicon

include::modules/ROOT/pages/index.adoc[leveloffset=+1]
Binary file added docs/fonts/mplus-1mn-bold.ttf
Binary file not shown.
Binary file added docs/fonts/mplus-1mn-medium.ttf
Binary file not shown.
Binary file added docs/fonts/mplus-1mn-regular.ttf
Binary file not shown.
Binary file added docs/fonts/mplus-1mn-thin.ttf
Binary file not shown.
Binary file added docs/fonts/mplus-1p-regular.ttf
Binary file not shown.
File renamed without changes.
18 changes: 9 additions & 9 deletions docs/resources/themes/owncloud-theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ font:
bold_italic: notoserif-bold_italic.ttf
# M+ 1mn supports ASCII and the circled numbers used for conums
M+ 1mn:
normal: mplus1mn-regular-ascii-conums.ttf
bold: mplus1mn-bold-ascii.ttf
italic: mplus1mn-italic-ascii.ttf
bold_italic: mplus1mn-bold_italic-ascii.ttf
normal: mplus-1mn-regular.ttf
bold: mplus-1mn-bold.ttf
italic: mplus-1mn-thin.ttf
bold_italic: mplus-1mn-medium.ttf
# M+ 1p supports Latin, Latin-1 Supplement, Latin Extended, Greek, Cyrillic, Vietnamese, Japanese & an assortment of symbols
# It also provides arrows for ->, <-, => and <= replacements in case these glyphs are missing from font
M+ 1p Fallback:
normal: mplus1p-regular-fallback.ttf
bold: mplus1p-regular-fallback.ttf
italic: mplus1p-regular-fallback.ttf
bold_italic: mplus1p-regular-fallback.ttf
normal: mplus-1p-regular.ttf
bold: mplus-1p-regular.ttf
italic: mplus-1p-regular.ttf
bold_italic: mplus-1p-regular.ttf
Open Sans:
normal: opensans-light.ttf
bold: opensans-bold.ttf
Expand All @@ -43,7 +43,7 @@ page:
margin_outer: 0.59in
size: A4
base:
align: justify
align: left
font_color: 1c1c1c
font_family: "DejaVu Serif"
font_size: 10.5
Expand Down

0 comments on commit 66e8e25

Please sign in to comment.