Skip to content

Commit e4ce3cb

Browse files
committed
wip: Store Lighthouse results
1 parent 4dd2c01 commit e4ce3cb

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

.github/workflows/lighthouse_cron.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ on:
77
environment:
88
description: 'Environment to run LHCI against'
99
required: false
10-
default: 'prod'
10+
default: 'stage'
1111
type: choice
1212
options:
1313
- stage
1414
- prod
1515
jobs:
1616
lhci:
17-
name: Lighthouse Report - ${{ inputs.environment != null && inputs.environment || 'prod' }}
17+
name: Lighthouse Report - ${{ inputs.environment != null && inputs.environment || 'stage' }}
1818
runs-on: ubuntu-latest
19+
environment: ${{ inputs.environment != null && inputs.environment || 'stage' }}
1920
permissions:
2021
contents: read
2122
id-token: write
@@ -40,7 +41,7 @@ jobs:
4041
with:
4142
workload_identity_provider: ${{ secrets.GC_LIGHTHOUSE_WORKLOAD_IDENTITY_PROVIDER }}
4243
service_account: ${{ secrets.GC_LIGHTHOUSE_SERVICE_ACCOUNT }}
43-
env:
44-
BQ_LIGHTHOUSE_DATASET: ${{ secrets.BQ_LIGHTHOUSE_DATASET }}
4544
- name: Report results
4645
run: npm run cron:report-lighthouse-results
46+
env:
47+
BQ_LIGHTHOUSE_DATASET: ${{ secrets.BQ_LIGHTHOUSE_DATASET }}

src/scripts/cronjobs/reportLighthouseResults.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,28 @@ type LighthouseResult = {
3131
};
3232

3333
async function getLighthouseResults() {
34+
if (
35+
!process.env.BQ_LIGHTHOUSE_PROJECT ||
36+
!process.env.BQ_LIGHTHOUSE_DATASET ||
37+
!process.env.BQ_LIGHTHOUSE_TABLE
38+
) {
39+
return null;
40+
}
41+
3442
try {
35-
const bigQueryClient = new BigQuery();
36-
const query = `SELECT * FROM ${process.env.BQ_LIGHTHOUSE_DATASET}`;
37-
const [rows] = await bigQueryClient.query({ query });
38-
return rows;
43+
const bigQueryClient = new BigQuery({
44+
projectId: process.env.BQ_LIGHTHOUSE_PROJECT,
45+
});
46+
47+
const table = bigQueryClient
48+
.dataset(process.env.BQ_LIGHTHOUSE_DATASET)
49+
.table(process.env.BQ_LIGHTHOUSE_TABLE);
50+
const [metadata] = await table.getMetadata();
51+
52+
console.log(
53+
`Table description: ${metadata.description || "No description"}`,
54+
);
55+
return table;
3956
} catch (error) {
4057
console.error("Error querying Lighthouse results", error);
4158
}
@@ -85,7 +102,7 @@ async function run() {
85102
console.table(transformedData);
86103
logger.info("lighthouse_report", lighthouseReport);
87104

88-
const results = getLighthouseResults();
105+
const results = await getLighthouseResults();
89106
console.info("BigQuery dataset", results);
90107
}
91108

0 commit comments

Comments
 (0)