Skip to content

Commit

Permalink
avoid second iteration on urls
Browse files Browse the repository at this point in the history
  • Loading branch information
niyas-sait committed Feb 9, 2022
1 parent 979c4a3 commit d85e2f4
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/test/shell/bazel/verify_workspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,22 @@ function test_verify_urls() {
# Find url-shaped lines, skipping jekyll-tree (which isn't a valid URL), and
# skipping comments.
invalid_urls=()
urls=()
checked_urls=()
for file in "${WORKSPACE_FILES[@]}"; do
for url in $(grep -E '"https://|http://' "${file}" | \
sed -e '/jekyll-tree/d' -e '/^#/d' -r -e 's#^.*"(https?://[^"]+)".*$#\1#g' | \
sort -u); do
# add only unique url to the array
if [[ ${#urls[@]} == 0 ]] || [[ ! " ${urls[@]} " =~ " ${url} " ]]; then
urls+=("${url}")
if [[ ${#checked_urls[@]} == 0 ]] || [[ ! " ${checked_urls[@]} " =~ " ${url} " ]]; then
checked_urls+=("${url}")
echo "Checking ${url} ..."
if ! curl --head --silent --show-error --fail --output /dev/null --retry 3 "${url}"; then
invalid_urls+=("${url}")
fi
fi
done
done

for url in "${urls[@]}"; do
echo "Checking ${url} ..."
if ! curl --head --silent --show-error --fail --output /dev/null --retry 3 "${url}"; then
invalid_urls+=("${url}")
fi
done

if [[ ${#invalid_urls[@]} > 0 ]]; then
fail "Invalid urls: ${invalid_urls[@]}"
fi
Expand Down

0 comments on commit d85e2f4

Please sign in to comment.