Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ads files redirected #136

Merged
merged 13 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 20 additions & 48 deletions .github/workflows/wpt-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ jobs:
fetch-depth: 0

- name: Install dependencies
run: |
npm install webpagetest
npm install jest
run: npm install jest webpagetest

- name: Run WebPageTest with unit tests
run: npm test
Expand All @@ -31,57 +29,31 @@ jobs:
WPT_API_KEY: ${{ secrets.HA_API_KEY }}

- name: Run WebPageTest for more websites
run: |
# Get the PR body
PR_BODY="$(cat <<'EOF'
${{ github.event.pull_request.body }}
EOF
)"

# Read PR body into an array, removing line breaks and carriage returns
declare -a lines
while IFS= read -r line; do
lines+=("${line//[$'\r\n']}")
done <<< "$PR_BODY"

# Find the index of the line after "**Test websites**:"
start_index=-1
for ((i=0; i<${#lines[@]}; i++)); do
if [[ "${lines[$i]}" == *"**Test websites**:"* ]]; then
start_index=$((i + 1))
break
fi
done

# If the index is valid, then parse the URLs
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%_.-]+)*(\#?)([a-zA-Z0-9%_.-=]+)*)"
run: node tests/wpt.js
env:
WPT_SERVER: "webpagetest.httparchive.org"
WPT_API_KEY: ${{ secrets.HA_API_KEY }}
PR_BODY: ${{ github.event.pull_request.body }}
rviscomi marked this conversation as resolved.
Show resolved Hide resolved

for ((i=start_index; i<${#lines[@]}; i++)); do
if [[ ${lines[$i]} =~ $url_pattern ]]; then
URLS+=("${BASH_REMATCH[1]}")
fi
done
- name: Upload artifact if needed
id: artifact-upload-step
uses: actions/upload-artifact@v4
with:
path: artifact.md

# Run WebPageTest for each URL
for TEST_WEBSITE in "${URLS[@]}"; do
echo "::group::Custom metrics for $TEST_WEBSITE"
node tests/wpt.js "$TEST_WEBSITE"
echo "::endgroup::"
done
- name: Update comment.md
run: |
if grep -q "{artifact-url}" comment.md; then
artifact_url="${{ steps.artifact-upload-step.outputs.artifact-url }}"
sed -i "s|{artifact-url}|$artifact_url|g" comment.md
echo "Placeholder {artifact-url} replaced with a value: $artifact_url."
else
echo "No websites found."
echo "No placeholder {artifact-url} found in comment.md."
fi

env:
WPT_SERVER: "webpagetest.httparchive.org"
WPT_API_KEY: ${{ secrets.HA_API_KEY }}

- name: Add comment with results
- name: Add comment to PR
uses: mshick/add-pr-comment@v2
if: always()
with:
refresh-message-position: true
message-path: test-results.md
message-path: comment.md
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
.DS_Store
**/.DS_Store
.env
2 changes: 2 additions & 0 deletions dist/ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const parseAdsTxt = async (response) => {
result = {
...result,
...{
redirected_to: response.redirected ? response.url : null,
account_count: 0,
account_types: {
direct: {
Expand Down Expand Up @@ -118,6 +119,7 @@ const parseSellersJSON = async (response) => {
result = {
...result,
...{
redirected_to: response.redirected ? response.url : null,
seller_count: 0,
seller_types: {
publisher: {
Expand Down
Loading
Loading