Skip to content

Commit 6585eea

Browse files
committed
feat: simplized input
1 parent 1a39ee4 commit 6585eea

4 files changed

Lines changed: 140 additions & 55 deletions

File tree

README.md

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@ Supports **refreshing directories**, **refreshing URLs**, and **preheating URLs*
55

66
---
77

8+
## ⚠️ Migration (breaking change)
9+
10+
This action no longer accepts the previous JSON-style inputs (`cdn-paths`, `eo-paths`, `eo-zoneid`).
11+
You must now provide targets using the multiline `paths` input. Each line contains one or more tokens separated by whitespace. Lines starting with a Zone ID (`zone-...`) are treated as EdgeOne zone entries; other tokens are treated as CDN paths.
12+
13+
Example migration:
14+
15+
Old (JSON inputs):
16+
17+
```yaml
18+
with:
19+
cdn-paths: '["https://example.com/"]'
20+
eo-zoneid: 'zone-XXXX'
21+
eo-paths: '["https://example.com/"]'
22+
```
23+
24+
New (`paths`):
25+
26+
```yaml
27+
with:
28+
paths: |
29+
https://example.com/
30+
zone-XXXX https://example.com/
31+
```
32+
33+
The new `paths` format is simpler and supports multiple EO zones in the same input.
34+
35+
---
36+
837
## ✨ Features
938

1039
* ✅ **PurgePathCache**: Refresh directory cache (e.g. `https://example.com/`)
@@ -48,15 +77,15 @@ jobs:
4877
4978
# ... Your build & deploy steps
5079
51-
- name: Refresh CDN cache
52-
uses: linrongda/tencent-cdn-action@v1.5
80+
- name: Refresh CDN / EdgeOne cache
81+
uses: linrongda/tencent-cdn-action@v2
5382
with:
5483
secret_id: ${{ secrets.TENCENT_SECRET_ID }}
5584
secret_key: ${{ secrets.TENCENT_SECRET_KEY }}
5685
action: purgePath
57-
cdn-paths: '["https://example.com/"]'
58-
# eo-zoneid: ${{ secrets.EDGEONE_ZONE_ID }}
59-
# eo-paths: '["https://example.com/"]'
86+
paths: |
87+
https://example.com/ https://www.example.com/
88+
zone-XXXX https://example.com/ https://eo.example.com/
6089
```
6190

6291
---
@@ -67,51 +96,49 @@ jobs:
6796
| ------------ | -------- | ----------- | ------------------------------------------------------ |
6897
| `secret_id` | ✅ | — | Tencent Cloud API SecretId |
6998
| `secret_key` | ✅ | — | Tencent Cloud API SecretKey |
70-
| `action` || `purgePath` | Operation type: `purgePath` / `purgeUrls` / `pushUrls` |
71-
| `cdn-paths` ||| JSON array string of URLs or directories |
72-
| `eo-zoneid` ||| EdgeOne ZoneId |
73-
| `eo-paths` ||| JSON array string of URLs or directories |
99+
| `action` | ✅ | `purgePath` | Operation type: `purgePath` / `purgeUrls` / `pushUrls` |
100+
| `paths` | ✅ | — | Multiline plain text. Each line tokens separated by spaces. Lines starting with `zone-...` are treated as EdgeOne zone entries. |
74101
---
75102

76103
### 4. Examples
77104

78105
#### Refresh whole directory
79106

80107
```yaml
81-
- uses: linrongda/tencent-cdn-action@v1
108+
- uses: linrongda/tencent-cdn-action@v2
82109
with:
83110
secret_id: ${{ secrets.TENCENT_SECRET_ID }}
84111
secret_key: ${{ secrets.TENCENT_SECRET_KEY }}
85112
action: purgePath
86-
cdn-paths: '["https://example.com/"]'
87-
# eo-zoneid: ${{ secrets.EDGEONE_ZONE_ID }}
88-
# eo-paths: '["https://example.com/"]'
113+
paths: |
114+
https://example.com/ https://www.example.com/
115+
zone-XXXX https://example.com/ https://eo.example.com/
89116
```
90117

91118
#### Refresh specific URLs
92119

93120
```yaml
94-
- uses: linrongda/tencent-cdn-action@v1
121+
- uses: linrongda/tencent-cdn-action@v2
95122
with:
96123
secret_id: ${{ secrets.TENCENT_SECRET_ID }}
97124
secret_key: ${{ secrets.TENCENT_SECRET_KEY }}
98125
action: purgeUrls
99-
cdn-paths: '["https://example.com/index.html","https://example.com/style.css"]'
100-
# eo-zoneid: ${{ secrets.EDGEONE_ZONE_ID }}
101-
# eo-paths: '["https://example.com/index.html","https://example.com/style.css"]'
126+
paths: |
127+
https://example.com/index.html
128+
zone-XXXX https://example.com/style.css
102129
```
103130

104131
#### Preheat URLs
105132

106133
```yaml
107-
- uses: linrongda/tencent-cdn-action@v1
134+
- uses: linrongda/tencent-cdn-action@v2
108135
with:
109136
secret_id: ${{ secrets.TENCENT_SECRET_ID }}
110137
secret_key: ${{ secrets.TENCENT_SECRET_KEY }}
111138
action: pushUrls
112-
cdn-paths: '["https://example.com/index.html"]'
113-
# eo-zoneid: ${{ secrets.EDGEONE_ZONE_ID }}
114-
# eo-paths: '["https://example.com/index.html"]'
139+
paths: |
140+
https://example.com/index.html
141+
zone-XXXX https://example.com/style.css
115142
```
116143

117144
---

action.yml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@ inputs:
1313
description: 'Tencent Cloud SecretKey'
1414
required: true
1515
action:
16-
description: 'CDN action type: purgePath | purgeUrls | pushUrls'
17-
required: false
16+
description: 'Action type: purgePath | purgeUrls | pushUrls'
17+
required: true
1818
default: 'purgePath'
19-
cdn-paths:
20-
description: 'List of URLs or directories to operate on (JSON array string)'
21-
required: false
22-
eo-zoneid:
23-
description: 'EdgeOne Zone ID (required for purgeUrls and pushUrls)'
24-
required: false
25-
eo-paths:
26-
description: 'List of URLs to operate on EdgeOne (JSON array string, required for purgeUrls and pushUrls)'
27-
required: false
19+
paths:
20+
description: |
21+
Each line contains paths separated by spaces.
22+
If a line begins with a Zone ID (starts with `zone-`) the remainder of that line are EdgeOne targets for that zone.
23+
Otherwise tokens are treated as CDN paths.
24+
required: true
2825

2926
runs:
3027
using: 'node20'

index.js

Lines changed: 83 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,58 @@
11
const core = require('@actions/core');
22
const 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+
450
const 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

1358
async 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

126169
async 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 ❌");

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tencent-cdn-action",
3-
"version": "1.5.0",
3+
"version": "2.0.0",
44
"description": "GitHub Action for Tencent Cloud CDN and EdgeOne operations",
55
"main": "index.js",
66
"dependencies": {

0 commit comments

Comments
 (0)