Skip to content

Commit

Permalink
suggested fix
Browse files Browse the repository at this point in the history
  • Loading branch information
max-ostapenko committed Oct 24, 2023
1 parent 13583c7 commit 37882ad
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/wpt-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,44 @@ jobs:

- name: Run WebPageTest for more websites
run: |
METRICS=$(for file in $(git diff --name-only --diff-filter=ACMRT \
${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | \
grep -E "^dist/.*\.js$"); do basename "$file"; done | cut -d\. -f1 | sort | uniq)
METRICS=$(git diff --name-only --diff-filter=ACMRT ${GITHUB_BASE_SHA} ${GITHUB_HEAD_SHA} | grep -E "^dist/.*\.js$" | xargs -I {} basename {} | cut -d. -f1 | sort | uniq)
PR_BODY="${{ github.event.pull_request.body }}"
declare -a lines
while IFS= read -r line; do
lines+=("${line//[$'\r\n']}")
done <<< "$PR_BODY"
# Read PR body into an array, removing line breaks
IFS=$'\n' read -r -a lines <<< "$PR_BODY"
# Find the start index of the section you're interested in
start_index=-1
for ((i=0; i<=${#lines[@]}; i++)); do
for ((i=0; i<${#lines[@]}; i++)); do
if [[ "${lines[$i]}" == *"**Test websites**:"* ]]; then
start_index=$((i + 1))
break
fi
done
if [ $start_index -gt -1 ]; then
# Initialize an array for URLs
declare -a URLS
url_pattern="^(http|https|ftp)://[a-zA-Z0-9.-]+(\.[a-zA-Z]{2,4})(/[a-zA-Z0-9_.-]+)*(\/?)(\?[a-zA-Z0-9_.-]+=[a-zA-Z0-9%_.-]+)*)?$"
url_pattern="^(http|https|ftp)://[a-zA-Z0-9.-]+(\.[a-zA-Z]{2,4})(/[a-zA-Z0-9_.-]+)*(\/?)(\?[a-zA-Z0-9_.-]+=[a-zA-Z0-9%_.-]+)*$"
for ((i=start_index; i<${#lines[@]}; i++)); do
url="${lines[$i]}"
url="${url//- /}"
# Remove any extra characters or spaces
url="${url//[- ]/}"
if [[ $url =~ $url_pattern ]]; then
URLS+=("$url")
URLS+=("$url")
fi
done
for TEST_WEBSITE in ${URLS[@]}; do
for TEST_WEBSITE in "${URLS[@]}"; do
echo "::group::Custom metrics for $TEST_WEBSITE"
node tests/wpt.js $TEST_WEBSITE "$METRICS"
node tests/wpt.js "$TEST_WEBSITE" "$METRICS"
echo "::endgroup::"
done
else
echo "No websites found."
fi
env:
WPT_SERVER: "webpagetest.httparchive.org"
WPT_API_KEY: ${{ secrets.HA_API_KEY }}
Expand Down

0 comments on commit 37882ad

Please sign in to comment.