Update Badges #81
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Badges | |
| on: | |
| schedule: | |
| - cron: '0 0 */2 * *' # 每48小时运行一次(每隔2天的0点运行) | |
| workflow_dispatch: # 允许手动触发 | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| update-badges: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v1 | |
| with: | |
| bun-version: latest | |
| - name: Install dependencies | |
| run: bun install | |
| - name: Run tests | |
| run: bun test | |
| - name: Update badges | |
| run: | | |
| # 获取当前时间戳 | |
| TIMESTAMP=$(date +%s) | |
| # 更新 README.md 中的徽章时间戳 | |
| # 使用临时文件来避免 sed 命令中的特殊字符问题 | |
| TMP_FILE=$(mktemp) | |
| # 更新所有徽章的时间戳 | |
| sed "s|&t=[0-9]*|&t=$TIMESTAMP|g" README.md > "$TMP_FILE" | |
| mv "$TMP_FILE" README.md | |
| - name: Commit changes | |
| run: | | |
| git config --local user.email "github-action@itcox.cn" | |
| git config --local user.name "GitHub Action" | |
| git add README.md | |
| git commit -m "chore: update badges with timestamp" || exit 0 | |
| git push || { | |
| echo "Failed to push changes. Retrying with force push..." | |
| git push -f || { | |
| echo "Force push failed. Please check the repository permissions." | |
| exit 1 | |
| } | |
| } |