Skip to content

Commit

Permalink
Merge pull request #38 from max-ostapenko/prospective-tortoise
Browse files Browse the repository at this point in the history
Show detected technologies for webalmanac + PR test fix
  • Loading branch information
pmeenan authored Jun 28, 2024
2 parents e147ef4 + 9ab94b7 commit 13af85d
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 264 deletions.
18 changes: 4 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ jobs:
WPT_SERVER: "webpagetest.httparchive.org"
WPT_API_KEY: ${{ secrets.HA_API_KEY }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
echo "::group::Unit tests"
yarn test
echo "::endgroup::"
run: yarn test

- name: Run WebPageTest for more websites
id: wpt-test
Expand All @@ -46,17 +43,10 @@ jobs:
WPT_API_KEY: ${{ secrets.HA_API_KEY }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
# Get the PR body
PR_BODY="$(cat <<'EOF'
${{ github.event.pull_request.body }}
EOF
)"
PR_BODY="${{ github.event.pull_request.body }}"
# 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"
IFS=$'\n' read -d '' -r -a lines <<< "${PR_BODY//$'\r\n'/ }"
# Find the index of the line after "**Test websites**:"
start_index=-1
Expand All @@ -70,7 +60,7 @@ jobs:
# If the index is valid, then parse the URLs
if [ $start_index -gt -1 ]; then
# Initialize an array for URLs
declare -a 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
Expand Down
2 changes: 1 addition & 1 deletion src/technologies/g.json
Original file line number Diff line number Diff line change
Expand Up @@ -2615,4 +2615,4 @@
"implies": "Python",
"website": "https://gunicorn.org"
}
}
}
23 changes: 13 additions & 10 deletions tests/wpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const isDirectRun = require.main === module

const wptServer = process.env.WPT_SERVER
const wptApiKey = process.env.WPT_API_KEY
const PRnumber = parseInt(process.env.PR_NUMBER)
const prNumber = parseInt(process.env.PR_NUMBER)
const wpt = new WebPageTest(wptServer, wptApiKey)

/**
Expand All @@ -17,11 +17,13 @@ const wpt = new WebPageTest(wptServer, wptApiKey)
* @throws {Error} If the test run fails or the response status code is not 200.
*/
function runWPTTest(url) {
const options = { key: wptApiKey, wappalyzerPR: PRnumber }
const options = { key: wptApiKey, wappalyzerPR: prNumber }

return new Promise((resolve, reject) => {
wpt.runTestAndWait(url, options, (error, response) => {
if (error || response.statusCode !== 200) {
console.error(`WPT test run for ${url} failed:`)
console.error(error || response)
reject(error || response)
} else {
const technologies = {
Expand All @@ -34,14 +36,15 @@ function runWPTTest(url) {

fs.appendFileSync(
'test-results.md',
'<details>\n' +
`<summary><strong>WPT test run for ${url}</strong></summary>\n\n` +
`Results: ${response.data.summary}\n` +
(isDirectRun
? 'Detected technologies:\n' +
`\`\`\`json\n${JSON.stringify(technologies, null, 4)}\n\`\`\`\n`
: '') +
'</details>\n'
`<details>
<summary><strong>WPT test run for ${url}</strong></summary>
WPT test run results: ${response.data.summary}
Detected technologies:
\`\`\`json
${JSON.stringify(technologies, null, 4)}
\`\`\`
</details>\n\n`
)

resolve(response.data)
Expand Down
Loading

0 comments on commit 13af85d

Please sign in to comment.