From 226925f5e87d07de84da590701620d45782039df Mon Sep 17 00:00:00 2001 From: Jonathan Pallant Date: Tue, 18 Jun 2024 16:09:31 +0100 Subject: [PATCH] Better github links from PR builds. --- cloudflare.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cloudflare.sh b/cloudflare.sh index f613352..fec198d 100755 --- a/cloudflare.sh +++ b/cloudflare.sh @@ -29,28 +29,29 @@ mkdir -p "${OUTPUT_DIR}" cp ./_redirects "${OUTPUT_DIR}/_redirects" # Build the book and slides +# +# $1 is the output folder name +# $2 is the git tag name function build_and_store { - if [ "$1" == "latest" ]; then - tag="main" - else - tag="$1" - fi mkdir -p "${OUTPUT_DIR}/$1" # Munge all the relative source code links to point at Github for folder in ${CODE_FOLDER_LIST}; do echo "Processing ${folder}" # This finds a Markdown links with relative URLs - find ./exercise-book -type f -name "*.md" -exec sed -e "s~(../../${folder}/~(https://github.com/ferrous-systems/rust-exercises/tree/${tag}/${folder}/~g" -i.backup {} \; + find ./exercise-book -type f -name "*.md" -exec sed -e "s~(../../${folder}/~(https://github.com/ferrous-systems/rust-exercises/tree/$2/${folder}/~g" -i.backup {} \; # This finds a Markdown references with relative URLs - find ./exercise-book -type f -name "*.md" -exec sed -e "s~]: ../../${folder}/~]: https://github.com/ferrous-systems/rust-exercises/tree/${tag}/${folder}/~g" -i.backup {} \; + find ./exercise-book -type f -name "*.md" -exec sed -e "s~]: ../../${folder}/~]: https://github.com/ferrous-systems/rust-exercises/tree/$2/${folder}/~g" -i.backup {} \; done # Build the book first, because mdbook will create any empty sections # The PATH override lets it find our local copy of mdbook-mermaid PATH=$PATH:. ./mdbook build -d "${OUTPUT_DIR}/$1/book" ./exercise-book } +# What branch are we building first? +local_branch=$(git rev-parse --abbrev-ref HEAD) + # Build what we currently have checked out -build_and_store latest +build_and_store latest ${local_branch} # Fetch all the git tags (in case this is some kind of shallow clone) git fetch --tags @@ -61,5 +62,6 @@ for tag in $(git tag); do mkdir -p "${OUTPUT_DIR}/${tag}" # Fetch a clean copy of the source material for this tag git checkout -f "${tag}" - build_and_store "${tag}" + # Output dir and git tag are the same + build_and_store "${tag}" "${tag}" done