Skip to content

Commit

Permalink
Test: tutorial split
Browse files Browse the repository at this point in the history
- support longer tutorial and/or more tutorials
  • Loading branch information
DrYak committed Oct 8, 2023
1 parent ee97b7b commit 7660c57
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions docs/convert.sh
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand All @@ -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[@]}"

0 comments on commit 7660c57

Please sign in to comment.