Skip to content

Commit 82635ed

Browse files
authored
Merge pull request #71017 from aireilly/add-get-updated-preview-urls-script
Adding get updated preview URLs script
2 parents 4f3d56f + b0840cb commit 82635ed

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

scripts/get-updated-preview-urls.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
# Returns a list of page preview URLs
3+
4+
# Check if jq is installed
5+
hash jq 2>/dev/null || { echo >&2 "Error: jq is not installed"; exit 1; }
6+
7+
pr_branch="$(git rev-parse --abbrev-ref HEAD)"
8+
commit_id=$(git log -n 1 --pretty=format:"%H")
9+
pr_number="$(curl -s "https://api.github.com/search/issues?q=$commit_id" | jq '.items[0].number')"
10+
preview_url_slug="ocpdocs-pr"
11+
preview_url="https://${pr_number}--${preview_url_slug}.netlify.app"
12+
assemblies=()
13+
pages=()
14+
files=$(git diff --name-only HEAD~1 HEAD --diff-filter=AMRD "*.adoc" ':(exclude)_unused_topics/*')
15+
16+
# Get the full list of built files
17+
if [ -e "_preview" ]; then
18+
built_pages=$(find _preview -type f -name "*.html" -printf "%P\n")
19+
else
20+
echo "_preview output folder not found"
21+
exit 1
22+
fi
23+
24+
# Search for $file references in all *.adoc files that are not in a folder called modules/, snippets/, or _unused_topics/
25+
for file in $files; do
26+
found_file=$(find . -name '*.adoc' -not -path "./modules/*" -not -path "./snippets/*" -not -path "./_unused_topics/*" -exec grep -rl "$file" {} +)
27+
assemblies+=("$found_file")
28+
done
29+
30+
# Make the html URL slug
31+
if [ ${#assemblies[@]} -gt 0 ]; then
32+
updated_pages=$(echo "${assemblies[@]}" | xargs -n1 basename | sed 's/\.adoc$/.html/' | sort | uniq)
33+
fi
34+
35+
# Search built_pages for every entry in updated_pages and add to pages array when it is found
36+
for updated_page in $updated_pages; do
37+
# Note also need to sed $pr_branch > "latest"
38+
found_page=$(echo "${built_pages}" | grep "${updated_page}" | sed "s/$pr_branch/latest/")
39+
pages+=("${preview_url}/${found_page}")
40+
done
41+
42+
printf '%s\n' "${pages[@]}"

0 commit comments

Comments
 (0)