forked from xixu-me/xget
-
Notifications
You must be signed in to change notification settings - Fork 0
376 lines (336 loc) · 14.8 KB
/
Copy pathsync.yml
File metadata and controls
376 lines (336 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
name: Sync to Page
on:
push:
branches:
- main
paths-ignore:
- '**.md'
- 'LICENSE'
- '.gitignore'
- '.editorconfig'
- '.vscode/**'
- 'docs/**'
- '.prettierrc*'
- '.eslintrc*'
- '.github/ISSUE_TEMPLATE/**'
- '.github/PULL_REQUEST_TEMPLATE/**'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
convert-and-sync:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: write
steps:
- name: Checkout main branch
uses: actions/checkout@v5
with:
ref: main
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create temporary working directory
run: |
mkdir -p /tmp/page-conversion
cd /tmp/page-conversion
- name: Copy source code files only
run: |
# Copy only runtime-required files (no documentation, tests, or dev configs)
cp -r src /tmp/page-conversion/
cp package.json /tmp/page-conversion/
cp package-lock.json /tmp/page-conversion/ 2>/dev/null || true
cp wrangler.toml /tmp/page-conversion/
cp LICENSE /tmp/page-conversion/
- name: Create Pages Function handler
run: |
mkdir -p /tmp/page-conversion/functions
cat > /tmp/page-conversion/functions/[[path]].js << 'EOF'
/**
* Xget - High-performance acceleration engine for developer resources
* Copyright (C) 2025 Xi Xu
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { handleRequest } from '../src/index.js';
/**
* Cloudflare Pages Function handler for all routes.
*
* This catch-all route handler processes all incoming requests to the Xget
* acceleration engine. It delegates request processing to the main handleRequest
* function from the Worker code, maintaining full compatibility with the
* existing implementation.
*
* The [[path]] syntax in the filename creates a catch-all route that matches
* any path, allowing this single function to handle all requests to the Pages
* application.
*
* @param {Object} context - Cloudflare Pages Function context
* @param {Request} context.request - The incoming HTTP request
* @param {Object} context.env - Environment variables and bindings (KV, secrets, etc.)
* @param {Object} context.params - Route parameters (path segments from [[path]])
* @param {Function} context.waitUntil - Extend function execution for background tasks
* @param {Function} context.next - Call next middleware in chain (not used here)
* @param {Object} context.data - Shared data between functions
* @returns {Promise<Response>} The HTTP response to return to the client
*
* @example
* // This is called automatically by Cloudflare Pages
* // User requests: https://xget.pages.dev/npm/lodash
* // Runtime invokes: onRequest(context)
* // Returns: Response with package data
*
* @example
* // Environment variables usage
* // wrangler.toml: [vars] TIMEOUT_SECONDS = "60"
* // context.env contains: { TIMEOUT_SECONDS: "60" }
* // handleRequest uses createConfig(env) to override defaults
*/
export async function onRequest(context) {
// Extract request, env, and create an execution context compatible with Workers
const { request, env, waitUntil } = context;
// Create a minimal ExecutionContext-like object for compatibility
const ctx = {
waitUntil: waitUntil,
passThroughOnException: () => {
// Pages doesn't support passThroughOnException, so this is a no-op
console.warn('passThroughOnException is not supported in Pages Functions');
}
};
// Delegate to the main request handler
return handleRequest(request, env, ctx);
}
EOF
- name: Export handleRequest from src/index.js
run: |
cd /tmp/page-conversion
# Add export statement before the default export at the end of the file
sed -i '/^export default {$/i\
export { handleRequest };' src/index.js
- name: Update wrangler.toml for Pages (remove observability)
run: |
cd /tmp/page-conversion
# Remove observability section (Pages doesn't support it)
cat > wrangler.toml << 'EOF'
#:schema node_modules/wrangler/config-schema.json
name = "xget"
pages_build_output_dir = "."
compatibility_date = "2024-10-22"
compatibility_flags = ["nodejs_compat"]
EOF
- name: Update package.json for Pages
run: |
cd /tmp/page-conversion
# Update deployment commands to use Pages
cat package.json | \
sed 's/"deploy": "wrangler deploy"/"deploy": "wrangler pages deploy ."/' | \
sed 's/"start": "wrangler dev"/"start": "wrangler pages dev ."/' \
> package.json.tmp && mv package.json.tmp package.json
- name: Initialize page branch
run: |
cd /tmp/page-conversion
git init
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b page
git add .
git commit -m "Convert Worker to Page
Auto-converted from main branch commit ${{ github.sha }}
Changes:
- Add functions/[[path]].js: Catch-all Pages Function handler
- Update src/index.js: Export handleRequest for Pages Function import
- Update wrangler.toml: Configure for Pages deployment (no observability)
- Update package.json: Change scripts to use Pages commands
Runtime files only (documentation, tests, and dev configs excluded)."
- name: Force push to page branch
run: |
cd /tmp/page-conversion
git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
git push -f origin page
- name: Clean up
if: always()
run: |
rm -rf /tmp/page-conversion
convert-to-edgeone:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: write
steps:
- name: Checkout main branch
uses: actions/checkout@v5
with:
ref: main
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create temporary working directory
run: |
mkdir -p /tmp/edgeone-conversion
cd /tmp/edgeone-conversion
- name: Copy source code files only
run: |
# Copy only runtime-required files (no documentation, tests, or dev configs)
cp -r src /tmp/edgeone-conversion/
cp package.json /tmp/edgeone-conversion/
cp package-lock.json /tmp/edgeone-conversion/ 2>/dev/null || true
cp LICENSE /tmp/edgeone-conversion/
- name: Create EdgeOne Pages Function handler
run: |
mkdir -p /tmp/edgeone-conversion/functions
cat > /tmp/edgeone-conversion/functions/[[path]].js << 'EOF'
/**
* Xget - High-performance acceleration engine for developer resources
* Copyright (C) 2025 Xi Xu
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { handleRequest } from '../src/index.js';
/**
* EdgeOne Pages Function handler for all routes.
*
* This catch-all route handler processes all incoming requests to the Xget
* acceleration engine. It delegates request processing to the main handleRequest
* function from the Worker code, maintaining full compatibility with the
* existing implementation.
*
* The [[path]] syntax in the filename creates a catch-all route that matches
* any path, allowing this single function to handle all requests to the Pages
* application.
*
* EdgeOne Pages Functions are compatible with Cloudflare Pages Functions,
* using the same onRequest() handler signature and context object structure.
*
* @param {Object} context - EdgeOne Pages Function context
* @param {Request} context.request - The incoming HTTP request
* @param {Object} context.env - Environment variables and bindings (KV, secrets, etc.)
* @param {Object} context.params - Route parameters (path segments from [[path]])
* @param {Function} context.waitUntil - Extend function execution for background tasks
* @param {Function} context.next - Call next middleware in chain (not used here)
* @param {Object} context.data - Shared data between functions
* @returns {Promise<Response>} The HTTP response to return to the client
*
* @example
* // This is called automatically by EdgeOne Pages
* // User requests: https://xget.pages.edgeone.app/npm/lodash
* // Runtime invokes: onRequest(context)
* // Returns: Response with package data
*
* @example
* // Environment variables usage
* // edgeone.json or Console: TIMEOUT_SECONDS = "60"
* // context.env contains: { TIMEOUT_SECONDS: "60" }
* // handleRequest uses createConfig(env) to override defaults
*/
export async function onRequest(context) {
// Extract request, env, and create an execution context compatible with Workers
const { request, env, waitUntil } = context;
// Create a minimal ExecutionContext-like object for compatibility
const ctx = {
waitUntil: waitUntil,
passThroughOnException: () => {
// Pages doesn't support passThroughOnException, so this is a no-op
console.warn('passThroughOnException is not supported in EdgeOne Pages Functions');
}
};
// Delegate to the main request handler
return handleRequest(request, env, ctx);
}
EOF
- name: Export handleRequest from src/index.js
run: |
cd /tmp/edgeone-conversion
# Add export statement before the default export at the end of the file
sed -i '/^export default {$/i\
export { handleRequest };' src/index.js
- name: Create edgeone.json configuration
run: |
cd /tmp/edgeone-conversion
cat > edgeone.json << 'EOF'
{
"buildCommand": "",
"installCommand": "npm install",
"outputDirectory": ".",
"nodeVersion": "22.11.0",
"headers": [
{
"source": "/*",
"headers": [
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-Frame-Options",
"value": "DENY"
},
{
"key": "Referrer-Policy",
"value": "no-referrer"
}
]
}
]
}
EOF
- name: Update package.json for EdgeOne Pages
run: |
cd /tmp/edgeone-conversion
# Update deployment commands for EdgeOne Pages
cat package.json | \
sed 's/\"deploy\": \"wrangler deploy\"/\"deploy\": \"echo \\\"Deploy via EdgeOne Pages Console\\\"\"/' | \
sed 's/\"start\": \"wrangler dev\"/\"start\": \"echo \\\"Use EdgeOne Pages local development\\\"\"/' \
> package.json.tmp && mv package.json.tmp package.json
- name: Initialize pages branch
run: |
cd /tmp/edgeone-conversion
git init
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b pages
git add .
git commit -m "Convert Worker to EdgeOne Pages
Auto-converted from main branch commit ${{ github.sha }}
Changes:
- Add functions/[[path]].js: Catch-all EdgeOne Pages Function handler
- Update src/index.js: Export handleRequest for Pages Function import
- Add edgeone.json: Configure for EdgeOne Pages deployment
- Update package.json: Note deployment via EdgeOne Console
Runtime files only (documentation, tests, and dev configs excluded)."
- name: Force push to pages branch
run: |
cd /tmp/edgeone-conversion
git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
git push -f origin pages
- name: Clean up
if: always()
run: |
rm -rf /tmp/edgeone-conversion