Skip to content

chore: remove outdated golden screenshots #7628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
15 changes: 13 additions & 2 deletions tools/gulp/tasks/screenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,26 @@ function compareScreenshotFile(fileName: string, database: Database, prNumber: s
}

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

return Promise.all(getLocalScreenshotFiles(SCREENSHOT_DIR).map(fileName => {
// Only delete golden images that are outdated to avoid collisions with other screenshot diffs.
// Deleting every golden screenshot may also work, but will likely cause flakiness if multiple
// screenshot tasks run.
const deleteOutdatedGoldenFiles = Promise.all(storageGoldenFiles
.filter((file: any) => !localScreenshots.includes(path.basename(file.name)))
.map((file: any) => file.delete()));

const uploadNewGoldenImages = Promise.all(localScreenshots.map(fileName => {
const filePath = path.join(SCREENSHOT_DIR, fileName);
const storageDestination = `${FIREBASE_STORAGE_GOLDENS}/${fileName}`;

return bucket.upload(filePath, { destination: storageDestination });
}));

await Promise.all([deleteOutdatedGoldenFiles, uploadNewGoldenImages]);
}

/**
Expand Down