Skip to content

Commit f750dc3

Browse files
Merge pull request #3 from kunyuanxu-star/main
合并CI
2 parents d9cf548 + 1f1ecb5 commit f750dc3

2 files changed

Lines changed: 167 additions & 8 deletions

File tree

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Calculate Student Score
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
workflow_dispatch:
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
calculate-score:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
18+
- name: Setup jq
19+
run: |
20+
sudo apt-get update
21+
sudo apt-get install -y jq
22+
23+
- name: Check for student's article
24+
id: check_article
25+
run: |
26+
REPO_NAME=${{ github.repository }}
27+
OWNER=$(echo $REPO_NAME | cut -d'/' -f1)
28+
REPO=$(echo $REPO_NAME | cut -d'/' -f2)
29+
30+
ARTICLE_EXISTS=0
31+
32+
CONTENTS_RESPONSE=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
33+
"https://api.github.com/repos/$OWNER/$REPO/contents")
34+
35+
if echo "$CONTENTS_RESPONSE" | jq -r '.[].name' | grep -q "^$OWNER\.md$"; then
36+
ARTICLE_EXISTS=1
37+
echo "Found article file: $OWNER.md"
38+
else
39+
echo "No article file named $OWNER.md found"
40+
fi
41+
42+
echo "article_exists=$ARTICLE_EXISTS" >> $GITHUB_ENV
43+
44+
if [ $ARTICLE_EXISTS -eq 1 ]; then
45+
ARTICLE_BONUS=20
46+
else
47+
ARTICLE_BONUS=0
48+
fi
49+
echo "article_bonus=$ARTICLE_BONUS" >> $GITHUB_ENV
50+
51+
- name: Calculate score based on GitHub metrics
52+
id: calculate
53+
run: |
54+
REPO_NAME=${{ github.repository }}
55+
OWNER=$(echo $REPO_NAME | cut -d'/' -f1)
56+
REPO=$(echo $REPO_NAME | cut -d'/' -f2)
57+
58+
echo "Repository: $OWNER/$REPO"
59+
60+
STARS_RESPONSE=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
61+
"https://api.github.com/repos/$OWNER/$REPO")
62+
STARS=$(echo $STARS_RESPONSE | jq -r '.stargazers_count // 0')
63+
echo "Stars response: $STARS_RESPONSE"
64+
65+
ALL_ISSUES_RESPONSE=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
66+
"https://api.github.com/repos/$OWNER/$REPO/issues?state=all&per_page=100")
67+
ALL_ISSUES=$(echo "$ALL_ISSUES_RESPONSE" | jq -r 'map(select(.pull_request == null)) | length')
68+
69+
OPEN_ISSUES_RESPONSE=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
70+
"https://api.github.com/repos/$OWNER/$REPO/issues?state=open&per_page=100")
71+
OPEN_ISSUES=$(echo "$OPEN_ISSUES_RESPONSE" | jq -r 'map(select(.pull_request == null)) | length')
72+
73+
CLOSED_ISSUES=$((ALL_ISSUES - OPEN_ISSUES))
74+
75+
PRS_RESPONSE=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
76+
"https://api.github.com/repos/$OWNER/$REPO/pulls?state=all&per_page=100")
77+
PR_COUNT=$(echo "$PRS_RESPONSE" | jq -r 'length')
78+
79+
STAR_WEIGHT=10
80+
ISSUE_WEIGHT=20
81+
PR_WEIGHT=30
82+
83+
ARTICLE_BONUS=${{ env.article_bonus }}
84+
85+
SCORE=$((STARS * STAR_WEIGHT + CLOSED_ISSUES * ISSUE_WEIGHT + PR_COUNT * PR_WEIGHT + ARTICLE_BONUS))
86+
87+
echo "=================== 学员成绩报告 ==================="
88+
echo "Stars: $STARS (权重: $STAR_WEIGHT) = $((STARS * STAR_WEIGHT)) 分"
89+
echo "已解决的Issues: $CLOSED_ISSUES (权重: $ISSUE_WEIGHT) = $((CLOSED_ISSUES * ISSUE_WEIGHT)) 分"
90+
echo "Pull Requests: $PR_COUNT (权重: $PR_WEIGHT) = $((PR_COUNT * PR_WEIGHT)) 分"
91+
echo "个人文章提交: $ARTICLE_EXISTS (权重: 20) = $ARTICLE_BONUS 分"
92+
echo "=================================================="
93+
echo "总分: $SCORE 分"
94+
echo "更新时间: $(date)"
95+
96+
echo "stars=$STARS" >> $GITHUB_ENV
97+
echo "issues=$CLOSED_ISSUES" >> $GITHUB_ENV
98+
echo "prs=$PR_COUNT" >> $GITHUB_ENV
99+
echo "score=$SCORE" >> $GITHUB_ENV
100+
101+
- name: Post summary JSON to remote API
102+
run: |
103+
REPO_NAME=${{ github.repository }}
104+
OWNER=$(echo $REPO_NAME | cut -d'/' -f1)
105+
REPO=$(echo $REPO_NAME | cut -d'/' -f2)
106+
107+
ACTOR=${{ github.actor }}
108+
109+
ENCRYPTED_CONFIG="QVBJX1RPS0VOPWUzNjE5Y2NkZGFmYzQ3NTg5YmJlNzg4Y2EzMWEyZGYwCkFQSV9VUkw9aHR0cHM6Ly9hcGkub3BlbmNhbXAuY24vd2ViL2FwaS9jb3Vyc2VSYW5rL2NyZWF0ZUJ5VGhpcmRUb2tlbgpDT1VSU0VfSUQ9MTk0OAo="
110+
111+
echo "$ENCRYPTED_CONFIG" | base64 -d > /tmp/decrypted-config.env
112+
source /tmp/decrypted-config.env
113+
114+
SUMMARY=$(cat <<EOF
115+
{
116+
"channel": "github",
117+
"courseId": $COURSE_ID,
118+
"ext": "aaa",
119+
"name": "$ACTOR",
120+
"score": ${{ env.score }},
121+
"totalScore": 9999
122+
}
123+
EOF
124+
)
125+
126+
curl -X POST "$API_URL" \
127+
-H "accept: application/json;charset=utf-8" \
128+
-H "Content-Type: application/json" \
129+
-H "token: $API_TOKEN" \
130+
-d "$SUMMARY" \
131+
-v
132+
133+
rm /tmp/decrypted-config.env

