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 authored and listochkin committed Jun 19, 2024
1 parent 7ea3afa commit ced61b5
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions cloudflare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,36 @@ 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?
git_branch=$(git branch --show-current)
current_branch="${CF_PAGES_BRANCH:-$git_branch}"

if [ "$current_branch" == "" ]; then
echo "Current branch unknown"
exit 1
fi

# Build what we currently have checked out
build_and_store latest
# Use what CloudFlare thinks is the current branch, or what git thinks
build_and_store latest "${current_branch}"

# Fetch all the git tags (in case this is some kind of shallow clone)
git fetch --tags
Expand All @@ -61,5 +69,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 ced61b5

Please sign in to comment.