Skip to content

Commit

Permalink
wip: Store Lighthouse results
Browse files Browse the repository at this point in the history
  • Loading branch information
flozia committed Jan 17, 2025
1 parent 4dd2c01 commit e4ce3cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/lighthouse_cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
27 changes: 22 additions & 5 deletions src/scripts/cronjobs/reportLighthouseResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit e4ce3cb

Please sign in to comment.