forked from dochne/wappalyzer
-
Notifications
You must be signed in to change notification settings - Fork 26
89 lines (78 loc) · 2.7 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: Tests
on:
pull_request_target:
branches:
- main
paths:
- "src/technologies/*.json"
- "src/categories.json"
- "src/groups.json"
- "tests/*.js"
workflow_dispatch:
jobs:
test:
name: WebPageTest Test Cases
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Install dependencies
run: yarn install
- name: Validate
run: yarn run validate
- name: Run WebPageTest with unit tests
id: unit-test
env:
WPT_SERVER: "webpagetest.httparchive.org"
WPT_API_KEY: ${{ secrets.HA_API_KEY }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: yarn test
- name: Run WebPageTest for more websites
id: wpt-test
env:
WPT_SERVER: "webpagetest.httparchive.org"
WPT_API_KEY: ${{ secrets.HA_API_KEY }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_BODY: ${{ github.event.pull_request.body }}
run: |
# Read PR body into an array, removing line breaks and carriage returns
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
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%_.-=]+)*)"
for ((i=start_index; i<${#lines[@]}; i++)); do
if [[ ${lines[$i]} =~ $url_pattern ]]; then
URLS+=("${BASH_REMATCH[1]}")
fi
done
# Run WebPageTest for each URL
for TEST_WEBSITE in "${URLS[@]}"; do
echo "::group::Running WPT test for $TEST_WEBSITE"
node tests/wpt.js "$TEST_WEBSITE"
echo "::endgroup::"
done
else
echo "No websites found."
fi
- name: Add comment with results
uses: mshick/add-pr-comment@v2
if: steps.unit-test.outcome == 'success' || steps.wpt-test.outcome == 'success'
with:
refresh-message-position: true
message-path: test-results.md