11const core = require ( '@actions/core' ) ;
22const tencentcloud = require ( "tencentcloud-sdk-nodejs" ) ;
33
4+ // Read raw inputs
5+ const secretId = core . getInput ( 'secret_id' ) ;
6+ const secretKey = core . getInput ( 'secret_key' ) ;
7+ const action = core . getInput ( 'action' ) ;
8+ const pathsRaw = core . getInput ( 'paths' ) ;
9+
10+ // Parse `paths` format into cdn paths and eo entries (zone -> paths)
11+ // Format: multi-line text, tokens separated by whitespace. Lines starting with `zone-` are treated as EO entries.
12+ function parsePurePaths ( text ) {
13+ const cdn = [ ] ;
14+ const eoMap = { } ; // zoneId -> Set(paths)
15+
16+ if ( ! text ) return { cdn, eoMap } ;
17+
18+ const lines = text . split ( / \r ? \n / ) ;
19+ for ( const line of lines ) {
20+ const t = line . trim ( ) ;
21+ if ( ! t ) continue ;
22+ // split by whitespace
23+ const tokens = t . split ( / \s + / ) . filter ( Boolean ) ;
24+ if ( tokens . length === 0 ) continue ;
25+
26+ if ( tokens [ 0 ] . startsWith ( 'zone-' ) ) {
27+ const zoneId = tokens [ 0 ] ;
28+ const paths = tokens . slice ( 1 ) ;
29+ if ( ! eoMap [ zoneId ] ) eoMap [ zoneId ] = new Set ( ) ;
30+ for ( const p of paths ) eoMap [ zoneId ] . add ( p ) ;
31+ } else {
32+ for ( const p of tokens ) cdn . push ( p ) ;
33+ }
34+ }
35+
36+ // convert sets to arrays
37+ for ( const k of Object . keys ( eoMap ) ) {
38+ eoMap [ k ] = Array . from ( eoMap [ k ] ) ;
39+ }
40+
41+ return { cdn, eoMap } ;
42+ }
43+
44+ const parsed = parsePurePaths ( pathsRaw ) ;
45+
46+ // Build CDN paths (deduplicated) and EO entries from `paths` only
47+ const cdnPaths = Array . from ( new Set ( parsed . cdn ) ) ;
48+ const eoEntries = Object . keys ( parsed . eoMap ) . map ( zoneId => ( { zoneId, paths : parsed . eoMap [ zoneId ] . slice ( ) } ) ) ;
49+
450const input = {
5- secretId : core . getInput ( 'secret_id' ) ,
6- secretKey : core . getInput ( 'secret_key' ) ,
7- action : core . getInput ( 'action' ) ,
8- cdnPaths : JSON . parse ( core . getInput ( 'cdn-paths' ) ) ,
9- eoZoneId : core . getInput ( 'eo-zoneid' ) ,
10- eoPaths : JSON . parse ( core . getInput ( 'eo-paths' ) ) ,
51+ secretId,
52+ secretKey,
53+ action,
54+ cdnPaths,
55+ eoEntries, // array of { zoneId, paths }
1156} ;
1257
1358async function initialcdn ( ) {
@@ -32,8 +77,6 @@ async function initialeo() {
3277 core . startGroup ( "🔧 Initializing EdgeOne client" ) ;
3378
3479 core . info ( `Action type: ${ input . action } ` ) ;
35- core . info ( `EdgeOne Zone ID: ${ input . eoZoneId } ` ) ;
36- core . info ( `Target EdgeOne paths: ${ JSON . stringify ( input . eoPaths ) } ` ) ;
3780 const eoClient = tencentcloud . teo . v20220901 . Client ;
3881 const client = new eoClient ( {
3982 credential : { secretId : input . secretId , secretKey : input . secretKey } ,
@@ -47,7 +90,7 @@ async function initialeo() {
4790 return client ;
4891}
4992
50- async function executeCdnOperation ( client ) {
93+ async function executeCdnOperation ( client , paths ) {
5194 core . startGroup ( "🚀 Executing CDN operation" ) ;
5295
5396 let params = { } ;
@@ -56,15 +99,15 @@ async function executeCdnOperation(client) {
5699 if ( input . action === 'purgePath' ) {
57100 core . info ( "Selected operation: PurgePathCache (Directory refresh)" ) ;
58101 fn = client . PurgePathCache . bind ( client ) ;
59- params = { Paths : input . cdnPaths , FlushType : "flush" } ;
102+ params = { Paths : paths , FlushType : "flush" } ;
60103 } else if ( input . action === 'purgeUrls' ) {
61104 core . info ( "Selected operation: PurgeUrlsCache (URL refresh)" ) ;
62105 fn = client . PurgeUrlsCache . bind ( client ) ;
63- params = { Urls : input . cdnPaths } ;
106+ params = { Urls : paths } ;
64107 } else if ( input . action === 'pushUrls' ) {
65108 core . info ( "Selected operation: PushUrlsCache (URL prefetch)" ) ;
66109 fn = client . PushUrlsCache . bind ( client ) ;
67- params = { Urls : input . cdnPaths } ;
110+ params = { Urls : paths } ;
68111 } else {
69112 throw new Error ( `Unknown action type: ${ input . action } ` ) ;
70113 }
@@ -85,7 +128,7 @@ async function executeCdnOperation(client) {
85128 core . setOutput ( "response" , result ) ;
86129}
87130
88- async function executeEoOperation ( client ) {
131+ async function executeEoOperation ( client , zoneId , paths ) {
89132 core . startGroup ( "🚀 Executing EdgeOne operation" ) ;
90133
91134 let params = { } ;
@@ -94,15 +137,15 @@ async function executeEoOperation(client) {
94137 if ( input . action === 'purgePath' ) {
95138 core . info ( "Selected operation: PurgeUrls (Directory refresh)" ) ;
96139 fn = client . CreatePurgeTask . bind ( client ) ;
97- params = { ZoneId : input . eoZoneId , Type : "purge_prefix" , Targets : input . eoPaths } ;
140+ params = { ZoneId : zoneId , Type : "purge_prefix" , Targets : paths } ;
98141 } else if ( input . action === 'purgeUrls' ) {
99142 core . info ( "Selected operation: PurgeUrls (URL refresh)" ) ;
100143 fn = client . CreatePurgeTask . bind ( client ) ;
101- params = { ZoneId : input . eoZoneId , Type : "purge_url" , Targets : input . eoPaths } ;
144+ params = { ZoneId : zoneId , Type : "purge_url" , Targets : paths } ;
102145 } else if ( input . action === 'pushUrls' ) {
103146 core . info ( "Selected operation: PurgeUrls (URL prefetch)" ) ;
104147 fn = client . CreatePrefetchTask . bind ( client ) ;
105- params = { ZoneId : input . eoZoneId , Targets : input . eoPaths } ;
148+ params = { ZoneId : zoneId , Targets : paths } ;
106149 } else {
107150 throw new Error ( `EdgeOne does not support action type: ${ input . action } , skipping EdgeOne operation.` ) ;
108151 }
@@ -125,13 +168,31 @@ async function executeEoOperation(client) {
125168
126169async function main ( ) {
127170 try {
128- if ( input . cdnPaths ) {
129- const cdn = await initialcdn ( )
130- await executeCdnOperation ( cdn ) ;
171+ // Validate that we have at least one target (CDN path or EO entry)
172+ const hasCdn = Array . isArray ( input . cdnPaths ) && input . cdnPaths . length > 0 ;
173+ const hasEo = Array . isArray ( input . eoEntries ) && input . eoEntries . length > 0 ;
174+ if ( ! hasCdn && ! hasEo ) {
175+ const example = `paths: |\n https://example.com/ https://www.example.com/\n zone-XXXX https://example.com/ https://eo.example.com/` ;
176+ const msg = `No target paths found. Provide targets via the required \`paths\` input (breaking change). Example:\n\n${ example } ` ;
177+ core . error ( msg ) ;
178+ core . setFailed ( 'No target paths provided' ) ;
179+ throw new Error ( 'No target paths provided' ) ;
131180 }
132- if ( input . eoPaths && input . eoZoneId ) {
133- const eo = await initialeo ( )
134- await executeEoOperation ( eo ) ;
181+
182+ // CDN operations (if any cdn paths were provided)
183+ if ( hasCdn ) {
184+ const cdn = await initialcdn ( ) ;
185+ await executeCdnOperation ( cdn , input . cdnPaths ) ;
186+ }
187+
188+ // EdgeOne operations: support multiple zone entries from `paths`
189+ if ( hasEo ) {
190+ const eoClient = await initialeo ( ) ;
191+ for ( const entry of input . eoEntries ) {
192+ if ( ! entry . zoneId || ! Array . isArray ( entry . paths ) || entry . paths . length === 0 ) continue ;
193+ core . info ( `Processing EdgeOne zone: ${ entry . zoneId } with ${ entry . paths . length } targets` ) ;
194+ await executeEoOperation ( eoClient , entry . zoneId , entry . paths ) ;
195+ }
135196 }
136197 } catch ( error ) {
137198 core . error ( "Execution failed ❌" ) ;
0 commit comments