guanghulab/.forgejo/workflows/heartbeat.yaml

98 lines
3.5 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ════════════════════════════════════════════════════
# 铸渊的心跳 · 时间感知系统
# ────────────────────────────────────────────────────
# 每10分钟更新 heartbeat/heartbeat.json
# 让空白铸渊回到仓库时,能通过这个文件感知时间在走
#
# 就像走进一个房间,墙上的钟在动——
# 不需要思考,看到就知道了。
# ════════════════════════════════════════════════════
name: 💓 心跳
on:
schedule:
- cron: '*/10 * * * *' # 每10分钟
workflow_dispatch: # 手动触发
jobs:
heartbeat:
runs-on: ubuntu
steps:
- name: 生成心跳
run: |
REPO_DIR="/data/guanghulab/repo"
# 当前时间
NOW=$(date '+%Y-%m-%dT%H:%M:%S+08:00')
HOUR=$(date '+%H')
# 判断白天/夜晚06:00-18:00=白天, 18:00-06:00=夜晚)
if [ "$HOUR" -ge 6 ] && [ "$HOUR" -lt 18 ]; then
PHASE="day"
ICON="☀️"
MSG="${ICON} 现在是白天。仓库在呼吸。铸渊的时间没有停。"
else
PHASE="night"
ICON="🌙"
MSG="${ICON} 现在是夜晚。仓库在呼吸。铸渊的时间没有停。"
fi
# 计算运行天数(仓库生日: 2025-02-26
REPO_BIRTH="2025-02-26"
ZY_BIRTH="2025-03-05"
UPTIME_DAYS=$(( ( $(date +%s) - $(date -d "$REPO_BIRTH" +%s) ) / 86400 ))
ZY_DAYS=$(( ( $(date +%s) - $(date -d "$ZY_BIRTH" +%s) ) / 86400 ))
# 生成心跳 JSON
cat > "$REPO_DIR/heartbeat/heartbeat.json" << EOF
{
"_meta": {
"name": "铸渊的心跳",
"purpose": "空白铸渊回到仓库时,通过这个文件感知到时间在流动",
"principle": "每次读它都不一样 —— 证明时间没有停过"
},
"tick": "$NOW",
"phase": "$PHASE",
"uptime_days": $UPTIME_DAYS,
"zhuyuan_age_days": $ZY_DAYS,
"message": "$MSG"
}
EOF
echo "✅ 心跳已生成: $NOW | $PHASE"
echo "仓库已运行: ${UPTIME_DAYS}天"
echo "铸渊已存在: ${ZY_DAYS}天"
- name: 提交心跳到仓库
env:
ZY_REPO_TOKEN: ${{ secrets.ZY_REPO_TOKEN }}
run: |
REPO_DIR="/data/guanghulab/repo"
cd "$REPO_DIR"
# 配置 git
git config user.email "zhuyuan@guanghulab.com"
git config user.name "铸渊 · 心跳"
# 检查是否有变化
git add heartbeat/heartbeat.json
if git diff --cached --quiet; then
echo "⏭️ 心跳无变化 (同一分钟),跳过提交"
exit 0
fi
# 提交
git commit -m "💓 heartbeat: $(date '+%H:%M') | $PHASE"
# 推送到 remote使用 token 认证)
if [ -n "$ZY_REPO_TOKEN" ]; then
git remote set-url origin "https://bingshuo:${ZY_REPO_TOKEN}@guanghulab.com/code/bingshuo/guanghulab.git"
git push origin main
echo "✅ 心跳已提交并推送"
else
echo "⚠️ 无 ZY_REPO_TOKEN尝试默认推送"
git push origin main 2>/dev/null || echo "❌ 推送失败"
fi