Skip to content

Commit

Permalink
Better github links from PR builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpallant committed Jun 18, 2024
1 parent 8112b95 commit 446f9ff
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions cloudflare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 branch --show-current)

# 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
Expand All @@ -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

0 comments on commit 446f9ff

Please sign in to comment.