From 55527c00eb35bf3b07b361363fd8ca2961afc8ba Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sat, 11 Apr 2020 12:25:56 +0200 Subject: [PATCH] docs: rename docs scripts and improve template --- dev.sh | 11 +++++++---- docs/README.md | 2 +- docs/build-archive | 4 ---- docs/build-current | 14 ------------- docs/build.sh | 23 ++++++++++++++++++++++ docs/{ci => ci.sh} | 12 +++++++---- docs/render_examples.py | 10 ++++++---- docs/{setup => setup.sh} | 10 ++++++++-- docs/{upload-archive => upload-archive.sh} | 8 ++++++-- docs/{upload-stable => upload-stable.sh} | 8 ++++++-- release/README.md | 8 ++++---- release/docker/docker-entrypoint.sh | 17 +++++++++------- tox.ini | 2 +- 13 files changed, 80 insertions(+), 49 deletions(-) delete mode 100755 docs/build-archive delete mode 100755 docs/build-current create mode 100755 docs/build.sh rename docs/{ci => ci.sh} (68%) rename docs/{setup => setup.sh} (64%) rename docs/{upload-archive => upload-archive.sh} (83%) rename docs/{upload-stable => upload-stable.sh} (75%) diff --git a/dev.sh b/dev.sh index a90b48ab3..df7b22d44 100755 --- a/dev.sh +++ b/dev.sh @@ -1,6 +1,9 @@ -#!/bin/sh -set -e -set -x +#!/usr/bin/env bash + +set -o errexit +set -o pipefail +set -o nounset +set -o xtrace echo "Creating dev environment in ./venv..." @@ -12,4 +15,4 @@ pip3 install -r requirements.txt echo "" echo " * Created virtualenv environment in ./venv." echo " * Installed all dependencies into the virtualenv." -echo " * You can now activate the $(python3 --version) virtualenv with this command: \`. venv/bin/activate\`" \ No newline at end of file +echo " * You can now activate the $(python3 --version) virtualenv with this command: \`. venv/bin/activate\`" diff --git a/docs/README.md b/docs/README.md index 5c99fb396..24c24d24c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -8,7 +8,7 @@ This directory houses the mitmproxy documentation available at "src/generated/${output%.*}.html" -done - -python3 render_examples > src/content/addons-examples.md - -cd src -hugo diff --git a/docs/build.sh b/docs/build.sh new file mode 100755 index 000000000..aaa52a2fb --- /dev/null +++ b/docs/build.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -o errexit +set -o pipefail +set -o nounset +# set -o xtrace + +SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" +pushd ${SCRIPTPATH} + +for script in scripts/* ; do + output="${script##*/}" + output="src/generated/${output%.*}.html" + echo "Generating output for ${script} into ${output} ..." + "${script}" > "${output}" +done + +output="src/content/addons-examples.md" +echo "Generating examples content page into ${output} ..." +./render_examples.py > "${output}" + +cd src +hugo diff --git a/docs/ci b/docs/ci.sh similarity index 68% rename from docs/ci rename to docs/ci.sh index 95a5218e2..159d0b50d 100755 --- a/docs/ci +++ b/docs/ci.sh @@ -1,9 +1,13 @@ -#!/bin/bash -set -e +#!/usr/bin/env bash -# This script gets run from CI to render and upload docs +set -o errexit +set -o pipefail +set -o nounset +# set -o xtrace -./build-current +# This script gets run from CI to render and upload docs for the master branch. + +./build.sh # Only upload if we have defined credentials - we only have these defined for # trusted commits (i.e. not PRs). diff --git a/docs/render_examples.py b/docs/render_examples.py index b6fa42eb6..9c6dea745 100755 --- a/docs/render_examples.py +++ b/docs/render_examples.py @@ -14,10 +14,12 @@ menu: # Examples of Addons and Scripts +The most recent set of examples is also available [on our GitHub project](https://github.com/mitmproxy/mitmproxy/tree/master/examples). + """) base = os.path.dirname(os.path.realpath(__file__)) -examples_path = os.path.join(base, '../src/examples/') +examples_path = os.path.join(base, 'src/examples/') pathlist = Path(examples_path).glob('**/*.py') examples = [os.path.relpath(str(p), examples_path) for p in sorted(pathlist)] @@ -33,7 +35,7 @@ for ex in examples: print(" * [Examples: {}]({{{{< relref \"addons-examples#{}\">}}}})".format(current_dir, sanitized)) sanitized = ex.replace('/', '').replace('.', '') - print(" * [{}]({{{{< relref \"addons-examples#{}\">}}}})".format(ex, sanitized)) + print(" * [{}]({{{{< relref \"addons-examples#example-{}\">}}}})".format(os.path.basename(ex), sanitized)) current_dir = None current_level = 2 @@ -43,6 +45,6 @@ for ex in examples: print("#" * current_level, current_dir) print(textwrap.dedent(""" - {} {} + {} Example: {} {{{{< example src="{}" lang="py" >}}}} - """.format("#" * (current_level + 1), ex, "/examples/" + ex))) + """.format("#" * (current_level + 1), ex, "examples/" + ex))) diff --git a/docs/setup b/docs/setup.sh similarity index 64% rename from docs/setup rename to docs/setup.sh index cb63841a4..da30a3c96 100755 --- a/docs/setup +++ b/docs/setup.sh @@ -1,5 +1,11 @@ -#!/bin/sh -set -e +#!/usr/bin/env bash + +set -o errexit +set -o pipefail +set -o nounset +# set -o xtrace + +# This is only needed once to provision a new fresh empty S3 bucket. aws configure set preview.cloudfront true aws --profile mitmproxy \ diff --git a/docs/upload-archive b/docs/upload-archive.sh similarity index 83% rename from docs/upload-archive rename to docs/upload-archive.sh index 3aaeb9be3..e35345e98 100755 --- a/docs/upload-archive +++ b/docs/upload-archive.sh @@ -1,5 +1,9 @@ -#!/bin/bash -set -e +#!/usr/bin/env bash + +set -o errexit +set -o pipefail +set -o nounset +# set -o xtrace if [[ $# -eq 0 ]] ; then echo "Please supply a version, e.g. 'v3'" diff --git a/docs/upload-stable b/docs/upload-stable.sh similarity index 75% rename from docs/upload-stable rename to docs/upload-stable.sh index 5aea74796..a2f20f01c 100755 --- a/docs/upload-stable +++ b/docs/upload-stable.sh @@ -1,5 +1,9 @@ -#!/bin/bash -set -e +#!/usr/bin/env bash + +set -o errexit +set -o pipefail +set -o nounset +# set -o xtrace aws configure set preview.cloudfront true aws --profile mitmproxy \ diff --git a/release/README.md b/release/README.md index 8632d6444..1de0824f6 100644 --- a/release/README.md +++ b/release/README.md @@ -37,10 +37,10 @@ These steps assume you are on the correct branch and have a git remote called `o `export VERSION=4.0.3 && docker pull mitmproxy/mitmproxy:$VERSION && docker tag mitmproxy/mitmproxy:$VERSION mitmproxy/mitmproxy:latest && docker push mitmproxy/mitmproxy:latest`. ### Docs - - `./build-current`. If everything looks alright, continue with - - `./upload-stable`, - - `./build-archive`, and - - `./upload-archive v4`. Doing this now already saves you from switching back to an old state on the next release. + - `./build.sh`. If everything looks alright, continue with + - `./upload-stable.sh`, + - `DOCS_ARCHIVE=true ./build.sh`, and + - `./upload-archive.sh v4`. Doing this now already saves you from switching back to an old state on the next release. ### Website - Update version here: diff --git a/release/docker/docker-entrypoint.sh b/release/docker/docker-entrypoint.sh index a4abe4cef..7bb3028a3 100755 --- a/release/docker/docker-entrypoint.sh +++ b/release/docker/docker-entrypoint.sh @@ -1,13 +1,16 @@ -#!/bin/sh -set -e +#!/usr/bin/env bash + +set -o errexit +set -o pipefail +set -o nounset +# set -o xtrace MITMPROXY_PATH="/home/mitmproxy/.mitmproxy" if [[ "$1" = "mitmdump" || "$1" = "mitmproxy" || "$1" = "mitmweb" ]]; then - mkdir -p "$MITMPROXY_PATH" - chown -R mitmproxy:mitmproxy "$MITMPROXY_PATH" - - su-exec mitmproxy "$@" + mkdir -p "$MITMPROXY_PATH" + chown -R mitmproxy:mitmproxy "$MITMPROXY_PATH" + su-exec mitmproxy "$@" else - exec "$@" + exec "$@" fi diff --git a/tox.ini b/tox.ini index 6ae38cbb4..353a4d18a 100644 --- a/tox.ini +++ b/tox.ini @@ -76,4 +76,4 @@ deps = awscli changedir = docs commands = - ./ci + ./ci.sh