-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOP-4831: Save Lighthouse HTML reports to S3 (rather than Atlas) (#84)
* comment out most of upload lighthouse, attempt getting upload ready * packaged * eliminate secret * packaged with s3 * use correct client * body * package * print out names * ready * return and no leading slash * leading slash gone * use entire file * full file * no stream * no stream * use aws upload * buffered * buffered * use new upload to s3 within normal action * combine * public-read * package * organize into files * package * lint * pr feedback * package * remove trailing slash
- Loading branch information
Showing
7 changed files
with
49,550 additions
and
2,436 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ExtendedSummary, Summary } from './types'; | ||
|
||
export const DB_NAME = `lighthouse`; | ||
/* Used on PR creation and update (synchronize) */ | ||
export const PR_COLL_NAME = `pr_reports`; | ||
/* Used on merge to main in Snooty to keep running scores of production */ | ||
export const MAIN_COLL_NAME = `main_reports`; | ||
|
||
export const summaryProperties: (keyof Summary)[] = [ | ||
'seo', | ||
'performance', | ||
'best-practices', | ||
'pwa', | ||
'accessibility', | ||
]; | ||
export const extendedSummaryProperties: (keyof ExtendedSummary)[] = [ | ||
'largest-contentful-paint', | ||
'first-contentful-paint', | ||
'total-blocking-time', | ||
'speed-index', | ||
'cumulative-layout-shift', | ||
'interactive', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import * as github from '@actions/github'; | ||
import { readFileAsync } from '.'; | ||
import { extendedSummaryProperties, summaryProperties } from './constants'; | ||
import { | ||
ExtendedSummary, | ||
JsonRun, | ||
Manifest, | ||
RunDocument, | ||
SortedRuns, | ||
} from './types'; | ||
|
||
const getEmptySummary = (): ExtendedSummary => ({ | ||
seo: 0, | ||
performance: 0, | ||
'best-practices': 0, | ||
pwa: 0, | ||
accessibility: 0, | ||
'largest-contentful-paint': 0, | ||
'first-contentful-paint': 0, | ||
'speed-index': 0, | ||
interactive: 0, | ||
'total-blocking-time': 0, | ||
'cumulative-layout-shift': 0, | ||
}); | ||
|
||
const getAverageSummary = ( | ||
manifests: Manifest[], | ||
jsonRuns: JsonRun[], | ||
): ExtendedSummary => { | ||
const summary = getEmptySummary(); | ||
for (const property of summaryProperties) { | ||
summary[property] = | ||
manifests.reduce((acc, cur) => acc + cur.summary[property], 0) / | ||
manifests.length; | ||
} | ||
for (const property of extendedSummaryProperties) { | ||
summary[property] = | ||
jsonRuns.reduce((acc, cur) => acc + cur.audits[property].score, 0) / | ||
jsonRuns.length; | ||
} | ||
return summary; | ||
}; | ||
|
||
/* Reads and returns files of runs in arrays */ | ||
const getRuns = async ( | ||
manifests: Manifest[], | ||
): Promise<{ jsonRuns: JsonRun[]; htmlRuns: string[] }> => { | ||
const jsonRuns = await Promise.all( | ||
manifests.map(async manifest => | ||
JSON.parse((await readFileAsync(manifest.jsonPath)).toString()), | ||
), | ||
); | ||
|
||
const htmlRuns = await Promise.all( | ||
manifests.map(async manifest => | ||
(await readFileAsync(manifest.htmlPath)).toString(), | ||
), | ||
); | ||
|
||
return { jsonRuns, htmlRuns }; | ||
}; | ||
|
||
export const sortAndAverageRuns = async ( | ||
manifests: Manifest[], | ||
): Promise<SortedRuns[]> => { | ||
const uniqueUrls = Array.from( | ||
new Set(manifests.map(manifest => manifest.url)), | ||
); | ||
|
||
const runs: { | ||
htmlRuns: string[]; | ||
summary: ExtendedSummary; | ||
url: string; | ||
}[] = await Promise.all( | ||
uniqueUrls.map(async url => { | ||
const manifestsForUrl = manifests.filter( | ||
manifest => manifest.url === url, | ||
); | ||
const { jsonRuns, htmlRuns } = await getRuns(manifestsForUrl); | ||
const summary = getAverageSummary(manifestsForUrl, jsonRuns); | ||
return { htmlRuns, summary, url }; | ||
}), | ||
); | ||
|
||
return runs; | ||
}; | ||
|
||
export const createRunDocument = ( | ||
{ url, summary }: SortedRuns, | ||
type: 'mobile' | 'desktop', | ||
): RunDocument => { | ||
const commitHash = github.context.sha; | ||
const author = github.context.actor; | ||
const commitMessage = process.env.COMMIT_MESSAGE || ''; | ||
const commitTimestamp = process.env.COMMIT_TIMESTAMP | ||
? new Date(process.env.COMMIT_TIMESTAMP) | ||
: new Date(); | ||
const project = process.env.PROJECT_TO_BUILD || ''; | ||
const branch = process.env.BRANCH_NAME || ''; | ||
|
||
return { | ||
commitHash, | ||
commitMessage, | ||
commitTimestamp, | ||
author, | ||
project, | ||
branch, | ||
url, | ||
summary, | ||
type, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.