@@ -96,7 +96,7 @@ export async function run(): Promise<void> {
96
96
const noTraffic = ( getInput ( 'no_traffic' ) || '' ) . toLowerCase ( ) === 'true' ;
97
97
const revTraffic = getInput ( 'revision_traffic' ) ;
98
98
const tagTraffic = getInput ( 'tag_traffic' ) ;
99
- const labels = Object . assign ( { } , defaultLabels ( ) , parseKVString ( getInput ( 'labels' ) ) ) ;
99
+ const labels = parseKVString ( getInput ( 'labels' ) ) ;
100
100
const flags = getInput ( 'flags' ) ;
101
101
102
102
let responseType = ResponseTypes . DEPLOY ; // Default response type for output parsing
@@ -124,34 +124,51 @@ export async function run(): Promise<void> {
124
124
responseType = ResponseTypes . UPDATE_TRAFFIC ;
125
125
126
126
// Update traffic
127
- cmd = [
128
- 'run' ,
129
- 'services' ,
130
- 'update-traffic' ,
131
- service ,
132
- '--platform' ,
133
- 'managed' ,
134
- '--region' ,
135
- region ,
136
- ] ;
127
+ cmd = [ 'run' , 'services' , 'update-traffic' , service ] ;
137
128
if ( revTraffic ) cmd . push ( '--to-revisions' , revTraffic ) ;
138
129
if ( tagTraffic ) cmd . push ( '--to-tags' , tagTraffic ) ;
139
130
140
- if ( image || envVars ?. length || secrets ?. length || timeout || labels ?. length ) {
141
- logWarning (
142
- `Updating traffic, ignoring inputs "image", "env_vars", "secrets", "timeout", and "labels"` ,
143
- ) ;
131
+ const providedButIgnored : Record < string , boolean > = {
132
+ image : image !== '' ,
133
+ metadata : metadata !== '' ,
134
+ source : source !== '' ,
135
+ env_vars : Object . keys ( envVars ) . length > 0 ,
136
+ no_traffic : noTraffic ,
137
+ secrets : Object . keys ( secrets ) . length > 0 ,
138
+ suffix : suffix !== '' ,
139
+ tag : tag !== '' ,
140
+ labels : Object . keys ( labels ) . length > 0 ,
141
+ timeout : timeout !== '' ,
142
+ } ;
143
+ for ( const key in providedButIgnored ) {
144
+ if ( providedButIgnored [ key ] ) {
145
+ logWarning ( `Updating traffic, ignoring "${ key } " input` ) ;
146
+ }
144
147
}
145
148
} else if ( metadata ) {
146
- cmd = [ 'run' , 'services' , 'replace' , metadata , '--platform' , 'managed' , '--region' , region ] ;
147
-
148
- if ( image || service || envVars ?. length || secrets ?. length || timeout || labels ?. length ) {
149
- logWarning (
150
- `Using metadata YAML, ignoring inputs "image", "name", "env_vars", "secrets", "timeout", and "labels"` ,
151
- ) ;
149
+ cmd = [ 'run' , 'services' , 'replace' , metadata ] ;
150
+
151
+ const providedButIgnored : Record < string , boolean > = {
152
+ image : image !== '' ,
153
+ service : service !== '' ,
154
+ source : source !== '' ,
155
+ env_vars : Object . keys ( envVars ) . length > 0 ,
156
+ no_traffic : noTraffic ,
157
+ secrets : Object . keys ( secrets ) . length > 0 ,
158
+ suffix : suffix !== '' ,
159
+ tag : tag !== '' ,
160
+ revision_traffic : revTraffic !== '' ,
161
+ tag_traffic : revTraffic !== '' ,
162
+ labels : Object . keys ( labels ) . length > 0 ,
163
+ timeout : timeout !== '' ,
164
+ } ;
165
+ for ( const key in providedButIgnored ) {
166
+ if ( providedButIgnored [ key ] ) {
167
+ logWarning ( `Using metadata YAML, ignoring "${ key } " input` ) ;
168
+ }
152
169
}
153
170
} else {
154
- cmd = [ 'run' , 'deploy' , service , '--quiet' , '--platform' , 'managed' , '--region' , region ] ;
171
+ cmd = [ 'run' , 'deploy' , service , '--quiet' ] ;
155
172
156
173
if ( image ) {
157
174
// Deploy service with image specified
@@ -173,12 +190,19 @@ export async function run(): Promise<void> {
173
190
}
174
191
if ( suffix ) cmd . push ( '--revision-suffix' , suffix ) ;
175
192
if ( noTraffic ) cmd . push ( '--no-traffic' ) ;
176
- if ( labels && Object . keys ( labels ) . length > 0 ) {
177
- cmd . push ( '--update-labels' , kvToString ( labels ) ) ;
178
- }
179
193
if ( timeout ) cmd . push ( '--timeout' , timeout ) ;
194
+
195
+ // Compile the labels
196
+ const compiledLabels = Object . assign ( { } , defaultLabels ( ) , labels ) ;
197
+ cmd . push ( '--update-labels' , kvToString ( compiledLabels ) ) ;
180
198
}
181
199
200
+ // Push common flags
201
+ cmd . push ( '--platform' , 'managed' ) ;
202
+ cmd . push ( '--format' , 'json' ) ;
203
+ if ( region ) cmd . push ( '--region' , region ) ;
204
+ if ( projectId ) cmd . push ( '--project' , projectId ) ;
205
+
182
206
// Add optional flags
183
207
if ( flags ) {
184
208
const flagList = parseFlags ( flags ) ;
@@ -193,6 +217,12 @@ export async function run(): Promise<void> {
193
217
addPath ( path . join ( toolPath , 'bin' ) ) ;
194
218
}
195
219
220
+ // Install gcloud component if needed and prepend the command
221
+ if ( gcloudComponent ) {
222
+ await installGcloudComponent ( gcloudComponent ) ;
223
+ cmd . unshift ( gcloudComponent ) ;
224
+ }
225
+
196
226
// Authenticate - this comes from google-github-actions/auth.
197
227
const credFile = process . env . GOOGLE_GHA_CREDS_PATH ;
198
228
if ( credFile ) {
@@ -202,18 +232,6 @@ export async function run(): Promise<void> {
202
232
logWarning ( 'No authentication found, authenticate with `google-github-actions/auth`.' ) ;
203
233
}
204
234
205
- // set PROJECT ID
206
- if ( projectId ) cmd . push ( '--project' , projectId ) ;
207
-
208
- // Install gcloud component if needed and prepend the command
209
- if ( gcloudComponent ) {
210
- await installGcloudComponent ( gcloudComponent ) ;
211
- cmd . unshift ( gcloudComponent ) ;
212
- }
213
-
214
- // Set output format to json
215
- cmd . push ( '--format' , 'json' ) ;
216
-
217
235
const toolCommand = getToolCommand ( ) ;
218
236
const options = { silent : true , ignoreReturnCode : true } ;
219
237
const commandString = `${ toolCommand } ${ cmd . join ( ' ' ) } ` ;
0 commit comments