-
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.
- Loading branch information
Showing
6 changed files
with
60 additions
and
49 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
|
@@ -55,4 +55,4 @@ export interface SortedRuns { | |
htmlRuns: string[]; | ||
summary: ExtendedSummary; | ||
url: string; | ||
} | ||
} |
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,44 @@ | ||
import * as github from '@actions/github'; | ||
import { | ||
ObjectCannedACL, | ||
PutObjectCommand, | ||
PutObjectCommandOutput, | ||
S3Client, | ||
} from '@aws-sdk/client-s3'; | ||
import { SortedRuns } from './types'; | ||
|
||
// Html reports will be uploaded to S3 | ||
export async function uploadHtmlToS3( | ||
{ htmlRuns, url }: SortedRuns, | ||
type: 'mobile' | 'desktop', | ||
): Promise<PutObjectCommandOutput[]> { | ||
const AWS_BUCKET = 'docs-lighthouse'; | ||
const commitHash = github.context.sha; | ||
const branch = process.env.BRANCH_NAME || ''; | ||
const client = new S3Client(); | ||
|
||
const reportType = branch === 'main' ? 'main_reports' : 'pr_reports'; | ||
|
||
let cleanedUrl = url.replace('http://localhost:9000/', ''); | ||
if (cleanedUrl.endsWith('?desktop')) cleanedUrl = cleanedUrl.slice(0, -8); | ||
cleanedUrl = cleanedUrl.split(/\/\/|\//).join('-'); | ||
|
||
const destinationDir = `${reportType}/${commitHash}/${cleanedUrl}/${type}`; | ||
|
||
const uploads = htmlRuns.map(async (htmlReport, i) => { | ||
const key = `${destinationDir}/${i + 1}.html`; | ||
console.log('Uploading to S3 at ', key); | ||
|
||
const input = { | ||
Body: Buffer.from(htmlReport), | ||
Key: key, | ||
Bucket: AWS_BUCKET, | ||
ContentType: 'text/html', | ||
CacheControl: 'no-cache', | ||
ACL: ObjectCannedACL.public_read, | ||
}; | ||
const command = new PutObjectCommand(input); | ||
return client.send(command); | ||
}); | ||
return Promise.all(uploads); | ||
} |
This file was deleted.
Oops, something went wrong.