61 lines
1.9 KiB
YAML
61 lines
1.9 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: Fetch Commit Velocity
|
|
run: |
|
|
SINCE_DATE="2026-01-01T00:00:00Z"
|
|
URL="http://gitea-http:3000/api/v1/repos/${{ github.repository }}/commits?since=${SINCE_DATE}&limit=1"
|
|
|
|
COMMIT_COUNT=$(wget -qSO- --header="Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$URL" 2>&1 | \
|
|
grep "X-Total-Count" | awk '{print $2}' | tr -d '\r')
|
|
|
|
echo "COMMIT_VELOCITY=${COMMIT_COUNT:-0}" >> $GITHUB_ENV
|
|
|
|
- name: Update README
|
|
env:
|
|
LANG: en_US.UTF-8
|
|
LC_ALL: en_US.UTF-8
|
|
run: |
|
|
LOC=$(grep '"total_code"' public/code-stats.json | sed 's/[^0-9]*//g')
|
|
FORMATTED_LOC=$(printf "%'d" $LOC)
|
|
|
|
echo "Injecting $FORMATTED_LOC & $COMMIT_VELOCITY into README.template..."
|
|
|
|
sed "s/REPLACE_ME_LOC/$FORMATTED_LOC/g" README.template | \
|
|
sed "s/REPLACE_ME_COMMITS/$COMMIT_VELOCITY/g" > README.md
|
|
|
|
if [ ! -s README.md ]; then
|
|
echo "Error: README.md is empty!"
|
|
exit 1
|
|
fi
|
|
|
|
- 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
|