Skip to content

Commit

Permalink
feat(screenshot): Update screenshot golds for merged PR (#3365)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinayuangao authored and kara committed Mar 1, 2017
1 parent 8aa9857 commit 1491291
Showing 1 changed file with 12 additions and 6 deletions.
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

0 comments on commit 1491291

Please sign in to comment.