Update Code Byte Stats #461
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 Code Byte Stats | |
| on: | |
| schedule: | |
| - cron: '0 */3 * * *' # 每 3 小时自动运行 | |
| workflow_dispatch: # 允许手动触发 | |
| push: | |
| paths: | |
| - 'svg/byte-stats/**' # Go 代码变更时也触发 | |
| jobs: | |
| update-byte-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 byte stats generator | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| working-directory: ./svg/byte-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/byte-stats.svg profile/README.md | |
| git diff --staged --quiet && exit 0 | |
| git commit -m "chore: auto-update byte 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 |