Skip to content

Commit 4747c29

Browse files
committed
feat: Add GC authentication to Lighthouse GitHub Action
1 parent 049b67d commit 4747c29

File tree

4 files changed

+87
-3
lines changed

4 files changed

+87
-3
lines changed

.github/workflows/lighthouse_cron.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ jobs:
1616
lhci:
1717
name: Lighthouse Report - ${{ inputs.environment != null && inputs.environment || 'prod' }}
1818
runs-on: ubuntu-latest
19+
permissions:
20+
contents: read
21+
id-token: write
1922
steps:
2023
- uses: actions/checkout@v4
2124
- name: Use Node.js 20.9.x
@@ -32,5 +35,12 @@ jobs:
3235
run: |
3336
npm ci
3437
npm run build-cronjobs
38+
- name: Authenticate to Google Cloud
39+
uses: google-github-actions/auth@v2
40+
with:
41+
workload_identity_provider: ${{ secrets.GC_LIGHTHOUSE_WORKLOAD_IDENTITY_PROVIDER }}
42+
service_account: ${{ secrets.GC_LIGHTHOUSE_SERVICE_ACCOUNT }}
43+
env:
44+
BQ_LIGHTHOUSE_DATASET: ${{ secrets.BQ_LIGHTHOUSE_DATASET }}
3545
- name: Report results
3646
run: npm run cron:report-lighthouse-results

package-lock.json

Lines changed: 61 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
},
116116
"devDependencies": {
117117
"@faker-js/faker": "^9.3.0",
118+
"@google-cloud/bigquery": "^7.9.1",
118119
"@playwright/test": "^1.49.1",
119120
"@storybook/addon-a11y": "^8.4.7",
120121
"@storybook/addon-actions": "^8.4.7",

src/scripts/cronjobs/reportLighthouseResults.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
import { readFile } from "node:fs/promises";
6+
import { BigQuery } from "@google-cloud/bigquery";
67
import { logger } from "../../app/functions/server/logging";
78

89
const AUDITS_TO_INCLUDE = [
@@ -29,6 +30,17 @@ type LighthouseResult = {
2930
};
3031
};
3132

33+
async function getLighthouseResults() {
34+
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;
39+
} catch (error) {
40+
console.error("Error querying Lighthouse results", error);
41+
}
42+
}
43+
3244
async function run() {
3345
// The Lighthouse report that will be created by running LHCI.
3446
const lighthouseResults: LighthouseResult[] =
@@ -72,6 +84,9 @@ async function run() {
7284
});
7385
console.table(transformedData);
7486
logger.info("lighthouse_report", lighthouseReport);
87+
88+
const results = getLighthouseResults();
89+
console.info("BigQuery dataset", results);
7590
}
7691

7792
try {

0 commit comments

Comments
 (0)