File tree Expand file tree Collapse file tree 3 files changed +71
-5
lines changed Expand file tree Collapse file tree 3 files changed +71
-5
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,41 @@ describe('Parse Tags', () => {
3737 const json = parseTags ( JSON . stringify ( [ { Key : 'Test' , Value : 'Value' } ] ) )
3838 expect ( json ) . toEqual ( [ { Key : 'Test' , Value : 'Value' } ] )
3939 } )
40+
41+ test ( 'returns valid Array from YAML key-value object format' , async ( ) => {
42+ const yaml = `
43+ Key1: Value1
44+ Key2: Value2
45+ `
46+ const result = parseTags ( yaml )
47+ expect ( result ) . toEqual ( [
48+ { Key : 'Key1' , Value : 'Value1' } ,
49+ { Key : 'Key2' , Value : 'Value2' }
50+ ] )
51+ } )
52+
53+ test ( 'returns valid Array from YAML array format' , async ( ) => {
54+ const yaml = `
55+ - Key: keyname1
56+ Value: value1
57+ - Key: keyname2
58+ Value: value2
59+ `
60+ const result = parseTags ( yaml )
61+ expect ( result ) . toEqual ( [
62+ { Key : 'keyname1' , Value : 'value1' } ,
63+ { Key : 'keyname2' , Value : 'value2' }
64+ ] )
65+ } )
66+
67+ test ( 'returns undefined for invalid YAML' , async ( ) => {
68+ const invalidYaml = `
69+ Key1: 'Value1
70+ Key2: Value2
71+ `
72+ const result = parseTags ( invalidYaml )
73+ expect ( result ) . toBeUndefined ( )
74+ } )
4075} )
4176
4277describe ( 'Parse Parameters' , ( ) => {
Original file line number Diff line number Diff line change 3636 "@actions/core" : " ^1.10.0" ,
3737 "@aws-sdk/client-cloudformation" : " ^3.474.0" ,
3838 "@smithy/node-http-handler" : " 3.0.0" ,
39- "https-proxy-agent" : " ^5.0.1"
39+ "https-proxy-agent" : " ^5.0.1" ,
40+ "js-yaml" : " ^4.1.0"
4041 },
4142 "devDependencies" : {
4243 "@types/jest" : " ^29.2.3" ,
Original file line number Diff line number Diff line change @@ -16,13 +16,43 @@ export function isUrl(s: string): boolean {
1616}
1717
1818export function parseTags ( s : string ) : Tag [ ] | undefined {
19- let json
19+ if ( ! s || s . trim ( ) === '' ) {
20+ return undefined ;
21+ }
22+
23+ let tags ;
24+
25+ // Try to parse as JSON first (backward compatibility)
26+ try {
27+ tags = JSON . parse ( s ) ;
28+ return tags ;
29+ } catch ( _ ) {
30+ // JSON parsing failed, try to parse as YAML
31+ }
2032
33+ // If JSON parsing fails, try to handle as YAML
2134 try {
22- json = JSON . parse ( s )
23- } catch ( _ ) { }
35+ const yaml = require ( 'js-yaml' ) ;
36+ const parsed = yaml . load ( s ) ;
37+
38+ if ( ! parsed ) {
39+ return undefined ;
40+ }
41+
42+ // Handle the two YAML structure formats
43+ if ( Array . isArray ( parsed ) ) {
44+ // Already in the format [{Key: 'key', Value: 'value'}, ...]
45+ return parsed ;
46+ } else if ( typeof parsed === 'object' ) {
47+ // Convert from {Key1: 'Value1', Key2: 'Value2'} format
48+ return Object . entries ( parsed ) . map ( ( [ Key , Value ] ) => ( { Key, Value } ) ) ;
49+ }
50+ } catch ( _ ) {
51+ // YAML parsing failed
52+ return undefined ;
53+ }
2454
25- return json
55+ return undefined ;
2656}
2757
2858export function parseARNs ( s : string ) : string [ ] | undefined {
You can’t perform that action at this time.
0 commit comments