Skip to content

Commit a52cb5b

Browse files
committed
enable settings to be passed in via a JSON object for greater flexiblity
1 parent 54b3393 commit a52cb5b

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

action.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
name: 'WebPageTest GitHub Action'
2-
description: 'Automatically run WebPageTest against URLs'
2+
author: 'WebPageTest'
3+
description: 'Automatically test code changes in WebPageTest and enforce performance budgets'
34
inputs:
45
apiKey:
56
description: 'WebPageTest API Token'
67
required: true
78
urls:
89
description: 'List of URL(s) to test'
10+
required: true
911
budget:
10-
description: 'WebPageTest Test Specs JSON file'
12+
description: 'Path to WebPageTest testspecs.json file'
13+
required: false
1114
label:
1215
description: 'Label for test (shows up in WebPageTest)'
16+
required: false
17+
wptOptions:
18+
description: 'Path to JSON file with WebPageTest test options (see https://github.com/marcelduran/webpagetest-api#test-works-for-runtest-method-only)'
19+
required: false
1320
GITHUB_TOKEN:
1421
description: 'Secret GitHub Token (automatically provided by GitHub)'
1522
runs:
1623
using: 'node12'
17-
main: 'index.js'
24+
main: 'index.js'
25+
branding:
26+
icon: 'bar-chart-2'
27+
color: 'blue'

index.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ const WebPageTest = require("webpagetest");
22
const core = require("@actions/core");
33
const github = require('@actions/github');
44
const ejs = require('ejs');
5+
const { cornflowerblue } = require("color-name");
56

67
const WPT_BUDGET = core.getInput('budget');
8+
const WPT_OPTIONS = core.getInput('wptOptions');
79
const WPT_API_KEY = core.getInput('apiKey');
810
const WPT_URLS = core.getInput('urls').split("\n");
911
const WPT_LABEL = core.getInput('label');
@@ -69,12 +71,25 @@ async function run() {
6971
//TODO: make this configurable
7072
let options = {
7173
"firstViewOnly": true,
72-
"runs": 1,
73-
"location": 'Dulles:Chrome',
74+
"runs": 3,
75+
"location": 'Dulles_MotoG4',
7476
"connectivity": '4G',
7577
"pollResults": 5,
7678
"timeout": 240
7779
}
80+
if (WPT_OPTIONS) {
81+
let settings = require(WPT_OPTIONS);
82+
if (typeof settings === 'object' && settings !== null) {
83+
core.debug(settings);
84+
options = {
85+
...options,
86+
...settings
87+
}
88+
} else {
89+
core.setFailed("The specified WebPageTest settings aren't a valid JavaScript object");
90+
}
91+
92+
}
7893
if (WPT_BUDGET) {
7994
options.specs = require(WPT_BUDGET);
8095
}
File renamed without changes.

samples/wpt-options.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"runs": 1,
3+
"location": "Dulles:Chrome"
4+
}

0 commit comments

Comments
 (0)