@@ -34,26 +34,13 @@ task('payload', ['material:clean-build'], async () => {
34
34
// Open a connection to Firebase. For PRs the connection will be established as a guest.
35
35
const database = openFirebaseDashboardApp ( ! isTravisMasterBuild ( ) ) ;
36
36
const currentSha = process . env [ 'TRAVIS_PULL_REQUEST_SHA' ] || process . env [ 'TRAVIS_COMMIT' ] ;
37
- const authToken = process . env [ 'FIREBASE_ACCESS_TOKEN' ] ;
38
- const previousPayload = await getLastPayloadResults ( database ) ;
39
37
40
- // Calculate library sizes by combining the CDK and Material FESM 2015 bundles.
41
- const previousSize = previousPayload . cdk_fesm_2015 + previousPayload . material_fesm_2015 ;
42
- const currentSize = results . cdk_fesm_2015 + results . material_fesm_2015 ;
43
- const deltaSize = currentSize - previousSize ;
44
-
45
- // Publish the results to firebase when it runs on Travis but not as a PR.
46
- if ( isTravisMasterBuild ( ) ) {
47
- await database . ref ( 'payloads' ) . child ( currentSha ) . set ( results ) ;
48
- }
49
-
50
- if ( authToken ) {
51
- // Update the Github status of the current commit by sending a request to the dashboard
52
- // firebase http trigger function.
53
- await updateGithubStatus ( currentSha , deltaSize , authToken ) ;
54
- } else {
55
- console . warn ( 'Cannot set the Github status because there is no "FIREBASE_ACCESS_TOKEN" set.' ) ;
56
- }
38
+ // Upload the payload results and calculate the payload diff in parallel. Otherwise the
39
+ // payload task will take much more time inside of Travis builds.
40
+ await Promise . all ( [
41
+ uploadPayloadResults ( database , currentSha , results ) ,
42
+ calculatePayloadDiff ( database , currentSha , results )
43
+ ] ) ;
57
44
58
45
// Disconnect database connection because Firebase otherwise prevents Gulp from exiting.
59
46
database . delete ( ) ;
@@ -71,6 +58,31 @@ function getFilesize(filePath: string) {
71
58
return statSync ( filePath ) . size / 1000 ;
72
59
}
73
60
61
+ /**
62
+ * Calculates the difference between the last and current library payload.
63
+ * The results will be published as a commit status on Github.
64
+ */
65
+ async function calculatePayloadDiff ( database : any , currentSha : string , currentPayload : any ) {
66
+ const authToken = process . env [ 'FIREBASE_ACCESS_TOKEN' ] ;
67
+
68
+ if ( ! authToken ) {
69
+ console . error ( 'Cannot calculate Payload diff because there is no "FIREBASE_ACCESS_TOKEN" ' +
70
+ 'environment variable set.' ) ;
71
+ return ;
72
+ }
73
+
74
+ const previousPayload = await getLastPayloadResults ( database ) ;
75
+
76
+ // Calculate library sizes by combining the CDK and Material FESM 2015 bundles.
77
+ const previousSize = previousPayload . cdk_fesm_2015 + previousPayload . material_fesm_2015 ;
78
+ const currentSize = currentPayload . cdk_fesm_2015 + currentPayload . material_fesm_2015 ;
79
+ const deltaSize = currentSize - previousSize ;
80
+
81
+ // Update the Github status of the current commit by sending a request to the dashboard
82
+ // firebase http trigger function.
83
+ await updateGithubStatus ( currentSha , deltaSize , authToken ) ;
84
+ }
85
+
74
86
/**
75
87
* Updates the Github status of a given commit by sending a request to a Firebase function of
76
88
* the dashboard. The function has access to the Github repository and can set status for PRs too.
@@ -98,6 +110,13 @@ async function updateGithubStatus(commitSha: string, payloadDiff: number, authTo
98
110
} ) ;
99
111
}
100
112
113
+ /** Uploads the current payload results to the Dashboard database. */
114
+ async function uploadPayloadResults ( database : any , currentSha : string , currentPayload : any ) {
115
+ if ( isTravisMasterBuild ( ) ) {
116
+ await database . ref ( 'payloads' ) . child ( currentSha ) . set ( currentPayload ) ;
117
+ }
118
+ }
119
+
101
120
/** Gets the last payload uploaded from previous Travis builds. */
102
121
async function getLastPayloadResults ( database : admin . database . Database ) {
103
122
const snapshot = await database . ref ( 'payloads' )
0 commit comments