1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 12:46:18 +01:00

Adding get updated preview URLs script

updates
This commit is contained in:
Aidan Reilly
2024-01-31 10:51:27 +00:00
parent 971d0a5244
commit b0840cbfd2

View File

@@ -0,0 +1,42 @@
#!/bin/bash
# Returns a list of page preview URLs
# Check if jq is installed
hash jq 2>/dev/null || { echo >&2 "Error: jq is not installed"; exit 1; }
pr_branch="$(git rev-parse --abbrev-ref HEAD)"
commit_id=$(git log -n 1 --pretty=format:"%H")
pr_number="$(curl -s "https://api.github.com/search/issues?q=$commit_id" | jq '.items[0].number')"
preview_url_slug="ocpdocs-pr"
preview_url="https://${pr_number}--${preview_url_slug}.netlify.app"
assemblies=()
pages=()
files=$(git diff --name-only HEAD~1 HEAD --diff-filter=AMRD "*.adoc" ':(exclude)_unused_topics/*')
# Get the full list of built files
if [ -e "_preview" ]; then
built_pages=$(find _preview -type f -name "*.html" -printf "%P\n")
else
echo "_preview output folder not found"
exit 1
fi
# Search for $file references in all *.adoc files that are not in a folder called modules/, snippets/, or _unused_topics/
for file in $files; do
found_file=$(find . -name '*.adoc' -not -path "./modules/*" -not -path "./snippets/*" -not -path "./_unused_topics/*" -exec grep -rl "$file" {} +)
assemblies+=("$found_file")
done
# Make the html URL slug
if [ ${#assemblies[@]} -gt 0 ]; then
updated_pages=$(echo "${assemblies[@]}" | xargs -n1 basename | sed 's/\.adoc$/.html/' | sort | uniq)
fi
# Search built_pages for every entry in updated_pages and add to pages array when it is found
for updated_page in $updated_pages; do
# Note also need to sed $pr_branch > "latest"
found_page=$(echo "${built_pages}" | grep "${updated_page}" | sed "s/$pr_branch/latest/")
pages+=("${preview_url}/${found_page}")
done
printf '%s\n' "${pages[@]}"