@@ -21,20 +21,25 @@ import { getGitLocalBranchName, getGitRemoteBranch } from '../../common/git';
21
21
import {
22
22
addAddons ,
23
23
addAppToPipeline ,
24
+ addBuildPack ,
24
25
addDrain ,
25
26
addMember ,
26
27
addWebhook ,
28
+ clearBuildPacks ,
27
29
createApp ,
28
30
createAppRemote ,
29
31
createPipeline ,
30
32
getPipelineName ,
33
+ hasPlugin ,
31
34
HerokuError ,
35
+ installPlugin ,
32
36
mergeConfigVars ,
33
37
pipelineExists ,
38
+ serializeConfigVars ,
34
39
} from '../../common/heroku' ;
35
40
import { HerokuBaseService } from '../../common/heroku/base.service' ;
36
41
import { Logger , LoggerInterface } from '../../common/logger' ;
37
- import { exec , sleep } from '../../common/utils' ;
42
+ import { exec , isExecException , sleep } from '../../common/utils' ;
38
43
import { DeployExecutorSchema , ExtendedDeployExecutorSchema } from '../schema' ;
39
44
import { DEPLOY_EXECUTOR_SCHEMA } from './tokens' ;
40
45
@@ -113,7 +118,7 @@ class HerokuApp {
113
118
} catch ( error ) {
114
119
const ex = error as ExecException ;
115
120
// there is (probably) nothing to commit
116
- this . logger . warn ( ex . message ) ;
121
+ this . logger . warn ( ex . message . trim ( ) ) ;
117
122
this . logger . warn ( ex . code ?. toString ( ) ) ;
118
123
}
119
124
}
@@ -151,25 +156,18 @@ class HerokuApp {
151
156
}
152
157
}
153
158
154
- private async hasPlugin ( plugin : string ) : Promise < boolean > {
155
- const { stdout : list } = await exec ( 'heroku plugins' , { encoding : 'utf8' } ) ;
156
- return list . includes ( plugin ) ;
157
- }
158
-
159
159
private async addBuildPacks ( ) : Promise < void > {
160
160
const { appName, buildPacks } = this . options ;
161
161
if ( buildPacks ?. length ) {
162
- if ( ! this . hasPlugin ( 'buildpack-registry' ) ) {
163
- await exec ( 'heroku plugins:install buildpack-registry') ;
162
+ if ( ! ( await hasPlugin ( 'buildpack-registry' ) ) ) {
163
+ await installPlugin ( ' buildpack-registry') ;
164
164
}
165
- await exec ( `heroku buildpacks:clear --app ${ appName } ` ) ;
166
- const promises = buildPacks . map ( ( buildPack , i ) => {
167
- const index = i + 1 ;
168
- return exec (
169
- `heroku buildpacks:add ${ buildPack } --app ${ appName } --index ${ index } `
170
- ) ;
171
- } ) ;
172
- await Promise . all ( promises ) ;
165
+ this . logger . info ( `Clearing and adding buildpacks...` ) ;
166
+ await clearBuildPacks ( { appName } ) ;
167
+ for ( const [ i , buildPack ] of buildPacks . entries ( ) ) {
168
+ await addBuildPack ( { appName, buildPack, index : i + 1 } ) ;
169
+ }
170
+ this . logger . info ( `Buildpacks ${ buildPacks } added.` ) ;
173
171
}
174
172
}
175
173
@@ -192,15 +190,23 @@ class HerokuApp {
192
190
org,
193
191
remoteName,
194
192
} ) ;
195
- this . logger . info ( `Created app ${ appName } on git remote ${ remoteName } ` ) ;
193
+ this . logger . info ( `Created app ${ appName } on git remote ${ remoteName } . ` ) ;
196
194
return true ;
197
195
}
198
196
throw error ;
199
197
}
200
- this . logger . info ( `Added git remote ${ remoteName } ` ) ;
198
+ this . logger . info ( `Added git remote ${ remoteName } . ` ) ;
201
199
return false ;
202
200
}
203
201
202
+ private async mergeConfigVars ( ) : Promise < void > {
203
+ const updatedConfigVars = await mergeConfigVars ( this . options ) ;
204
+ if ( updatedConfigVars ) {
205
+ this . logger . info (
206
+ `Merged config vars : ${ serializeConfigVars ( updatedConfigVars ) } .`
207
+ ) ;
208
+ }
209
+ }
204
210
private async addToPipeline ( ) : Promise < void > {
205
211
const {
206
212
appName,
@@ -220,7 +226,7 @@ class HerokuApp {
220
226
} ) ;
221
227
} else {
222
228
this . logger . warn (
223
- `Pipeline ${ pipelineName } not found, it will be created at the next step`
229
+ `Pipeline ${ pipelineName } not found, it will be created at the next step. `
224
230
) ;
225
231
await createPipeline ( { appName, environment, org, pipelineName } ) ;
226
232
if ( repositoryName ) {
@@ -230,8 +236,8 @@ class HerokuApp {
230
236
}
231
237
}
232
238
} catch ( error ) {
233
- if ( error . status !== 2 ) {
234
- this . logger . warn ( error . message ) ;
239
+ if ( isExecException ( error ) && error . code !== 2 ) {
240
+ this . logger . warn ( error . message . trim ( ) ) ;
235
241
}
236
242
}
237
243
}
@@ -292,8 +298,8 @@ class HerokuApp {
292
298
remoteBranch : string | undefined
293
299
) : Promise < boolean > {
294
300
this . logger . info ( `Reset repo ${ remoteBranch } ` ) ;
295
- if ( ! ( await this . hasPlugin ( 'heroku-repo' ) ) ) {
296
- await exec ( 'heroku plugins:install heroku-repo') ;
301
+ if ( ! ( await hasPlugin ( 'heroku-repo' ) ) ) {
302
+ await installPlugin ( ' heroku-repo') ;
297
303
}
298
304
await exec ( `heroku repo:reset -a ${ appName } ` ) ;
299
305
return true ;
@@ -316,9 +322,11 @@ class HerokuApp {
316
322
}
317
323
318
324
const push = spawn ( 'git' , args , { signal } ) ;
325
+ //? if data contains `Everything up-to-date`, should we still restart the app
319
326
push . stdout
320
327
. setEncoding ( 'utf-8' )
321
328
. on ( 'data' , ( data ) => this . logger . info ( data ) ) ;
329
+
322
330
push . stderr
323
331
. setEncoding ( 'utf-8' )
324
332
. on ( 'data' , ( data ) => this . logger . info ( data ) ) ;
@@ -432,7 +440,7 @@ class HerokuApp {
432
440
await this . createStatic ( ) ;
433
441
await this . createAptfile ( ) ;
434
442
await this . addRemote ( ) ;
435
- await mergeConfigVars ( this . options ) ;
443
+ await this . mergeConfigVars ( ) ;
436
444
await this . addBuildPacks ( ) ;
437
445
// TODO: add warning if stack update is available https://devcenter.heroku.com/articles/upgrading-to-the-latest-stack
438
446
await this . addToPipeline ( ) ;
0 commit comments