Skip to content

Commit f15a925

Browse files
committed
Lighthouse: DUmmy test
1 parent fb8b4f2 commit f15a925

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

.github/workflows/lighthouse.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Update lighthouse report artifact for main branch
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- "**"
8+
workflow_dispatch:
9+
10+
env:
11+
GITHUB_PR_NUMBER: "main"
12+
jobs:
13+
generate-lighthouse-report:
14+
runs-on: ubuntu-22.04
15+
steps:
16+
- uses: actions/checkout@v5
17+
with:
18+
ref: ${{ github.event.workflow_run.head_branch }}
19+
- uses: actions/setup-node@v5
20+
with:
21+
node-version: 18
22+
- name: Setup Hugo
23+
uses: peaceiris/actions-hugo@75d2e84710de30f6ff7268e08f310b60ef14033f # v3.0.0
24+
with:
25+
hugo-version: '0.147.8'
26+
extended: true
27+
- name: Installing packages
28+
run: cd performance && npm ci
29+
- name: Run hugo site
30+
run: hugo serve
31+
- name: Generating lighthouse reports for main...
32+
run: |
33+
node performance/lighthouse-script.js

performance/lighthouse-script.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ const fs = require('fs');
44
const PORT = 8041;
55
const PR_NUMBER = process.env.GITHUB_PR_NUMBER;
66
const OUTPUT_DIR = './lighthouse-reports';
7-
const ENVIRONMENTS = [
8-
{
9-
title: 'pr',
10-
url: `https://frontdoor-test-docs.nginx.com/previews/nginx-hugo-theme/${PR_NUMBER}/`,
11-
},
12-
];
137

148
const signIntoFrontDoor = async (browser, env) => {
159
const page = await browser.newPage();
@@ -36,21 +30,34 @@ const generateLighthouseReport = async (env) => {
3630
console.log(`Generated report for ${env['title']}...`);
3731
};
3832

39-
(async () => {
40-
const browser = await puppeteer.launch({
33+
const launchBrowser = async () => {
34+
return await puppeteer.launch({
4135
args: [`--remote-debugging-port=${PORT}`],
4236
headless: true,
4337
});
38+
};
39+
40+
(async () => {
41+
const browser = await launchBrowser();
4442
if (!fs.existsSync(OUTPUT_DIR)) {
4543
fs.mkdirSync(OUTPUT_DIR);
4644
}
4745

48-
for (const env of ENVIRONMENTS) {
49-
if (env['title'] === 'pr') {
50-
await signIntoFrontDoor(browser, env);
51-
}
52-
await generateLighthouseReport(env);
46+
let environment = {};
47+
if (PR_NUMBER === 'main') {
48+
environment = {
49+
title: 'main',
50+
url: 'http://localhost:1313/',
51+
};
52+
} else {
53+
environment = {
54+
title: 'pr',
55+
url: `https://frontdoor-test-docs.nginx.com/previews/nginx-hugo-theme/${PR_NUMBER}/`,
56+
};
5357
}
5458

59+
await signIntoFrontDoor(browser, environment);
60+
await generateLighthouseReport(environment);
61+
5562
browser.close();
5663
})();

0 commit comments

Comments
 (0)