Update GitHub Stats #1348
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 GitHub Stats | |
| on: | |
| schedule: | |
| - cron: '30 */3 * * *' # 每 3 小时(在代码字节统计后 30 分钟,错开执行) | |
| workflow_dispatch: # 允许手动触发 | |
| push: | |
| paths: | |
| - 'svg/git-stats/**' # Go 代码变更时也触发 | |
| jobs: | |
| update-git-stats: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.21' | |
| cache: false | |
| - name: Run GitHub stats generator | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| working-directory: ./svg/git-stats | |
| run: go run main.go | |
| - name: Commit and push changes | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| git add -f profile/github-stats.svg profile/README.md | |
| git diff --staged --quiet && exit 0 | |
| git commit -m "chore: auto-update GitHub stats [skip ci]" | |
| for i in 1 2 3; do | |
| git pull --rebase origin main && git push && break | |
| echo "Retry $i..." | |
| sleep $((i * 5)) | |
| done |