Skip to content

Commit 655abeb

Browse files
committed
chore: add README and GitHub Actions workflow for testing
1 parent 9ca160c commit 655abeb

2 files changed

Lines changed: 177 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [18.x]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
25+
- name: Install pnpm
26+
uses: pnpm/action-setup@v2
27+
with:
28+
version: 8
29+
run_install: false
30+
31+
- name: Get pnpm store directory
32+
shell: bash
33+
run: |
34+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
35+
36+
- name: Setup pnpm cache
37+
uses: actions/cache@v3
38+
with:
39+
path: ${{ env.STORE_PATH }}
40+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
41+
restore-keys: |
42+
${{ runner.os }}-pnpm-store-
43+
44+
- name: Install dependencies
45+
run: pnpm install
46+
47+
- name: Run tests
48+
run: pnpm test

README.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# GitHub Achievements API
2+
3+
[![License](https://img.shields.io/github/license/wangrunlin/github-achievements-api)](https://github.com/wangrunlin/github-achievements-api/blob/main/LICENSE)
4+
[![GitHub package.json version](https://img.shields.io/github/package-json/v/wangrunlin/github-achievements-api)](https://github.com/wangrunlin/github-achievements-api/blob/main/package.json)
5+
[![GitHub last commit](https://img.shields.io/github/last-commit/wangrunlin/github-achievements-api)](https://github.com/wangrunlin/github-achievements-api/commits)
6+
[![Test Status](https://img.shields.io/github/actions/workflow/status/wangrunlin/github-achievements-api/test.yml?label=test)](https://github.com/wangrunlin/github-achievements-api/actions)
7+
8+
一个简单的 API 服务,用于获取 GitHub 用户的成就信息。基于 Cloudflare Workers 构建。
9+
10+
## 在线使用
11+
12+
- [https://github-achievements-api.wangrunlin.workers.dev](https://github-achievements-api.wangrunlin.workers.dev)
13+
14+
## 功能特点
15+
16+
- 获取用户的 GitHub 成就列表
17+
- 支持成就等级统计
18+
- 提供原始成就数量和加权成就数量
19+
- 自动缓存结果(1 小时)以提高性能
20+
- 使用 Cloudflare Workers 部署,低延迟全球访问
21+
22+
## API 使用说明
23+
24+
### 基本端点
25+
26+
```http
27+
GET https://<your-worker>.workers.dev/<github_username>
28+
```
29+
30+
### 示例请求
31+
32+
```http
33+
GET https://<your-worker>.workers.dev/wangrunlin
34+
```
35+
36+
### 响应格式
37+
38+
```json
39+
{
40+
"total": {
41+
"raw": 5, // 原始成就数量(不计算等级)
42+
"weighted": 8 // 加权成就数量(计算等级)
43+
},
44+
"achievements": [
45+
{
46+
"type": "pair-extraordinaire",
47+
"tier": 3
48+
},
49+
{
50+
"type": "pull-shark",
51+
"tier": 2
52+
},
53+
{
54+
"type": "quickdraw",
55+
"tier": 1
56+
}
57+
// ...
58+
]
59+
}
60+
```
61+
62+
## 本地开发
63+
64+
### 前置要求
65+
66+
- Node.js 18+
67+
- pnpm
68+
69+
### 安装依赖
70+
71+
```bash
72+
pnpm install
73+
```
74+
75+
### 本地运行
76+
77+
```bash
78+
pnpm dev
79+
```
80+
81+
### 运行测试
82+
83+
```bash
84+
pnpm test
85+
```
86+
87+
## 部署
88+
89+
1. 登录到 Cloudflare
90+
91+
```bash
92+
pnpm dlx wrangler login
93+
```
94+
95+
2. 部署 Worker
96+
97+
```bash
98+
pnpm deploy
99+
```
100+
101+
## 技术栈
102+
103+
- TypeScript
104+
- Cloudflare Workers
105+
- Vitest (测试框架)
106+
- Wrangler (开发&部署工具)
107+
108+
## 许可证
109+
110+
MIT
111+
112+
## 贡献指南
113+
114+
欢迎提交 Issue 和 Pull Request!
115+
116+
1. Fork 本仓库
117+
2. 创建你的特性分支 (`git checkout -b feature/AmazingFeature`)
118+
3. 提交你的更改 (`git commit -m 'Add some AmazingFeature'`)
119+
4. 推送到分支 (`git push origin feature/AmazingFeature`)
120+
5. 开启一个 Pull Request
121+
122+
## 作者
123+
124+
[Leo Wang](https://github.com/wangrunlin)
125+
126+
## 致谢
127+
128+
- GitHub 提供的成就系统
129+
- Cloudflare Workers 平台

0 commit comments

Comments
 (0)