Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Wheel Request

### Library Information
- **Library Name**: [填写库名,如:numpy]
- **Version**: [版本要求,可选,如:latest 或 1.24.3]
- **Platform**: [平台要求,可选,如:macos, linux, windows]
- **Architecture**: [架构要求,可选,如:x86_64, arm64]

### Use Case
[描述为什么需要这个库,使用场景等]

### Additional Notes
[其他说明,如特殊要求、依赖关系等]

---

**注意**:
- 请确保 PR 标题格式为:`Add missing wheel: <库名>`
- 系统会自动从 PyPI 下载最新的兼容版本
- 如果指定了版本,系统会尝试下载该版本
- 支持多平台文件上传
52 changes: 52 additions & 0 deletions .github/workflows/auto-wheel-upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Auto Wheel Upload

on:
pull_request:
types: [opened, edited, synchronize]

jobs:
process-wheel-request:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.WHEEL_UPLOAD_TOKEN }}

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'

- name: Build llpkgstore
run: |
cd cmd/llpkgstore
go build -o llpkgstore .

- name: Process wheel request
env:
GITHUB_TOKEN: ${{ secrets.WHEEL_UPLOAD_TOKEN }}
TARGET_REPO_OWNER: Bigdata-shiyang
TARGET_REPO_NAME: test
GITHUB_REPOSITORY_OWNER: Bigdata-shiyang
GITHUB_REPOSITORY: llpkgstore-test
run: |
cd cmd/llpkgstore
./llpkgstore wheel-upload ${{ github.event.number }}

- name: Add success label
if: success()
run: |
gh pr edit ${{ github.event.number }} --add-label "wheel-added"
gh pr edit ${{ github.event.number }} --remove-label "wheel-request"

- name: Add failure label
if: failure()
run: |
gh pr edit ${{ github.event.number }} --add-label "wheel-failed"
gh pr edit ${{ github.event.number }} --remove-label "wheel-request"
175 changes: 175 additions & 0 deletions IMPLEMENTATION_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# llpkgstore Wheel Upload 功能实现总结

## 概述

已成功为 `llpkgstore` 实现了自动化 wheel 文件上传功能,该功能能够处理用户提交的 PR 请求,自动从 PyPI 下载 Python 库的 wheel 文件并上传到 GitHub Release。

## 实现的功能

### 1. 核心功能

- ✅ **PR 解析**:自动解析 PR 标题提取库名
- ✅ **PyPI 搜索**:从 PyPI JSON API 搜索库信息
- ✅ **版本选择**:智能选择最佳匹配的版本
- ✅ **平台匹配**:自动检测和匹配平台特定的 wheel 文件
- ✅ **文件下载**:从 PyPI 下载 wheel 文件
- ✅ **Release 管理**:创建或更新 GitHub Release
- ✅ **文件上传**:将 wheel 文件上传到 Release
- ✅ **状态更新**:在 PR 中添加成功评论

### 2. 技术特性

- ✅ **智能版本选择**:优先选择最新稳定版本
- ✅ **平台兼容性**:支持 macOS、Linux、Windows
- ✅ **架构支持**:支持 x86_64 和 aarch64
- ✅ **错误处理**:完善的错误处理和重试机制
- ✅ **配置管理**:灵活的环境变量配置
- ✅ **测试覆盖**:包含单元测试

### 3. 文件结构

```
llpkgstore/
├── cmd/llpkgstore/internal/
│ ├── wheel_upload.go # 主要实现文件
│ └── wheel_upload_test.go # 测试文件
├── config/
│ └── wheel_config.go # 配置管理
├── .github/
│ ├── workflows/
│ │ └── auto-wheel-upload.yml # GitHub Actions 工作流
│ └── pull_request_template.md # PR 模板
├── docs/
│ └── wheel-upload.md # 详细文档
└── demo_wheel_upload.sh # 演示脚本
```

## 使用方法

### 1. 用户提交 PR

**PR 标题格式**:
```
Add missing wheel: <库名>
```

**PR 描述示例**:
```markdown
## Wheel Request

### Library Information
- **Library Name**: numpy
- **Version**: latest
- **Platform**: macos
- **Architecture**: x86_64

### Use Case
需要使用 numpy 进行数值计算和数组操作
```

### 2. 环境配置

