From 7660c57f41f1e1a4aa542b3cca1ac21412b6909a Mon Sep 17 00:00:00 2001 From: Ivan Blagoev Topolsky Date: Wed, 28 Jun 2023 22:27:19 +0200 Subject: [PATCH] Test: tutorial split - support longer tutorial and/or more tutorials --- docs/convert.sh | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/docs/convert.sh b/docs/convert.sh index d9d34c7d..132d9bc7 100755 --- a/docs/convert.sh +++ b/docs/convert.sh @@ -1,5 +1,30 @@ #!/usr/bin/env bash +patch_branch=0 + +# command-line options +while [[ -n $1 ]]; do + case "$1" in + --branch|branch) + patch_branch=1 + ;; + *) + break + ;; + esac + shift +done + +# positional args +if [[ -n $1 ]]; then + alltut=( "${@}" ) +else + alltut=( ./tutorial*.md ) +fi + +echo "Will run on:" +printf "<%s>\n" "${alltut[@]}" + # branch (for usual PR and pushes) branch="$(git branch --show-current)" # fall back on tags if branch was left empty (checked out in grafted/detached head mode, e.g. when testing a tag) @@ -10,12 +35,13 @@ branch="${branch:-$(git rev-parse HEAD)}" default="master" echo "current branch: ${branch}" -if [[ "${1}" == "branch" ]]; then + +if (( patch_branch )); then if [[ -z "${branch}" ]]; then echo -e "\e[31;1mCannot determine current branch or tag!\e[0m The installer in tutorials will still clone the \`${default}\` branch." elif [[ "${branch}" != "${default}" ]]; then echo "patching tutorials..." - sed -ri "s@(quick_install.sh) +(-[^b])@\1 -b ${branch} \2@g;s@(V-pipe)/${default}(/utils)@\1/${branch}\2@g" ./tutorial*.md + sed -ri "s@(quick_install.sh) +(-[^b])@\1 -b ${branch} \2@g;s@(V-pipe)/${default}(/utils)@\1/${branch}\2@g" "${alltut[@]}" ## example command to keep the output with errors # jupytext --to ipynb --pipe-fmt ipynb --pipe 'jupyter nbconvert --to ipynb --execute --allow-errors --stdin --stdout' ./*.md else @@ -26,4 +52,4 @@ elif [[ "${branch}" != "${default}" ]]; then fi # create Jupyter Notebooks for all Markdown files -exec jupytext --set-formats ipynb,md --execute ./tutorial*.md +exec jupytext --set-formats ipynb,md --execute "${alltut[@]}"