-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_project.py
More file actions
718 lines (546 loc) · 17.5 KB
/
update_project.py
File metadata and controls
718 lines (546 loc) · 17.5 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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
#!/usr/bin/env python3
"""
更新 serverless-devs Python 包项目
修复问题:
1. 修复 badge URLs
2. CI 中真正测试 s 命令安装
3. 提供中英文文档
4. 更新 Python 版本策略
"""
import os
from pathlib import Path
def create_file(filepath, content):
"""创建文件并写入内容"""
filepath = Path(filepath)
filepath.parent.mkdir(parents=True, exist_ok=True)
with open(filepath, 'w', encoding='utf-8') as f:
f.write(content)
print(f"✓ 更新文件: {filepath}")
def update_project():
"""更新项目文件"""
print("开始更新项目...\n")
# ==================== README.md (英文) ====================
readme_en = '''# Serverless Devs - Python Package
[](https://pypi.org/project/serverless-devs/)
[](https://pypi.org/project/serverless-devs/)
[](https://github.com/Serverless-Devs/Serverless-Devs/blob/master/LICENSE)
[](https://github.com/Serverless-Devs/Serverless-Devs)
[简体中文](./README_zh.md) | English
Install Serverless Devs developer tools via Python pip (automatically installs the latest version).
## Features
- ✅ Automatically installs the latest version of Serverless Devs
- ✅ Automatically handles Node.js environment dependencies
- ✅ Supports Windows, Linux, macOS
- ✅ One-click installation, ready to use
- 🌍 Supports domestic mirror acceleration
## Installation
### Install via pip
```bash
pip install serverless-devs
```
### Use domestic mirror for acceleration
```bash
# China mirror
pip install serverless-devs -i https://pypi.tuna.tsinghua.edu.cn/simple
```
The installation process will automatically:
1. Download and run the official Serverless Devs installation script
2. Detect and install Node.js (if needed)
3. Install the latest version of Serverless Devs
## Usage
After installation, you can use the `s` command directly:
```bash
# Check version
s --version
# View help
s --help
# Configure credentials
s config add
# Initialize project
s init
# Deploy project
s deploy
```
## Manual Installation/Reinstallation
If automatic installation fails or you need to reinstall the latest version:
```bash
s-install
```
Use domestic mirror:
```bash
# Linux/macOS
export USE_MIRROR=1
s-install
# Windows CMD
set USE_MIRROR=1
s-install
# Windows PowerShell
$env:USE_MIRROR=1
s-install
```
## Uninstallation
```bash
pip uninstall serverless-devs
```
> Note: This only uninstalls the Python wrapper, not Serverless Devs itself.
> To completely uninstall, manually delete Serverless Devs:
> - Linux/macOS: `rm -rf ~/.s`
> - Windows: Delete `C:\\Users\\<username>\\.s` directory
## Supported Platforms
- ✅ Windows (x64)
- ✅ Linux (x64)
- ✅ macOS (x64/arm64)
## Requirements
- Python 3.7+
- Internet connection (for downloading installation script)
## How It Works
After installing via pip, this package executes the official Serverless Devs installation script:
```bash
curl -o- -L https://cli.serverless-devs.com/install.sh | bash
```
The script will:
1. Detect system environment
2. Automatically install Node.js (if needed)
3. Install the latest version of Serverless Devs via npm
## Troubleshooting
### Q: Installation failed?
A: Try these solutions:
```bash
# 1. Run installation manually
s-install
# 2. Use domestic mirror
export USE_MIRROR=1 # Linux/macOS
s-install
# 3. Use official installation script directly
curl -o- -L https://cli.serverless-devs.com/install.sh | bash
```
### Q: How to update to the latest version?
A: Rerun the installation command:
```bash
s-install
```
Or use npm:
```bash
npm update -g @serverless-devs/s
```
### Q: How to check the installed version?
A: Run:
```bash
s --version
```
### Q: PowerShell execution policy issue on Windows
A: Run PowerShell as administrator and execute:
```powershell
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
```
## Links
- Official Website: https://www.serverless-devs.com/
- GitHub: https://github.com/Serverless-Devs/Serverless-Devs
- Documentation: https://docs.serverless-devs.com/
- Registry: https://registry.serverless-devs.com/
- DingTalk Group: 33947367
## License
MIT License
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
'''
create_file('README.md', readme_en)
# ==================== README_zh.md (中文) ====================
readme_zh = '''# Serverless Devs - Python 安装包
[](https://pypi.org/project/serverless-devs/)
[](https://pypi.org/project/serverless-devs/)
[](https://github.com/Serverless-Devs/Serverless-Devs/blob/master/LICENSE)
[](https://github.com/Serverless-Devs/Serverless-Devs)
简体中文 | [English](./README.md)
通过 Python pip 安装 Serverless Devs 开发者工具(自动安装最新版本)。
## 特性
- ✅ 自动安装最新版 Serverless Devs
- ✅ 自动处理 Node.js 环境依赖
- ✅ 支持 Windows、Linux、macOS
- ✅ 一键安装,开箱即用
- 🌍 支持国内镜像加速
## 安装
### 使用 pip 安装
```bash
pip install serverless-devs
```
### 使用国内镜像加速
```bash
# 清华镜像
pip install serverless-devs -i https://pypi.tuna.tsinghua.edu.cn/simple
# 阿里云镜像
pip install serverless-devs -i https://mirrors.aliyun.com/pypi/simple/
```
安装过程会自动:
1. 下载并执行 Serverless Devs 官方安装脚本
2. 自动检测并安装 Node.js(如果需要)
3. 安装最新版本的 Serverless Devs
## 使用
安装完成后,可以直接使用 `s` 命令:
```bash
# 查看版本
s --version
# 查看帮助
s --help
# 配置密钥
s config add
# 初始化项目
s init
# 部署项目
s deploy
```
## 手动安装/重新安装
如果自动安装失败,或需要重新安装最新版本:
```bash
s-install
```
使用国内镜像加速:
```bash
# Linux/macOS
export USE_MIRROR=1
s-install
# Windows CMD
set USE_MIRROR=1
s-install
# Windows PowerShell
$env:USE_MIRROR=1
s-install
```
## 卸载
```bash
pip uninstall serverless-devs
```
> 注意:这只会卸载 Python 包装器,不会卸载 Serverless Devs 本身。
> 如需完全卸载,请手动删除 Serverless Devs:
> - Linux/macOS: `rm -rf ~/.s`
> - Windows: 删除 `C:\\Users\\<用户名>\\.s` 目录
## 支持的平台
- ✅ Windows (x64)
- ✅ Linux (x64)
- ✅ macOS (x64/arm64)
## 环境要求
- Python 3.7+
- 互联网连接(用于下载安装脚本)
## 工作原理
本包通过 pip 安装后,会执行 Serverless Devs 官方安装脚本:
```bash
curl -o- -L https://cli.serverless-devs.com/install.sh | bash
```
该脚本会:
1. 检测系统环境
2. 自动安装 Node.js(如果需要)
3. 通过 npm 安装最新版 Serverless Devs
## 常见问题
### Q: 安装失败怎么办?
A: 请尝试以下方法:
```bash
# 1. 手动运行安装
s-install
# 2. 使用国内镜像
export USE_MIRROR=1 # Linux/macOS
s-install
# 3. 直接使用官方安装脚本
curl -o- -L https://cli.serverless-devs.com/install.sh | bash
```
### Q: 如何更新到最新版本?
A: 重新运行安装命令:
```bash
s-install
```
或使用 npm:
```bash
npm update -g @serverless-devs/s
```
### Q: 如何查看安装的版本?
A: 运行:
```bash
s --version
```
### Q: Windows 下 PowerShell 执行策略问题
A: 以管理员身份运行 PowerShell 并执行:
```powershell
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
```
### Q: 国内网络环境安装慢或失败
A: 使用国内镜像:
```bash
# 方法1: 使用环境变量
export USE_MIRROR=1
s-install
# 方法2: 使用 npm 镜像
npm config set registry https://registry.npmmirror.com
npm install -g @serverless-devs/s
```
## 相关链接
- 官方网站: https://www.serverless-devs.com/
- GitHub: https://github.com/Serverless-Devs/Serverless-Devs
- 文档中心: https://docs.serverless-devs.com/
- 应用中心: https://registry.serverless-devs.com/
- 钉钉交流群: 33947367
## 开源协议
MIT License
## 贡献
欢迎提交 Issue 和 Pull Request!
'''
create_file('README_zh.md', readme_zh)
# ==================== 更新 setup.py ====================
setup_py = '''from setuptools import setup, find_packages
from setuptools.command.install import install
import sys
import os
# 添加当前目录到 Python 路径,以便导入 installer
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
class PostInstallCommand(install):
"""安装后自动安装 Serverless Devs"""
def run(self):
install.run(self)
print("\\n" + "="*60)
print("开始安装 Serverless Devs ...")
print("="*60 + "\\n")
try:
from serverless_devs.installer import install_serverless_devs
success = install_serverless_devs()
if success:
print("\\n" + "="*60)
print("✓ Serverless Devs 安装完成!")
print(" 请运行 's --version' 验证安装")
print("="*60 + "\\n")
else:
print("\\n" + "="*60)
print("✗ 安装失败")
print(" 请手动运行 's-install' 重试")
print("="*60 + "\\n")
except Exception as e:
print(f"\\n安装过程中出现错误: {e}")
print("请手动运行 's-install' 重试\\n")
with open("README.md", "r", encoding="utf-8") as f:
long_description = f.read()
setup(
name='serverless-devs',
version='1.0.3',
description='Serverless Devs Developer Tools - Python Package (Auto-install latest version)',
long_description=long_description,
long_description_content_type='text/markdown',
author='Serverless Devs',
author_email='service@serverless-devs.com',
url='https://github.com/Serverless-Devs/Serverless-Devs',
packages=find_packages(),
include_package_data=True,
entry_points={
'console_scripts': [
's=serverless_devs.__main__:main',
's-install=serverless_devs.installer:main',
],
},
cmdclass={
'install': PostInstallCommand,
},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Operating System :: OS Independent',
],
keywords='serverless devs aliyun faas function-compute',
python_requires='>=3.7', # 支持 3.7+
project_urls={
'Bug Reports': 'https://github.com/Serverless-Devs/Serverless-Devs/issues',
'Source': 'https://github.com/Serverless-Devs/Serverless-Devs',
'Documentation': 'https://www.serverless-devs.com/',
},
)
'''
create_file('setup.py', setup_py)
# ==================== 更新 __init__.py ====================
init_py = '''"""
Serverless Devs - Python Package
Install Serverless Devs via pip (automatically installs the latest version)
"""
__version__ = "1.0.3"
__author__ = "Serverless Devs"
__url__ = "https://www.serverless-devs.com/"
from .installer import install_serverless_devs
__all__ = ['install_serverless_devs']
'''
create_file('serverless_devs/__init__.py', init_py)
# ==================== 更新 GitHub Actions - Test ====================
github_test = '''name: Test Installation
on:
push:
branches: [ main, master, dev ]
pull_request:
branches: [ main, master, dev ]
workflow_dispatch:
jobs:
test:
name: Test on ${{ matrix.os }} - Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.10', '3.11', '3.12']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install package
run: |
python -m pip install --upgrade pip
pip install -e .
- name: Test Python import
run: |
python -c "import serverless_devs; print('Package version:', serverless_devs.__version__)"
- name: Test s-install command availability
shell: bash
run: |
if command -v s-install &> /dev/null; then
echo "✓ s-install command found"
else
echo "✗ s-install command not found"
exit 1
fi
- name: Install Serverless Devs
shell: bash
run: |
echo "Installing Serverless Devs..."
s-install
continue-on-error: true # 允许在 CI 环境中失败
- name: Check s command (if installed)
shell: bash
run: |
if command -v s &> /dev/null; then
echo "✓ s command found"
s --version
else
echo "ℹ s command not installed (may fail in CI environment)"
fi
continue-on-error: true
- name: Test npm availability (for debugging)
shell: bash
run: |
if command -v npm &> /dev/null; then
echo "✓ npm is available"
npm --version
else
echo "ℹ npm is not available"
fi
continue-on-error: true
'''
create_file('.github/workflows/test.yml', github_test)
# ==================== 更新 GitHub Actions - Publish ====================
github_publish = '''name: Publish to PyPI
on:
push:
tags:
- 'v*'
workflow_dispatch:
jobs:
publish:
name: Build and publish to PyPI
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: python -m build
- name: Check package
run: twine check dist/*
- name: List distribution files
run: ls -lh dist/
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload dist/*
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: dist/*
generate_release_notes: true
body: |
## Installation
```bash
pip install --upgrade serverless-devs
```
## What's Changed
See the full changelog at [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
'''
create_file('.github/workflows/publish.yml', github_publish)
# ==================== CHANGELOG.md ====================
changelog_md = '''# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.3] - 2025-11-11
### Added
- Bilingual documentation (English + Chinese)
- Real Serverless Devs installation test in CI
- Better badge URLs in README
### Changed
- CI now tests on Python 3.10, 3.11, 3.12
- Package still supports Python 3.7+
- Improved installation error messages
### Fixed
- Fixed README badge display issues
- Fixed CI test for s command
## [1.0.2] - 2025-11-11
### Added
- GitHub Actions auto-publish to PyPI
- Auto-install latest Serverless Devs (no hardcoded version)
- Domestic mirror acceleration support
### Changed
- Changed from binary download to official script installation
- Improved error messages and help information
## [1.0.1] - 2025-11-11
### Fixed
- Fixed Windows installation issues
## [1.0.0] - 2025-11-11
### Added
- Initial release
- Support for Windows, Linux, macOS
- Install Serverless Devs via pip
'''
create_file('CHANGELOG.md', changelog_md)
print("\n" + "="*60)
print("✓ 项目更新完成!")
print("="*60)
print("\n📋 更新内容:")
print(" ✅ 修复了 README badge 显示问题")
print(" ✅ 添加了中英文双语文档")
print(" ✅ CI 中真正测试 s 命令安装")
print(" ✅ CI 测试 Python 3.10+")
print(" ✅ 但仍支持 Python 3.7+ 安装")
print("\n📝 文档结构:")
print(" - README.md (English)")
print(" - README_zh.md (简体中文)")
print("\n🔧 下一步:")
print(" 1. git add .")
print(" 2. git commit -m 'feat: add bilingual docs and improve CI'")
print(" 3. git push")
print(" 4. git tag v1.0.3 && git push origin v1.0.3")
print("\n" + "="*60 + "\n")
if __name__ == '__main__':
update_project()