```bash
export GITHUB_TOKEN=your_github_token
export TARGET_REPO_OWNER=Bigdata-shiyang
export TARGET_REPO_NAME=test
```

### 3. 手动执行

```bash
cd cmd/llpkgstore
go build -o llpkgstore .
./llpkgstore wheel-upload <PR_NUMBER>
```

## 工作流程

1. **用户发现缺失**:用户执行 `llgo get <库名>` 失败
2. **提交 PR**:用户提交 PR 说明缺少某个库的 wheel 文件
3. **自动触发**:GitHub Actions 自动检测并触发处理流程
4. **PyPI 搜索**:从 PyPI 搜索库信息和最佳匹配的 wheel 文件
5. **文件下载**:下载选定的 wheel 文件
6. **Release 创建**:在目标仓库创建或更新 Release
7. **文件上传**:将 wheel 文件上传到 Release
8. **状态更新**:在 PR 中添加成功评论和状态更新

## Release 结构

上传的 wheel 文件会按照以下结构组织:

```
Bigdata-shiyang/test/releases
├── numpy/v1.24.3
│ ├── numpy-1.24.3-cp312-cp312-macosx_10_9_x86_64.whl
│ ├── numpy-1.24.3-cp312-cp312-linux_x86_64.whl
│ └── numpy-1.24.3-cp312-cp312-win_amd64.whl
├── pandas/v2.0.3
│ ├── pandas-2.0.3-cp312-cp312-macosx_10_9_x86_64.whl
│ └── pandas-2.0.3-cp312-cp312-linux_x86_64.whl
└── scipy/v1.11.1
├── scipy-1.11.1-cp312-cp312-macosx_10_9_x86_64.whl
└── scipy-1.11.1-cp312-cp312-linux_x86_64.whl
```

## 技术实现细节

### 1. PyPI 集成

- 使用 PyPI JSON API (`https://pypi.org/pypi/<库名>/json`)
- 解析 JSON 响应获取版本和文件信息
- 智能选择最佳匹配的 wheel 文件

### 2. GitHub API 集成

- 使用 `go-github/v69` 库
- 支持 PR 信息获取、Release 管理、文件上传
- 完善的错误处理和重试机制

### 3. 平台匹配算法

- 优先选择平台特定的 wheel 文件
- 支持 macOS、Linux、Windows 平台
- 支持 x86_64 和 aarch64 架构
- 回退到通用 wheel 文件

### 4. 配置管理

- 环境变量配置
- 默认值设置
- 平台检测
- 权限验证

## 测试结果

- ✅ 编译成功
- ✅ 单元测试通过
- ✅ 命令帮助正常显示
- ✅ 演示脚本运行正常

## 扩展性

### 1. 未来改进

- 批量处理多个库
- 依赖关系解析
- 版本回滚功能
- 监控和统计

### 2. 配置扩展

- 支持更多包源(Conda、自定义源)
- 支持更多文件类型
- 自定义版本选择策略

## 总结

已成功实现了完整的自动化 wheel 文件上传功能,包括:

1. **完整的代码实现**:核心功能、配置管理、错误处理
2. **完善的文档**:使用说明、技术文档、API 文档
3. **自动化工作流**:GitHub Actions 集成
4. **测试覆盖**:单元测试和集成测试
5. **用户友好**:PR 模板、演示脚本、帮助文档

该功能大大简化了 Python 库的 wheel 文件管理,用户只需要提交一个简单的 PR,系统就能自动完成从 PyPI 下载到 GitHub Release 上传的整个流程,实现了完全自动化的包管理和分发。
11 changes: 11 additions & 0 deletions _demo/cjson.pc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=/Users/admin/.conan2/p/b/cjson604c4b2303218/p
libdir=${prefix}/lib
includedir=${prefix}/include
bindir=${prefix}/bin

Name: cjson
Description: Conan package: cjson
Version: 1.7.18
Libs: -L"${libdir}"
Cflags: -I"${includedir}"
Requires: libcjson
10 changes: 10 additions & 0 deletions _demo/libcjson.pc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
prefix=/Users/admin/.conan2/p/b/cjson604c4b2303218/p
libdir=${prefix}/lib
includedir=${prefix}/include
bindir=${prefix}/bin

Name: libcjson
Description: Conan component: libcjson
Version: 1.7.18
Libs: -L"${libdir}" -lcjson
Cflags: -I"${includedir}"
Loading
Loading