83 lines
2.6 KiB
YAML
83 lines
2.6 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"
|
|
PAGE=1
|
|
TOTAL_NAMES=0
|
|
|
|
while true; do
|
|
echo "Fetching page $PAGE..."
|
|
URL="http://gitea-http:3000/api/v1/repos/${{ github.repository }}/commits?since=${SINCE_DATE}&page=${PAGE}&limit=50"
|
|
|
|
RESP=$(wget -qO- --header="Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$URL")
|
|
|
|
PAGE_NAMES=$(echo "$RESP" | grep -o "\"name\":\"patrick\"" | wc -l || echo 0)
|
|
|
|
if [ "$PAGE_NAMES" -eq 0 ]; then
|
|
echo "No more commits found for user 'patrick' on page $PAGE."
|
|
break
|
|
fi
|
|
|
|
TOTAL_NAMES=$((TOTAL_NAMES + PAGE_NAMES))
|
|
echo "Found $PAGE_NAMES name matches on page $PAGE. Total matches: $TOTAL_NAMES"
|
|
|
|
PAGE=$((PAGE + 1))
|
|
|
|
if [ "$PAGE" -gt 100 ]; then break; fi
|
|
done
|
|
|
|
# Final calculation
|
|
RAW_COUNT=$((TOTAL_NAMES / 2))
|
|
echo "Final Human Count: $RAW_COUNT"
|
|
echo "COMMIT_VELOCITY=$RAW_COUNT" >> $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
|