From e4ce3cbdbefa096256ec0ce05ae4e3b2d4500f75 Mon Sep 17 00:00:00 2001 From: Florian Zia Date: Wed, 15 Jan 2025 18:32:54 +0100 Subject: [PATCH] wip: Store Lighthouse results --- .github/workflows/lighthouse_cron.yml | 9 ++++--- .../cronjobs/reportLighthouseResults.ts | 27 +++++++++++++++---- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/.github/workflows/lighthouse_cron.yml b/.github/workflows/lighthouse_cron.yml index 7bdb4ea87d2..45b52a41e30 100644 --- a/.github/workflows/lighthouse_cron.yml +++ b/.github/workflows/lighthouse_cron.yml @@ -7,15 +7,16 @@ on: environment: description: 'Environment to run LHCI against' required: false - default: 'prod' + default: 'stage' type: choice options: - stage - prod jobs: lhci: - name: Lighthouse Report - ${{ inputs.environment != null && inputs.environment || 'prod' }} + name: Lighthouse Report - ${{ inputs.environment != null && inputs.environment || 'stage' }} runs-on: ubuntu-latest + environment: ${{ inputs.environment != null && inputs.environment || 'stage' }} permissions: contents: read id-token: write @@ -40,7 +41,7 @@ jobs: 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 + env: + BQ_LIGHTHOUSE_DATASET: ${{ secrets.BQ_LIGHTHOUSE_DATASET }} diff --git a/src/scripts/cronjobs/reportLighthouseResults.ts b/src/scripts/cronjobs/reportLighthouseResults.ts index e5a5be2b243..50c04f0ba63 100644 --- a/src/scripts/cronjobs/reportLighthouseResults.ts +++ b/src/scripts/cronjobs/reportLighthouseResults.ts @@ -31,11 +31,28 @@ type LighthouseResult = { }; async function getLighthouseResults() { + if ( + !process.env.BQ_LIGHTHOUSE_PROJECT || + !process.env.BQ_LIGHTHOUSE_DATASET || + !process.env.BQ_LIGHTHOUSE_TABLE + ) { + return null; + } + try { - const bigQueryClient = new BigQuery(); - const query = `SELECT * FROM ${process.env.BQ_LIGHTHOUSE_DATASET}`; - const [rows] = await bigQueryClient.query({ query }); - return rows; + const bigQueryClient = new BigQuery({ + projectId: process.env.BQ_LIGHTHOUSE_PROJECT, + }); + + const table = bigQueryClient + .dataset(process.env.BQ_LIGHTHOUSE_DATASET) + .table(process.env.BQ_LIGHTHOUSE_TABLE); + const [metadata] = await table.getMetadata(); + + console.log( + `Table description: ${metadata.description || "No description"}`, + ); + return table; } catch (error) { console.error("Error querying Lighthouse results", error); } @@ -85,7 +102,7 @@ async function run() { console.table(transformedData); logger.info("lighthouse_report", lighthouseReport); - const results = getLighthouseResults(); + const results = await getLighthouseResults(); console.info("BigQuery dataset", results); }