Skip to content

Commit 2ea6b87

Browse files
authored
feat(run-lighthouse-tests): init [ED-325] (#17)
1 parent c1bad15 commit 2ea6b87

File tree

17 files changed

+488
-44
lines changed

17 files changed

+488
-44
lines changed

.github/workflows/test-actions.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ concurrency:
88
cancel-in-progress: true
99

1010
jobs:
11-
setup-wp-and-elementor-env:
12-
name: Setup WP and Elementor env
11+
test-performance-flow:
12+
name: Performance flow (Setup WP, Elementor env and run Lighthouse tests)
1313
runs-on: ubuntu-latest
1414
if: startsWith( github.repository, 'elementor/' )
1515
steps:
@@ -34,24 +34,41 @@ jobs:
3434
- name: Setup Elementor Env
3535
uses: ./actions/setup-elementor-env
3636
with:
37-
env: 'development'
37+
env: 'testing'
3838
experiments: |-
3939
pages_panel:true
4040
editor_v2:false
4141
e_nested_atomic_repeaters:false
4242
templates: |-
4343
elementor-templates
4444
45-
- name: Ping to check if the site is up and import successful
45+
- name: Run Lighthouse tests
46+
uses: ./actions/run-lighthouse-tests
47+
id: run-lighthouse-tests
48+
with:
49+
number-of-runs: 3
50+
urls: |-
51+
rquth:http://localhost:8889/react-query-under-the-hood/
52+
categories: |-
53+
performance
54+
55+
- name: Check if score meets the threshold
4656
uses: actions/github-script@v7
4757
env:
48-
URL_TO_CHECK: 'http://localhost:8888/react-query-under-the-hood/'
58+
PERFORMANCE_SCORE: ${{ steps.run-lighthouse-tests.outputs.rquth-performance-score }}
59+
THRESHOLD: 0.70
4960
with:
5061
script: |
51-
const { URL_TO_CHECK } = process.env;
52-
53-
const response = await fetch(URL_TO_CHECK)
62+
const { PERFORMANCE_SCORE, THRESHOLD } = process.env;
5463
55-
if (!response.ok) {
56-
core.setFailed(`Failed to ping ${URL_TO_CHECK}, status: ${response.status}.`);
64+
if (PERFORMANCE_SCORE < THRESHOLD) {
65+
core.setFailed(`Performance score is ${PERFORMANCE_SCORE}, which is below the threshold of ${threshold}.`);
5766
}
67+
68+
- name: Upload reports
69+
if: failure() && steps.run-lighthouse-tests.outputs.reports-path
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: performance-reports
73+
path: ${{ steps.run-lighthouse-tests.outputs.reports-path }}
74+
retention-days: 3

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ node_modules/
33
.idea/
44
.DS_Store/
55
tmp/
6+
.lhci/
7+
.lighthouseci/
68
.wp-env.json
9+
.lighthouserc.json
710

811
*.log
912
*.map

actions/inputs.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import * as core from '@actions/core';
22

33
export function getStringInput(name: string) {
4-
return core.getInput(name, { trimWhitespace: true });
4+
return core.getInput(name, { trimWhitespace: true }) || null;
5+
}
6+
7+
export function getNumberInput(name: string) {
8+
const value = getStringInput(name);
9+
10+
return value ? parseFloat(value) : null;
511
}
612

713
export function getBooleanInput(name: string) {
@@ -17,7 +23,7 @@ export function getMapInput(name: string): Record<string, string> {
1723
core
1824
.getMultilineInput(name, { trimWhitespace: true })
1925
.reduce<Array<[string, string]>>((acc, line) => {
20-
const [key, value] = line.split(':');
26+
const [, key, value] = line.match(/^(.+?):(.+)$/) || [];
2127

2228
if (key && value) {
2329
acc.push([key.trim(), value.trim()]);

actions/outputs.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as core from '@actions/core';
2+
import styles from 'ansi-styles';
3+
4+
export function setOutput(name: string, value: unknown) {
5+
core.info(
6+
` -> ${styles.cyan.open}[${name}]${styles.cyan.close} ${JSON.stringify(value)}`,
7+
);
8+
core.setOutput(name, value);
9+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Do not commit your actual .env file to Git! This may contain secrets or other
2+
# private information.
3+
4+
# Enable/disable step debug logging (default: `false`). For local debugging, it
5+
# may be useful to set it to `true`.
6+
ACTIONS_STEP_DEBUG=true
7+
8+
# GitHub Actions inputs should follow `INPUT_<name>` format (case-insensitive).
9+
INPUT_urls="
10+
rquth:http://localhost:8889/react-query-under-the-hood/
11+
"
12+
INPUT_categories="
13+
performance
14+
"
15+
INPUT_number-of-runs=3
16+
INPUT_skip-lhci-install="false"
17+
18+
# GitHub Actions default environment variables. These are set for every run of a
19+
# workflow and can be used in your actions. Setting the value here will override
20+
# any value set by the local-action tool.
21+
# https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
22+
23+
# CI="true"
24+
# GITHUB_ACTION=""
25+
# GITHUB_ACTION_PATH=""
26+
# GITHUB_ACTION_REPOSITORY=""
27+
# GITHUB_ACTIONS=""
28+
# GITHUB_ACTOR="mona"
29+
# GITHUB_ACTOR_ID="123456789"
30+
# GITHUB_API_URL=""
31+
# GITHUB_BASE_REF=""
32+
# GITHUB_ENV=""
33+
# GITHUB_EVENT_NAME=""
34+
# GITHUB_EVENT_PATH=""
35+
# GITHUB_GRAPHQL_URL=""
36+
# GITHUB_HEAD_REF=""
37+
# GITHUB_JOB=""
38+
# GITHUB_OUTPUT=""
39+
# GITHUB_PATH=""
40+
# GITHUB_REF=""
41+
# GITHUB_REF_NAME=""
42+
# GITHUB_REF_PROTECTED=""
43+
# GITHUB_REF_TYPE=""
44+
# GITHUB_REPOSITORY=""
45+
# GITHUB_REPOSITORY_ID=""
46+
# GITHUB_REPOSITORY_OWNER=""
47+
# GITHUB_REPOSITORY_OWNER_ID=""
48+
# GITHUB_RETENTION_DAYS=""
49+
# GITHUB_RUN_ATTEMPT=""
50+
# GITHUB_RUN_ID=""
51+
# GITHUB_RUN_NUMBER=""
52+
# GITHUB_SERVER_URL=""
53+
# GITHUB_SHA=""
54+
# GITHUB_STEP_SUMMARY=""
55+
# GITHUB_TRIGGERING_ACTOR=""
56+
# GITHUB_WORKFLOW=""
57+
# GITHUB_WORKFLOW_REF=""
58+
# GITHUB_WORKFLOW_SHA=""
59+
# GITHUB_WORKSPACE=""
60+
# RUNNER_ARCH=""
61+
# RUNNER_DEBUG=""
62+
# RUNNER_NAME=""
63+
# RUNNER_OS=""
64+
# RUNNER_TEMP=""
65+
# RUNNER_TOOL_CACHE=""
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Run Lighthouse tests
2+
3+
### TODO
4+
5+
- [ ] Need to define baseline for all pages
6+
- [ ] Need to allow pages to define their own baseline and override the default
7+
- [ ] Need to define how to calculate the score
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Run Lighthouse tests
2+
description: Run Lighthouse tests on given URLs
3+
4+
inputs:
5+
urls:
6+
description: A map of URLs to test, with aliases as keys, separated by new lines (e.g. `moshe:http://localhost:8889/moshe \n haim:http://localhost:8889/haim`)
7+
required: true
8+
categories:
9+
description: A list of categories to test, separated by new lines (e.g. `performance \n accessibility` \n `best-practices` \n `seo`)
10+
required: true
11+
number-of-runs:
12+
description: The number of times to run the Lighthouse test on each URL
13+
required: false
14+
default: '3'
15+
skip-lhci-install:
16+
description: Skip installing the LHCI package (for debugging purposes or using custom LHCI version)
17+
required: false
18+
default: 'false'
19+
20+
runs:
21+
using: node20
22+
main: ./dist/index.cjs

actions/run-lighthouse-tests/dist/index.cjs

Lines changed: 75 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { run } from './main';
2+
3+
void run();

0 commit comments

Comments
 (0)