Last active
August 5, 2023 08:48
-
-
Save mike-at-redspace/ef890657ad3e5299f8d328932003f79d to your computer and use it in GitHub Desktop.
Website Speed Test Github Action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// webpagetest-action/index.js | |
const core = require('@actions/core'); | |
const webpagetest = require('webpagetest'); | |
async function run() { | |
try { | |
const domains = core.getInput('domains'); | |
const apiKey = core.getInput('key'); | |
const results = []; | |
for (let domain of domains.split(',')) { | |
const testId = await webpagetest.runTest(domain, {key: apiKey}); | |
const resultUrl = `https://www.webpagetest.org/result/${testId}`; | |
results.push(resultUrl); | |
} | |
core.setOutput('results', JSON.stringify(results)); | |
} catch (error) { | |
core.setFailed(error.message); | |
} | |
} | |
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .github/workflows/speed-test.yml | |
name: Website Speed Test | |
on: | |
pull_request: | |
types: [opened, synchronize] | |
jobs: | |
speed-test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Run tests | |
id: webpagetest | |
uses: webpagetest-action | |
- name: Post results | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const domains = ${{ github.event.inputs.domains }}; | |
const results = ${{ steps.webpagetest.outputs.results }}; | |
let comment = '## WebPageTest Results\n'; | |
for (let i = 0; i < domains.length; i++) { | |
const domain = domains[i]; | |
const resultUrl = results[i]; | |
comment += `- [${domain}](${resultUrl})\n`; | |
} | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo, | |
body: comment | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment