Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions action/dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -61495,22 +61495,23 @@ async function checkS3PrefixExists(bucketName, prefix) {
}
}
async function downloadS3Directory(bucketName, s3Prefix, localDir) {
info(`Downloading screenshots from s3://${bucketName}/${s3Prefix}`);
info(`Downloading base images from s3://${bucketName}/${s3Prefix}`);
const command = new ListObjectsV2Command({
Bucket: bucketName,
Prefix: s3Prefix
});
const response = await s3Client.send(command);
const objects = response.Contents ?? [];
info(`Found ${objects.length} file(s) to download`);
await (0, import_bluebird.map)(objects, async (object) => {
if (!object.Key) return;
const relativePath = object.Key.substring(s3Prefix.length);
const allObjects = response.Contents ?? [];
const baseObjects = allObjects.filter((obj2) => obj2.Key?.endsWith("base.png"));
info(`Found ${baseObjects.length} base image(s) to download`);
await (0, import_bluebird.map)(baseObjects, async ({ Key }) => {
if (!Key) return;
const relativePath = Key.substring(s3Prefix.length);
const localFilePath = path5.join(localDir, relativePath);
await import_fs5.promises.mkdir(path5.dirname(localFilePath), { recursive: true });
const getCommand = new GetObjectCommand({
Bucket: bucketName,
Key: object.Key
Key
});
const { Body } = await s3Client.send(getCommand);
if (Body instanceof import_stream10.Readable) {
Expand All @@ -61520,10 +61521,10 @@ async function downloadS3Directory(bucketName, s3Prefix, localDir) {
});
}
});
info(`Downloaded ${objects.length} file(s) to ${localDir}`);
info(`Downloaded ${baseObjects.length} base image(s) to ${localDir}`);
}
async function uploadLocalDirectory(localDir, bucketName, s3Prefix) {
const files = await glob("**/*.png", {
const files = await glob("**/{base,diff,new}.png", {
cwd: localDir,
nodir: true,
absolute: false
Expand Down Expand Up @@ -65577,9 +65578,12 @@ var run = async () => {
).length;
const screenshotsDirectory = getInput("screenshots-directory");
const screenshotsPath = path6.join(process.cwd(), screenshotsDirectory);
const filesInScreenshotDirectory = await glob(`${screenshotsPath}/**/*.png`, {
absolute: false
});
const filesInScreenshotDirectory = await glob(
`${screenshotsPath}/**/{base,diff,new}.png`,
{
absolute: false
}
);
const diffFilePaths = filesInScreenshotDirectory.filter(
(file) => file.endsWith("diff.png")
);
Expand Down
2 changes: 1 addition & 1 deletion action/dist/main.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion action/dist/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -30784,7 +30784,9 @@ var post = async () => {
info("Cleaning up PNG files in screenshots directory...");
const screenshotsDirectory = getInput("screenshots-directory");
try {
const pngFiles = await glob(`${screenshotsDirectory}/**/*.png`);
const pngFiles = await glob(
`${screenshotsDirectory}/**/{base,diff,new}.png`
);
await (0, import_bluebird.map)(pngFiles, (file) => (0, import_promises2.rm)(file, { force: true }));
info(`Removed ${pngFiles.length} PNG file(s) from ${screenshotsDirectory}`);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion action/dist/post.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion action/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const post = async () => {
const screenshotsDirectory = getInput('screenshots-directory');

try {
const pngFiles = await glob(`${screenshotsDirectory}/**/*.png`);
const pngFiles = await glob(
`${screenshotsDirectory}/**/{base,diff,new}.png`
);
await map(pngFiles, file => rm(file, { force: true }));

info(`Removed ${pngFiles.length} PNG file(s) from ${screenshotsDirectory}`);
Expand Down
9 changes: 6 additions & 3 deletions action/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ export const run = async () => {

const screenshotsDirectory = getInput('screenshots-directory');
const screenshotsPath = path.join(process.cwd(), screenshotsDirectory);
const filesInScreenshotDirectory = await glob(`${screenshotsPath}/**/*.png`, {
absolute: false
});
const filesInScreenshotDirectory = await glob(
`${screenshotsPath}/**/{base,diff,new}.png`,
{
absolute: false
}
);
const diffFilePaths = filesInScreenshotDirectory.filter(file =>
file.endsWith('diff.png')
);
Expand Down
19 changes: 10 additions & 9 deletions action/src/s3-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,30 @@ async function downloadS3Directory(
s3Prefix: string,
localDir: string
): Promise<void> {
info(`Downloading screenshots from s3://${bucketName}/${s3Prefix}`);
info(`Downloading base images from s3://${bucketName}/${s3Prefix}`);

const command = new ListObjectsV2Command({
Bucket: bucketName,
Prefix: s3Prefix
});

const response = await s3Client.send(command);
const objects = response.Contents ?? [];
const allObjects = response.Contents ?? [];
const baseObjects = allObjects.filter(obj => obj.Key?.endsWith('base.png'));

info(`Found ${objects.length} file(s) to download`);
info(`Found ${baseObjects.length} base image(s) to download`);

await map(objects, async object => {
if (!object.Key) return;
await map(baseObjects, async ({ Key }) => {
if (!Key) return;

const relativePath = object.Key.substring(s3Prefix.length);
const relativePath = Key.substring(s3Prefix.length);
const localFilePath = path.join(localDir, relativePath);

await fsPromises.mkdir(path.dirname(localFilePath), { recursive: true });

const getCommand = new GetObjectCommand({
Bucket: bucketName,
Key: object.Key
Key
});

const { Body } = await s3Client.send(getCommand);
Expand All @@ -76,15 +77,15 @@ async function downloadS3Directory(
}
});

info(`Downloaded ${objects.length} file(s) to ${localDir}`);
info(`Downloaded ${baseObjects.length} base image(s) to ${localDir}`);
}

async function uploadLocalDirectory(
localDir: string,
bucketName: string,
s3Prefix: string
): Promise<void> {
const files = await glob('**/*.png', {
const files = await glob('**/{base,diff,new}.png', {
cwd: localDir,
nodir: true,
absolute: false
Expand Down
29 changes: 15 additions & 14 deletions app/backend/src/fetchCurrentPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ export const fetchCurrentPage = async ({
});
}
const { keys, title } = currentPage;
const images = (
await Promise.all(
keys.map(async key => {
const result = fileNameSchema.safeParse(parse(key).name);
if (!result.success) {
return;
}
const images = await Promise.all(
keys.map(async key => {
const result = fileNameSchema.safeParse(parse(key).name);
if (!result.success) {
throw new TRPCError({
code: 'BAD_REQUEST',
message: `Invalid file name: ${key}. ${result.error.message}`
});
}

return {
name: result.data,
url: await getTemporaryObjectUrl(key, bucket)
};
})
)
).filter(Boolean);
return {
name: result.data,
url: await getTemporaryObjectUrl(key, bucket)
};
})
);
const nextPage = page < paginatedKeys.length ? page + 1 : undefined;
return {
title,
Expand Down
18 changes: 15 additions & 3 deletions app/backend/test/fetchCurrentPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const listObjectsV2Mock = mock(() => ({
{ Key: `${pathPrefix}/SMALL/srpPage/base.png` },
{ Key: `${pathPrefix}/SMALL/srpPage/diff.png` },
{ Key: `${pathPrefix}/SMALL/srpPage/new.png` },
{ Key: `${pathPrefix}/EXTRA_LARGE/pdpPage/new.png }` }
{ Key: `${pathPrefix}/EXTRA_LARGE/pdpPage/new.png }` },
{ Key: `${pathPrefix}/LARGE/invalidPage/invalid.png` },
{ Key: `${pathPrefix}/LARGE/invalidPage/new.png` }
]
}));
mock.module('../src/s3Client', () => ({
Expand Down Expand Up @@ -61,7 +63,7 @@ describe('fetchCurrentPage', () => {
url: 'url'
}
],
nextPage: undefined
nextPage: 3
});
});

Expand All @@ -72,6 +74,16 @@ describe('fetchCurrentPage', () => {
bucket: 'bucket',
page: 12
})
).rejects.toThrow('Page 12 does not exist. Only 2 pages were found.');
).rejects.toThrow('Page 12 does not exist. Only 3 pages were found.');
});

it('should throw when a key does not conform to fileNameSchema', async () => {
expect(
fetchCurrentPage({
hash: 'hash',
bucket: 'bucket',
page: 3
})
).rejects.toThrow('Invalid file name');
});
});
Loading