#!/bin/bash # Converts the agent docs here to the ReadTheDocs repo at # https://github.com/signalfx/product-docs. You will probably have to provide # the envvar $PRODUCT_DOCS_REPO, which is the directory path to the root of the # product-docs repo. It will overwrite any existing agent docs in the repo, # but will not commit them to git. # For Mac, Pandoc 2.5 should be used and can be gotten from # https://github.com/jgm/pandoc/releases/tag/2.5 set -euo pipefail SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" AGENT_REPO_BASE="$SCRIPT_DIR/../.." PRODUCT_DOCS_REPO="${PRODUCT_DOCS_REPO:-$AGENT_REPO_BASE/../product-docs}" AGENT_PRODUCT_DOCS="$PRODUCT_DOCS_REPO/integrations/agent" MANAGE_GIT="${MANAGE_GIT-yes}" check_pandoc_version() { pandoc --version | grep 'pandoc 2.[57]' } header_comment() { printf ".. Generated by scripts/docs/to-product-docs in signalfx-agent repo. DO NOT EDIT in product-docs!!\n\n" } . $SCRIPT_DIR/common.sh convert_overview_links() { sed -E -e 's@../README.html@./overview.html@' } # Convert all relative links that aren't already html links to be absolute to # the github repo url. convert_relative_links() { sed -E -e '/\.html(#.*)?$/! s@(\.\. _[a-zA-Z].*:) \.\/(.*)@\1 https://github.com/signalfx/signalfx-agent/tree/master/\2@' } # Changes .md extensions to .html convert_doc_extensions() { sed -E -e '/http:|https:|(development|signalfx-agent.1|MANUAL).md/! s/\.md(#.*)?[[:>:]]/.html\1/g' -e'/(development|signalfx-agent.1).md/! s@\./docs/@./@g' } strip_needless_header_refs() { sed -E -e '/\.\. _.*default-metrics-version/d' } reset_repo() { if ! git -C $PRODUCT_DOCS_REPO diff --exit-code; then echo "Product docs repo has uncommitted changes, please deal with them first" >&2 exit 1 fi git -C $PRODUCT_DOCS_REPO fetch origin git -C $PRODUCT_DOCS_REPO checkout smart-agent # If there aren't any pending commits in the smart-agent branch, then reset # with the latest master first if [[ -z "$(git cherry -v origin/master origin/smart-agent || echo '')" ]]; then git -C $PRODUCT_DOCS_REPO reset --hard origin/master fi } check_pandoc_version [ -d $PRODUCT_DOCS_REPO ] || \ (echo "product-docs repo dir cannot be found at $PRODUCT_DOCS_REPO; please set \$PRODUCT_DOCS_REPO" && exit 1) if [[ "$MANAGE_GIT" == "yes" ]]; then reset_repo fi mkdir -p $AGENT_PRODUCT_DOCS/{monitors,observers} for f in $(find $AGENT_REPO_BASE/docs -name "*.md"); do if [[ $f =~ writing-a-monitor.md$ ]] || [[ $f =~ development.md$ ]]; then continue fi out_file=$AGENT_PRODUCT_DOCS/$(echo $f | sed -e "s@${AGENT_REPO_BASE}/docs/@@" | sed 's/md/rst/') header_comment > $out_file cat $f | \ use_marketing_name | \ pandoc \ --from gfm \ --to rst \ --standalone \ --reference-links \ --columns=1300 | \ convert_doc_extensions | \ convert_relative_links | \ strip_needless_header_refs | \ convert_overview_links \ >> $out_file if [[ $out_file =~ monitor-config.rst$ ]]; then cat <> $out_file .. toctree:: :glob: :hidden: :maxdepth: 1 ./monitors/* EOH fi if [[ $out_file =~ observer-config.rst$ ]]; then cat <> $out_file .. toctree:: :glob: :hidden: :maxdepth: 1 ./observers/* EOH fi done header_comment | \ cat - $AGENT_REPO_BASE/README.md | \ use_marketing_name | \ sed -e 's/# SignalFx Smart Agent/# Overview/' | \ sed -e '/GoDoc/d' | \ sed -e '/CircleCI/d' | \ pandoc --from gfm --to rst --standalone --reference-links --wrap none | \ convert_doc_extensions | \ convert_relative_links \ > $AGENT_PRODUCT_DOCS/overview.rst # Make sure we can build the project in sphinx make -C $AGENT_PRODUCT_DOCS html