From 4747c290f2e748ebd7534bce02e59b60b2e5bae4 Mon Sep 17 00:00:00 2001 From: Florian Zia Date: Thu, 2 Jan 2025 12:39:20 +0100 Subject: [PATCH] feat: Add GC authentication to Lighthouse GitHub Action --- .github/workflows/lighthouse_cron.yml | 10 +++ package-lock.json | 64 ++++++++++++++++++- package.json | 1 + .../cronjobs/reportLighthouseResults.ts | 15 +++++ 4 files changed, 87 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lighthouse_cron.yml b/.github/workflows/lighthouse_cron.yml index 06d2fe70e63..72ecf194c02 100644 --- a/.github/workflows/lighthouse_cron.yml +++ b/.github/workflows/lighthouse_cron.yml @@ -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 @@ -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 diff --git a/package-lock.json b/package-lock.json index 17585b86417..3e35e176ad5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,6 +54,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", @@ -3680,6 +3681,54 @@ "tslib": "2" } }, + "node_modules/@google-cloud/bigquery": { + "version": "7.9.1", + "resolved": "https://registry.npmjs.org/@google-cloud/bigquery/-/bigquery-7.9.1.tgz", + "integrity": "sha512-ZkcRMpBoFLxIh6TiQBywA22yT3c2j0f07AHWEMjtYqMQzZQbFrpxuJU2COp3tyjZ91ZIGHe4gY7/dGZL88cltg==", + "dev": true, + "dependencies": { + "@google-cloud/common": "^5.0.0", + "@google-cloud/paginator": "^5.0.2", + "@google-cloud/precise-date": "^4.0.0", + "@google-cloud/promisify": "^4.0.0", + "arrify": "^2.0.1", + "big.js": "^6.0.0", + "duplexify": "^4.0.0", + "extend": "^3.0.2", + "is": "^3.3.0", + "stream-events": "^1.0.5", + "uuid": "^9.0.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@google-cloud/bigquery/node_modules/big.js": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/big.js/-/big.js-6.2.2.tgz", + "integrity": "sha512-y/ie+Faknx7sZA5MfGA2xKlu0GDv8RWrXGsmlteyJQ2lvoKv9GBK/fpRMc2qlSoBAgNxrixICFCBefIq8WCQpQ==", + "dev": true, + "engines": { + "node": "*" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/bigjs" + } + }, + "node_modules/@google-cloud/bigquery/node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "dev": true, + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/@google-cloud/common": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/@google-cloud/common/-/common-5.0.1.tgz", @@ -3754,9 +3803,9 @@ } }, "node_modules/@google-cloud/paginator": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/@google-cloud/paginator/-/paginator-5.0.0.tgz", - "integrity": "sha512-87aeg6QQcEPxGCOthnpUjvw4xAZ57G7pL8FS0C4e/81fr3FjkpUpibf1s2v5XGyGhUVGF4Jfg7yEcxqn2iUw1w==", + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@google-cloud/paginator/-/paginator-5.0.2.tgz", + "integrity": "sha512-DJS3s0OVH4zFDB1PzjxAsHqJT6sKVbRwwML0ZBP9PbU7Yebtu/7SWMRzvO2J3nUi9pRNITCfu4LJeooM2w4pjg==", "dependencies": { "arrify": "^2.0.0", "extend": "^3.0.2" @@ -16451,6 +16500,15 @@ "node": ">=10" } }, + "node_modules/is": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/is/-/is-3.3.0.tgz", + "integrity": "sha512-nW24QBoPcFGGHJGUwnfpI7Yc5CdqWNdsyHQszVE/z2pKHXzh7FZ5GWhJqSyaQ9wMkQnsTx+kAI8bHlCX4tKdbg==", + "dev": true, + "engines": { + "node": "*" + } + }, "node_modules/is-arguments": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", diff --git a/package.json b/package.json index e220e46efbe..107d6519ab2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/scripts/cronjobs/reportLighthouseResults.ts b/src/scripts/cronjobs/reportLighthouseResults.ts index 8c0764aca68..e5a5be2b243 100644 --- a/src/scripts/cronjobs/reportLighthouseResults.ts +++ b/src/scripts/cronjobs/reportLighthouseResults.ts @@ -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 = [ @@ -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[] = @@ -72,6 +84,9 @@ async function run() { }); console.table(transformedData); logger.info("lighthouse_report", lighthouseReport); + + const results = getLighthouseResults(); + console.info("BigQuery dataset", results); } try {