README.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,40 @@
44

55
Upstream 这个代码仓用于帮助商业训练营的同学们完成作业。
66

7-
作业安排:
7+
## 作业安排:
88

99
每位同学首先:
1010

11-
构建自己的仓库 Fork github.com/mofa/github到自己的仓库
12-
以Markdown的格式(.md)提交一篇文章 写一篇有关训练营/自己组队的想法的文章,笔记等,提交到自己的Repo请使用自己的GitHub 用户名命名该md文件。
13-
至少给其他同学的3个repo各提1个issue。
14-
给其他同学的repo 10个stars
15-
解决自己Repo至少一个issue。
16-
获得10个stars 想办法为自己的Repo获得十个点赞
17-
提交PR
11+
1. 构建自己的仓库 Fork本仓库
12+
2. 以Markdown的格式(.md)提交一篇文章 写一篇有关训练营/自己组队的想法的文章,笔记等,提交到自己的Repo请使用自己的GitHub 用户名命名该md文件。
13+
3. 至少给其他同学的3个repo各提1个issue。
14+
4. 给其他同学的repo 10个stars
15+
5. 解决自己Repo至少一个issue。
16+
6. 获得10个stars 想办法为自己的Repo获得十个点赞
17+
7. 提交PR
18+
19+
## 自动评分系统
20+
21+
本仓库包含一个自动评分系统,用于评估学员在GitHub上的参与度和贡献。评分系统会根据以下指标自动计算分数:
22+
23+
### 计分标准
24+
25+
| 指标 | 权重 | 说明 |
26+
|------|------|------|
27+
| Stars | 10分/个 | 每获得一个star得10分 |
28+
| 已解决的Issues | 20分/个 | 每解决一个issue得20分 |
29+
| Pull Requests | 30分/个 | 每提交一个PR得30分 |
30+
| 个人文章提交 | 20分 | 提交以自己GitHub用户名命名的.md文章得20分 |
31+
32+
### 总分说明
33+
34+
- 系统会每天自动计算分数并在终端输出成绩报告
35+
- 总分上限为9999分
36+
- 学员可以通过积极参与获得更多分数,没有严格的上限限制
37+
- 评分结果会通过API发送到课程系统
38+
39+
### 如何查看自己的分数
40+
41+
- 系统每天北京时间早上8点自动运行计算分数
42+
- 每次向仓库push代码时也会触发分数计算
43+
- 可以通过GitHub Actions界面手动触发计算

0 commit comments

Comments
 (0)