Skip to content

插件仓库可用性检查 #55

插件仓库可用性检查

插件仓库可用性检查 #55

Workflow file for this run

name: 插件仓库可用性检查
on:
schedule:
# 每天 UTC 04:00 = 北京时间 12:00
- cron: '0 4 * * *'
workflow_dispatch:
inputs:
grace_hours:
description: '不可访问多少小时后自动移除'
required: false
default: '24'
permissions:
contents: write
issues: write
pull-requests: write
concurrency:
group: health-check
cancel-in-progress: false
jobs:
health:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: 检查各插件仓库是否可访问
id: check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GRACE_HOURS: ${{ github.event.inputs.grace_hours || '24' }}
run: python .github/scripts/health_check.py
- name: 创建 PR 提交变更
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHANGED: ${{ steps.check.outputs.changed }}
run: |
if [[ -z "$(git status --porcelain plugins.json onebot_plugins.json .github/health-state.json)" ]]; then
echo "无变更,跳过"
exit 0
fi
DATE=$(date -u +%Y-%m-%d)
BRANCH="health-check/${DATE}"
MSG="chore(health): 更新仓库可用性状态"
[[ "$CHANGED" == "true" ]] && MSG="$MSG 并移除失效插件"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# 关闭旧的健康检查 PR
OLD_PRS=$(gh pr list --search "head:health-check/" --state open --json number --jq '.[].number' 2>/dev/null || true)
for NUM in $OLD_PRS; do
gh pr close "$NUM" --delete-branch 2>/dev/null || true
done
# 如果远程已有同名分支则删除
git push origin --delete "$BRANCH" 2>/dev/null || true
git checkout -b "$BRANCH"
git add plugins.json onebot_plugins.json .github/health-state.json
git commit -m "$MSG"
git push origin "$BRANCH"
# 使用健康检查报告作为 PR 正文(报告中已包含 @插件作者 提醒)
gh pr create \
--title "$MSG" \
--body-file .github/health-report.md \
--base main \
--head "$BRANCH"
echo "pr_created=true" >> "$GITHUB_OUTPUT"
- name: 开/更新/关闭告警 Issue
if: steps.check.outputs.notify == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ACTIVE: ${{ steps.check.outputs.active }}
run: |
TITLE="🔴 插件仓库可用性告警"
BODY=.github/health-report.md
NUM=$(gh issue list --state open --json number,title \
--jq ".[] | select(.title==\"$TITLE\") | .number" | head -n1)
if [[ -n "$NUM" ]]; then
gh issue comment "$NUM" --body-file "$BODY"
elif [[ "$ACTIVE" == "true" ]]; then
NUM=$(gh issue create --title "$TITLE" --body-file "$BODY" | grep -oE '[0-9]+$' | tail -n1)
fi
# 问题已全部解决 (恢复或已移除) 则关闭告警 Issue
if [[ "$ACTIVE" != "true" && -n "$NUM" ]]; then
gh issue comment "$NUM" --body "✅ 所有此前不可访问的仓库均已恢复或对应插件已移除,关闭告警。"
gh issue close "$NUM"
fi