Skip to content

Commit 20bb82d

Browse files
committed
lint
1 parent f0256d4 commit 20bb82d

File tree

6 files changed

+60
-49
lines changed

6 files changed

+60
-49
lines changed

src/upload-lighthouse/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ExtendedSummary, Summary } from "./types";
1+
import { ExtendedSummary, Summary } from './types';
22

33
export const DB_NAME = `lighthouse`;
44
/* Used on PR creation and update (synchronize) */
@@ -20,4 +20,4 @@ export const extendedSummaryProperties: (keyof ExtendedSummary)[] = [
2020
'speed-index',
2121
'cumulative-layout-shift',
2222
'interactive',
23-
];
23+
];

src/upload-lighthouse/helpers.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import * as github from '@actions/github';
2-
import { readFileAsync } from ".";
3-
import { extendedSummaryProperties, summaryProperties } from "./constants";
4-
import { ExtendedSummary, JsonRun, Manifest, RunDocument, SortedRuns } from "./types";
2+
import { readFileAsync } from '.';
3+
import { extendedSummaryProperties, summaryProperties } from './constants';
4+
import {
5+
ExtendedSummary,
6+
JsonRun,
7+
Manifest,
8+
RunDocument,
9+
SortedRuns,
10+
} from './types';
511

612
const getEmptySummary = (): ExtendedSummary => ({
713
seo: 0,
@@ -74,7 +80,7 @@ export const sortAndAverageRuns = async (
7480

7581
return runs;
7682
};
77-
83+
7884
export const createRunDocument = (
7985
{ url, summary }: SortedRuns,
8086
type: 'mobile' | 'desktop',
@@ -99,4 +105,4 @@ export const createRunDocument = (
99105
summary,
100106
type,
101107
};
102-
};
108+
};

src/upload-lighthouse/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { MongoClient } from 'mongodb';
1414

1515
import { Manifest } from './types';
1616
import { DB_NAME, MAIN_COLL_NAME, PR_COLL_NAME } from './constants';
17-
import { uploadHtmlToS3 } from './uploadToS3';
17+
import { uploadHtmlToS3 } from './upload-to-s3';
1818
import { createRunDocument, sortAndAverageRuns } from './helpers';
1919

2020
export const readFileAsync = promisify(fs.readFile);
@@ -81,6 +81,6 @@ async function main(): Promise<void> {
8181
console.log('Error occurred when reading file', error);
8282
throw error;
8383
}
84-
};
84+
}
8585

8686
main();

src/upload-lighthouse/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ export interface SortedRuns {
5555
htmlRuns: string[];
5656
summary: ExtendedSummary;
5757
url: string;
58-
}
58+
}

src/upload-lighthouse/upload-to-s3.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as github from '@actions/github';
2+
import {
3+
ObjectCannedACL,
4+
PutObjectCommand,
5+
PutObjectCommandOutput,
6+
S3Client,
7+
} from '@aws-sdk/client-s3';
8+
import { SortedRuns } from './types';
9+
10+
// Html reports will be uploaded to S3
11+
export async function uploadHtmlToS3(
12+
{ htmlRuns, url }: SortedRuns,
13+
type: 'mobile' | 'desktop',
14+
): Promise<PutObjectCommandOutput[]> {
15+
const AWS_BUCKET = 'docs-lighthouse';
16+
const commitHash = github.context.sha;
17+
const branch = process.env.BRANCH_NAME || '';
18+
const client = new S3Client();
19+
20+
const reportType = branch === 'main' ? 'main_reports' : 'pr_reports';
21+
22+
let cleanedUrl = url.replace('http://localhost:9000/', '');
23+
if (cleanedUrl.endsWith('?desktop')) cleanedUrl = cleanedUrl.slice(0, -8);
24+
cleanedUrl = cleanedUrl.split(/\/\/|\//).join('-');
25+
26+
const destinationDir = `${reportType}/${commitHash}/${cleanedUrl}/${type}`;
27+
28+
const uploads = htmlRuns.map(async (htmlReport, i) => {
29+
const key = `${destinationDir}/${i + 1}.html`;
30+
console.log('Uploading to S3 at ', key);
31+
32+
const input = {
33+
Body: Buffer.from(htmlReport),
34+
Key: key,
35+
Bucket: AWS_BUCKET,
36+
ContentType: 'text/html',
37+
CacheControl: 'no-cache',
38+
ACL: ObjectCannedACL.public_read,
39+
};
40+
const command = new PutObjectCommand(input);
41+
return client.send(command);
42+
});
43+
return Promise.all(uploads);
44+
}

src/upload-lighthouse/uploadToS3.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)