Skip to content

Commit c142e68

Browse files
authored
Merge pull request #72074 from aireilly/final-tweaks-preview-urls
final tweaks for prow URLs script
2 parents 70ddc73 + 67c56d2 commit c142e68

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

scripts/get-updated-preview-urls.sh

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
#!/bin/bash
2-
# Returns a list of page preview URLs for use with Prow CI jobs
2+
# Returns a list of page preview URLs
33
# To run locally, clean the _preview folder and do a new asciibinder build before running the script
4+
# To run in Prow CI, run with
5+
# ./get-updated-preview-urls.sh $PULL_NUMBER
46

57
# Check if jq is installed
68
hash jq 2>/dev/null || { echo >&2 "Error: jq is not installed"; exit 1; }
79

8-
pr_branch="$(git rev-parse --abbrev-ref HEAD)"
10+
# Set $pull_number if it is not passed as variable
11+
if [ $# -eq 0 ]; then
912
commit_id=$(git log -n 1 --pretty=format:"%H")
10-
pr_number="$(curl -s "https://api.github.com/search/issues?q=$commit_id" | jq '.items[0].number')"
13+
pull_number="$(curl -s "https://api.github.com/search/issues?q=$commit_id" | jq '.items[0].number')"
14+
pr_branch="$(git rev-parse --abbrev-ref HEAD)"
15+
else
16+
pull_number=$1
17+
pr_branch="latest"
18+
fi
19+
1120
preview_url_slug="ocpdocs-pr"
12-
preview_url="https://${pr_number}--${preview_url_slug}.netlify.app"
21+
preview_url="https://${pull_number}--${preview_url_slug}.netlify.app"
1322
assemblies=()
1423
pages=()
1524
files=$(git diff --name-only HEAD~1 HEAD --diff-filter=AMRD "*.adoc" ':(exclude)_unused_topics/*')
@@ -25,25 +34,29 @@ fi
2534
# Search for $file references in all *.adoc files that are not in a folder called modules/, snippets/, or _unused_topics/
2635
for file in $files; do
2736
include_ref="include::$file"
28-
found_file=$(find . -name '*.adoc' -not -path "./modules/*" -not -path "./snippets/*" -not -path "./_unused_topics/*" -exec grep -rl "^$include_ref" {} +)
37+
found_file=$(find . -name '*.adoc' -not -path "modules/*" -not -path "snippets/*" -not -path "_unused_topics/*" -exec grep -rl "^$include_ref" {} +)
38+
# Add the found updated assemblies, not directly included in PR
39+
assemblies+=("$found_file")
40+
# If not found, then it is a directly updated assembly file
2941
if [ -z "$found_file" ]; then
3042
assemblies+=("$file")
3143
fi
3244
done
3345

3446
# Make the HTML URL slug
3547
if [ ${#assemblies[@]} -gt 0 ]; then
36-
updated_pages=$(echo "${assemblies[@]}" | xargs -n1 basename | sed 's/\.adoc$/.html/' | sort | uniq)
48+
updated_pages=$(echo "${assemblies[@]}" | sed 's/\.adoc$/.html/' | sort | uniq)
3749
else
3850
# No updated pages, just add default URL
3951
pages+=("${preview_url}")
4052
fi
4153

4254
# Search built_pages for every entry in updated_pages and add to pages array when it is found
4355
for updated_page in $updated_pages; do
44-
# sed $pr_branch > "latest" to match the Prow build URL
45-
found_page=$(echo "${built_pages}" | grep "${updated_page}" | sed "s/$pr_branch/latest/")
46-
pages+=("${preview_url}/${found_page}")
56+
# sed s/$pr_branch/latest to match the Prow build URL
57+
found_page=$(echo "${built_pages}" | grep "${updated_page}" | sed "s|/$pr_branch/|/latest/|")
58+
pages+=("${found_page}")
4759
done
4860

49-
printf '%s\n' "${pages[@]}" | sort | uniq
61+
#Echo the results, prepending the $preview_url to every line
62+
echo "${pages[@]}" | tr ' ' '\n' | sort | uniq | sed "s|^|$preview_url/|"

0 commit comments

Comments
 (0)