Skip to content
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
18 changes: 12 additions & 6 deletions tools/gulp/tasks/screenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ task('screenshots', () => {
.then((files: any[]) => downloadAllGoldsAndCompare(files, database, prNumber))
.then((results: boolean) => updateResult(database, prNumber, results))
.then((result: boolean) => updateGithubStatus(result, prNumber))
.then(() => uploadScreenshots(prNumber, 'diff'))
.then(() => uploadScreenshots(prNumber, 'test'))
.then(() => uploadScreenshots('diff', prNumber))
.then(() => uploadScreenshots('test', prNumber))
.then(() => updateTravis(database, prNumber))
.then(() => setScreenFilenames(database, prNumber))
.then(() => database.goOffline(), () => database.goOffline());
} else if (process.env['TRAVIS']) {
// Only update golds and filenames for build
let database = openFirebaseScreenshotsDatabase();
uploadScreenshots('gold')
.then(() => setScreenFilenames(database))
.then(() => database.goOffline(), () => database.goOffline());
}
});

Expand Down Expand Up @@ -70,19 +76,19 @@ function getLocalScreenshotFiles(dir: string): string[] {
* Upload screenshots to google cloud storage.
* @param prNumber - The key used in firebase. Here it is the PR number.
* If there's no prNumber, we will upload images to 'golds/' folder
* @param mode - Can be 'test' or 'diff' or null.
* @param mode - Can be 'test' or 'diff' or 'gold'.
* If the images are the test results, mode should be 'test'.
* If the images are the diff images generated, mode should be 'diff'.
* For golds mode should be null.
* For golds mode should be 'gold'.
*/
function uploadScreenshots(prNumber?: string, mode?: 'test' | 'diff') {
function uploadScreenshots(mode?: 'test' | 'diff' | 'gold', prNumber?: string) {
let bucket = openScreenshotsBucket();

let promises: any[] = [];
let localDir = mode == 'diff' ? path.join(SCREENSHOT_DIR, 'diff') : SCREENSHOT_DIR;
getLocalScreenshotFiles(localDir).forEach((file: string) => {
let fileName = path.join(localDir, file);
let destination = (mode == null || !prNumber) ?
let destination = (mode == 'gold' || !prNumber) ?
`golds/${file}` : `screenshots/${prNumber}/${mode}/${file}`;
promises.push(bucket.upload(fileName, { destination: destination }));
});
Expand Down