54 lines
1.7 KiB
YAML
54 lines
1.7 KiB
YAML
name: Update Code Statistics
|
|
on:
|
|
push:
|
|
paths:
|
|
- 'public/code-stats.json'
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
sync-stats:
|
|
runs-on: sh
|
|
steps:
|
|
- name: Manual Internal Checkout
|
|
run: |
|
|
git clone http://gitea-http:3000/${{ github.repository }}.git .
|
|
git checkout ${{ github.ref_name }}
|
|
|
|
- name: Sync with upstream
|
|
run: |
|
|
git fetch origin
|
|
git rebase origin/${{ github.ref_name }}
|
|
|
|
- name: Process Statistics and Update README
|
|
run: |
|
|
HUMAN_COUNT=$(git rev-list --count --author="patrick" --since="2026-01-01" --all)
|
|
|
|
echo "Local Git detected $HUMAN_COUNT commits by Patrick since Jan 1."
|
|
|
|
LOC=$(grep '"total_code"' public/code-stats.json | sed 's/[^0-9]*//g')
|
|
FORMATTED_LOC=$(printf "%'d" $LOC)
|
|
|
|
echo "Injecting $FORMATTED_LOC LOC and $HUMAN_COUNT Commits into README..."
|
|
|
|
sed "s/REPLACE_ME_LOC/$FORMATTED_LOC/g" README.template | \
|
|
sed "s/REPLACE_ME_COMMITS/$HUMAN_COUNT/g" > README.md
|
|
|
|
if [ ! -s README.md ]; then
|
|
echo "Error: README.md is empty!"
|
|
exit 1
|
|
fi
|
|
|
|
echo "FORMATTED_LOC=$FORMATTED_LOC" >> $GITHUB_ENV
|
|
|
|
- name: Commit and Push
|
|
run: |
|
|
git config user.name "Ares-Bot"
|
|
git config user.email "ares@beane.me"
|
|
git add README.md
|
|
if git diff --staged --quiet; then
|
|
echo "No changes"
|
|
else
|
|
git commit -m "chore: sync code velocity to $FORMATTED_LOC LOC [skip ci]"
|
|
git push http://${{ secrets.GITHUB_TOKEN }}@gitea-http:3000/${{ github.repository }}.git ${{ github.ref_name }}
|
|
fi
|