-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (59 loc) · 2.01 KB
/
Copy pathcommit.yml
File metadata and controls
72 lines (59 loc) · 2.01 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
name: Daily Commit
on:
schedule:
# 每天 UTC 0-23 随机触发(通过多个 cron 实现)
- cron: '0 1 * * *'
- cron: '0 5 * * *'
- cron: '0 9 * * *'
- cron: '0 13 * * *'
- cron: '0 17 * * *'
- cron: '0 21 * * *'
workflow_dispatch: # 支持手动触发
permissions:
contents: write
env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
jobs:
commit:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Random delay
run: |
# 随机延迟 0-300 秒(5分钟内)
DELAY=$((RANDOM % 301))
echo "Waiting ${DELAY} seconds..."
sleep ${DELAY}
- name: Make commit
run: |
# 生成今天的日期文件
TODAY=$(date '+%Y-%m-%d')
NOW=$(date '+%H:%M:%S')
# 检查今天是否已经提交
if [ -f "contributions/${TODAY}.txt" ]; then
echo "Already committed today, skipping..."
exit 0
fi
# 读取配置
if [ -f "config.json" ]; then
# 获取随机模板
TEMPLATES=$(cat config.json | jq -r '.content_templates[]')
TEMPLATE=$(echo "$TEMPLATES" | shuf -n 1)
# 替换变量
CONTENT=$(echo "$TEMPLATE" | sed "s/{date}/$TODAY/g" | sed "s/{time}/$NOW/g")
# 获取提交信息模板
COMMIT_MSG=$(cat config.json | jq -r '.commit_message' | sed "s/{date}/$TODAY/g")
else
CONTENT="Contribution on ${TODAY} ${NOW}"
COMMIT_MSG="feat: contribution ${TODAY}"
fi
# 创建文件
echo "$CONTENT" >> contributions/${TODAY}.txt
# 配置 git
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
# 提交
git add .
git commit -m "$COMMIT_MSG"
git push