Skip to content

Commit

Permalink
feat: Add GC authentication to Lighthouse GitHub Action
Browse files Browse the repository at this point in the history
  • Loading branch information
flozia committed Jan 2, 2025
1 parent 049b67d commit 4747c29
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/lighthouse_cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
lhci:
name: Lighthouse Report - ${{ inputs.environment != null && inputs.environment || 'prod' }}
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20.9.x
Expand All @@ -32,5 +35,12 @@ jobs:
run: |
npm ci
npm run build-cronjobs
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ secrets.GC_LIGHTHOUSE_WORKLOAD_IDENTITY_PROVIDER }}
service_account: ${{ secrets.GC_LIGHTHOUSE_SERVICE_ACCOUNT }}
env:
BQ_LIGHTHOUSE_DATASET: ${{ secrets.BQ_LIGHTHOUSE_DATASET }}
- name: Report results
run: npm run cron:report-lighthouse-results
64 changes: 61 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
},
"devDependencies": {
"@faker-js/faker": "^9.3.0",
"@google-cloud/bigquery": "^7.9.1",
"@playwright/test": "^1.49.1",
"@storybook/addon-a11y": "^8.4.7",
"@storybook/addon-actions": "^8.4.7",
Expand Down
15 changes: 15 additions & 0 deletions src/scripts/cronjobs/reportLighthouseResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

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

const AUDITS_TO_INCLUDE = [
Expand All @@ -29,6 +30,17 @@ type LighthouseResult = {
};
};

async function getLighthouseResults() {
try {
const bigQueryClient = new BigQuery();
const query = `SELECT * FROM ${process.env.BQ_LIGHTHOUSE_DATASET}`;
const [rows] = await bigQueryClient.query({ query });
return rows;
} catch (error) {
console.error("Error querying Lighthouse results", error);
}
}

async function run() {
// The Lighthouse report that will be created by running LHCI.
const lighthouseResults: LighthouseResult[] =
Expand Down Expand Up @@ -72,6 +84,9 @@ async function run() {
});
console.table(transformedData);
logger.info("lighthouse_report", lighthouseReport);

const results = getLighthouseResults();
console.info("BigQuery dataset", results);
}

try {
Expand Down

0 comments on commit 4747c29

Please sign in to comment.