@@ -11,7 +11,7 @@ import { Messages } from '@salesforce/core';
1111import { RequestStatus , ComponentStatus } from '@salesforce/source-deploy-retrieve' ;
1212
1313import { SourceTracking , throwIfInvalid , replaceRenamedCommands } from '@salesforce/source-tracking' ;
14- import { DeployCommand } from '../../../../deployCommand' ;
14+ import { DeployCommand , getVersionMessage } from '../../../../deployCommand' ;
1515import { PushResponse , PushResultFormatter } from '../../../../formatters/pushResultFormatter' ;
1616import { ProgressFormatter } from '../../../../formatters/progressFormatter' ;
1717import { DeployProgressBarFormatter } from '../../../../formatters/deployProgressBarFormatter' ;
@@ -51,11 +51,12 @@ export default class Push extends DeployCommand {
5151 protected static requiresProject = true ;
5252 protected readonly lifecycleEventNames = [ 'predeploy' , 'postdeploy' ] ;
5353
54- private isRest = false ;
54+ private tracking : SourceTracking ;
5555
5656 public async run ( ) : Promise < PushResponse [ ] > {
5757 await this . deploy ( ) ;
5858 this . resolveSuccess ( ) ;
59+ await this . updateTrackingFiles ( ) ;
5960 return this . formatResult ( ) ;
6061 }
6162
@@ -66,19 +67,20 @@ export default class Push extends DeployCommand {
6667 toValidate : 'plugin-source' ,
6768 command : replaceRenamedCommands ( 'force:source:push' ) ,
6869 } ) ;
69- const waitDuration = this . getFlag < Duration > ( 'wait' ) ;
70- this . isRest = await this . isRestDeploy ( ) ;
7170
72- const tracking = await SourceTracking . create ( {
71+ this . tracking = await SourceTracking . create ( {
7372 org : this . org ,
7473 project : this . project ,
7574 apiVersion : this . flags . apiversion as string ,
7675 } ) ;
7776 if ( ! this . flags . forceoverwrite ) {
78- processConflicts ( await tracking . getConflicts ( ) , this . ux , messages . getMessage ( 'conflictMsg' ) ) ;
77+ processConflicts ( await this . tracking . getConflicts ( ) , this . ux , messages . getMessage ( 'conflictMsg' ) ) ;
78+ }
79+ const componentSet = await this . tracking . localChangesAsComponentSet ( ) ;
80+ const sourceApiVersion = await this . getSourceApiVersion ( ) ;
81+ if ( sourceApiVersion ) {
82+ componentSet . sourceApiVersion = sourceApiVersion ;
7983 }
80- const componentSet = await tracking . localChangesAsComponentSet ( ) ;
81- componentSet . sourceApiVersion = await this . getSourceApiVersion ( ) ;
8284
8385 // there might have been components in local tracking, but they might be ignored by SDR or unresolvable.
8486 // SDR will throw when you try to resolve them, so don't
@@ -89,13 +91,15 @@ export default class Push extends DeployCommand {
8991
9092 // fire predeploy event for sync and async deploys
9193 await this . lifecycle . emit ( 'predeploy' , componentSet . toArray ( ) ) ;
92- this . ux . log ( `*** Pushing with ${ this . isRest ? 'REST' : 'SOAP' } API v${ componentSet . sourceApiVersion } ***` ) ;
94+
95+ const isRest = await this . isRestDeploy ( ) ;
96+ this . ux . log ( getVersionMessage ( 'Pushing' , componentSet , isRest ) ) ;
9397
9498 const deploy = await componentSet . deploy ( {
9599 usernameOrConnection : this . org . getUsername ( ) ,
96100 apiOptions : {
97101 ignoreWarnings : this . getFlag < boolean > ( 'ignorewarnings' , false ) ,
98- rest : this . isRest ,
102+ rest : isRest ,
99103 testLevel : 'NoTestRun' ,
100104 } ,
101105 } ) ;
@@ -107,32 +111,52 @@ export default class Push extends DeployCommand {
107111 : new DeployProgressStatusFormatter ( this . logger , this . ux ) ;
108112 progressFormatter . progress ( deploy ) ;
109113 }
110- this . deployResult = await deploy . pollStatus ( 500 , waitDuration . seconds ) ;
114+ this . deployResult = await deploy . pollStatus ( 500 , this . getFlag < Duration > ( 'wait' ) . seconds ) ;
115+
116+ if ( this . deployResult ) {
117+ // Only fire the postdeploy event when we have results. I.e., not async.
118+ await this . lifecycle . emit ( 'postdeploy' , this . deployResult ) ;
119+ }
120+ }
111121
122+ protected async updateTrackingFiles ( ) : Promise < void > {
123+ if ( process . exitCode !== 0 || ! this . deployResult ) {
124+ return ;
125+ }
112126 const successes = this . deployResult
113127 . getFileResponses ( )
114128 . filter ( ( fileResponse ) => fileResponse . state !== ComponentStatus . Failed ) ;
115129 const successNonDeletes = successes . filter ( ( fileResponse ) => fileResponse . state !== ComponentStatus . Deleted ) ;
116130 const successDeletes = successes . filter ( ( fileResponse ) => fileResponse . state === ComponentStatus . Deleted ) ;
117131
118- if ( this . deployResult ) {
119- // Only fire the postdeploy event when we have results. I.e., not async.
120- await this . lifecycle . emit ( 'postdeploy' , this . deployResult ) ;
121- }
122-
123132 await Promise . all ( [
124- tracking . updateLocalTracking ( {
133+ this . tracking . updateLocalTracking ( {
125134 files : successNonDeletes . map ( ( fileResponse ) => fileResponse . filePath ) ,
126135 deletedFiles : successDeletes . map ( ( fileResponse ) => fileResponse . filePath ) ,
127136 } ) ,
128- tracking . updateRemoteTracking ( successes ) ,
137+ this . tracking . updateRemoteTracking ( successes ) ,
129138 ] ) ;
130139 }
131140
132141 protected resolveSuccess ( ) : void {
142+ const StatusCodeMap = new Map < RequestStatus , number > ( [
143+ [ RequestStatus . Succeeded , 0 ] ,
144+ [ RequestStatus . Canceled , 1 ] ,
145+ [ RequestStatus . Failed , 1 ] ,
146+ [ RequestStatus . InProgress , 69 ] ,
147+ [ RequestStatus . Pending , 69 ] ,
148+ [ RequestStatus . Canceling , 69 ] ,
149+ ] ) ;
133150 // there might not be a deployResult if we exited early with an empty componentSet
134- if ( this . deployResult && this . deployResult . response . status !== RequestStatus . Succeeded ) {
135- this . setExitCode ( 1 ) ;
151+ if ( this . deployResult && this . deployResult . response . status ) {
152+ this . setExitCode ( StatusCodeMap . get ( this . deployResult . response . status ) ?? 1 ) ;
153+ // special override case for "only warnings about deleted things that are already deleted"
154+ if (
155+ this . deployResult . response . status === RequestStatus . Failed &&
156+ this . deployResult . getFileResponses ( ) . every ( ( fr ) => fr . state !== 'Failed' )
157+ ) {
158+ this . setExitCode ( 0 ) ;
159+ }
136160 }
137161 }
138162
0 commit comments