@@ -27,6 +27,9 @@ import {
2727} from '@actions/core' ;
2828import { getExecOutput } from '@actions/exec' ;
2929import * as toolCache from '@actions/tool-cache' ;
30+ import { readFile } from 'fs/promises' ;
31+ import { parse as parseYAML } from 'yaml' ;
32+
3033import {
3134 errorMessage ,
3235 isPinnedToHead ,
@@ -146,45 +149,17 @@ export async function run(): Promise<void> {
146149 cmd = [ 'run' , 'services' , 'update-traffic' , service ] ;
147150 if ( revTraffic ) cmd . push ( '--to-revisions' , revTraffic ) ;
148151 if ( tagTraffic ) cmd . push ( '--to-tags' , tagTraffic ) ;
149-
150- const providedButIgnored : Record < string , boolean > = {
151- image : image !== '' ,
152- metadata : metadata !== '' ,
153- source : source !== '' ,
154- env_vars : envVars !== '' ,
155- no_traffic : noTraffic ,
156- secrets : Object . keys ( secrets ) . length > 0 ,
157- suffix : suffix !== '' ,
158- tag : tag !== '' ,
159- labels : Object . keys ( labels ) . length > 0 ,
160- timeout : timeout !== '' ,
161- } ;
162- for ( const key in providedButIgnored ) {
163- if ( providedButIgnored [ key ] ) {
164- logWarning ( `Updating traffic, ignoring "${ key } " input` ) ;
165- }
166- }
167152 } else if ( metadata ) {
168- cmd = [ 'run' , 'services' , 'replace' , metadata ] ;
169-
170- const providedButIgnored : Record < string , boolean > = {
171- image : image !== '' ,
172- service : service !== '' ,
173- source : source !== '' ,
174- env_vars : envVars !== '' ,
175- no_traffic : noTraffic ,
176- secrets : Object . keys ( secrets ) . length > 0 ,
177- suffix : suffix !== '' ,
178- tag : tag !== '' ,
179- revision_traffic : revTraffic !== '' ,
180- tag_traffic : revTraffic !== '' ,
181- labels : Object . keys ( labels ) . length > 0 ,
182- timeout : timeout !== '' ,
183- } ;
184- for ( const key in providedButIgnored ) {
185- if ( providedButIgnored [ key ] ) {
186- logWarning ( `Using metadata YAML, ignoring "${ key } " input` ) ;
187- }
153+ const contents = await readFile ( metadata , 'utf8' ) ;
154+ const parsed = parseYAML ( contents ) ;
155+
156+ const kind = parsed ?. kind ;
157+ if ( kind === 'Service' ) {
158+ cmd = [ 'run' , 'services' , 'replace' , metadata ] ;
159+ } else if ( kind === 'Job' ) {
160+ cmd = [ 'run' , 'jobs' , 'replace' , metadata ] ;
161+ } else {
162+ throw new Error ( `Unkown metadata type "${ kind } ", expected "Job" or "Service"` ) ;
188163 }
189164 } else if ( job ) {
190165 logWarning (
@@ -249,17 +224,14 @@ export async function run(): Promise<void> {
249224
250225 // Push common flags
251226 cmd . push ( '--format' , 'json' ) ;
252- if ( region ) {
253- switch ( region . length ) {
254- case 0 :
255- break ;
256- case 1 :
257- cmd . push ( '--region' , region [ 0 ] ) ;
258- break ;
259- default :
260- cmd . push ( '--region' , region . join ( ',' ) ) ;
261- break ;
262- }
227+ if ( region ?. length > 0 ) {
228+ cmd . push (
229+ '--region' ,
230+ region
231+ . flat ( )
232+ . filter ( ( e ) => e !== undefined && e !== null && e !== '' )
233+ . join ( ',' ) ,
234+ ) ;
263235 }
264236 if ( projectId ) cmd . push ( '--project' , projectId ) ;
265237
0 commit comments