Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeigs committed Jul 17, 2024
1 parent f0256d4 commit 20bb82d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 49 deletions.
4 changes: 2 additions & 2 deletions src/upload-lighthouse/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExtendedSummary, Summary } from "./types";
import { ExtendedSummary, Summary } from './types';

export const DB_NAME = `lighthouse`;
/* Used on PR creation and update (synchronize) */
Expand All @@ -20,4 +20,4 @@ export const extendedSummaryProperties: (keyof ExtendedSummary)[] = [
'speed-index',
'cumulative-layout-shift',
'interactive',
];
];
16 changes: 11 additions & 5 deletions src/upload-lighthouse/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import * as github from '@actions/github';
import { readFileAsync } from ".";
import { extendedSummaryProperties, summaryProperties } from "./constants";
import { ExtendedSummary, JsonRun, Manifest, RunDocument, SortedRuns } from "./types";
import { readFileAsync } from '.';
import { extendedSummaryProperties, summaryProperties } from './constants';
import {
ExtendedSummary,
JsonRun,
Manifest,
RunDocument,
SortedRuns,
} from './types';

const getEmptySummary = (): ExtendedSummary => ({
seo: 0,
Expand Down Expand Up @@ -74,7 +80,7 @@ export const sortAndAverageRuns = async (

return runs;
};

export const createRunDocument = (
{ url, summary }: SortedRuns,
type: 'mobile' | 'desktop',
Expand All @@ -99,4 +105,4 @@ export const createRunDocument = (
summary,
type,
};
};
};
4 changes: 2 additions & 2 deletions src/upload-lighthouse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { MongoClient } from 'mongodb';

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

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

main();
2 changes: 1 addition & 1 deletion src/upload-lighthouse/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ export interface SortedRuns {
htmlRuns: string[];
summary: ExtendedSummary;
url: string;
}
}
44 changes: 44 additions & 0 deletions src/upload-lighthouse/upload-to-s3.ts
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);
}
39 changes: 0 additions & 39 deletions src/upload-lighthouse/uploadToS3.ts

This file was deleted.

0 comments on commit 20bb82d

Please sign in to comment.