Skip to content

Commit 2d72ac9

Browse files
devversionandrewseguin
authored andcommitted
chore: remove outdated golden screenshots (#7628)
* chore: remove outdated golden screenshots Currently if a screenshot test changed its name, the old golden reference image won't be deleted. This causes the screenshot diff task to compare against nothing (screenshot diffs now always fail). With this change, outdated screenshot images will be deleted in master builds. * Address feedback
1 parent 0d00374 commit 2d72ac9

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

tools/gulp/tasks/screenshots.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,26 @@ function compareScreenshotFile(fileName: string, database: Database, prNumber: s
188188
}
189189

190190
/** Uploads golden screenshots to the Google Cloud Storage bucket for the screenshots. */
191-
function uploadGoldenScreenshots() {
191+
async function uploadGoldenScreenshots() {
192192
const bucket = openScreenshotsBucket();
193+
const localScreenshots = getLocalScreenshotFiles(SCREENSHOT_DIR);
194+
const storageGoldenFiles = (await bucket.getFiles({prefix: FIREBASE_STORAGE_GOLDENS}))[0];
193195

194-
return Promise.all(getLocalScreenshotFiles(SCREENSHOT_DIR).map(fileName => {
196+
// Only delete golden images that are outdated to avoid collisions with other screenshot diffs.
197+
// Deleting every golden screenshot may also work, but will likely cause flakiness if multiple
198+
// screenshot tasks run.
199+
const deleteOutdatedGoldenFiles = Promise.all(storageGoldenFiles
200+
.filter((file: any) => !localScreenshots.includes(path.basename(file.name)))
201+
.map((file: any) => file.delete()));
202+
203+
const uploadNewGoldenImages = Promise.all(localScreenshots.map(fileName => {
195204
const filePath = path.join(SCREENSHOT_DIR, fileName);
196205
const storageDestination = `${FIREBASE_STORAGE_GOLDENS}/${fileName}`;
197206

198207
return bucket.upload(filePath, { destination: storageDestination });
199208
}));
209+
210+
await Promise.all([deleteOutdatedGoldenFiles, uploadNewGoldenImages]);
200211
}
201212

202213
/**

0 commit comments

Comments
 (0)