Files
.profile/.gitea/workflows/update-readme.yaml
2026-01-21 21:53:33 -05:00

82 lines
2.5 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 "Requesting 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")
if [ "$RESP" = "[]" ] || [ -z "$RESP" ]; then
echo "Reached the end of history at page $PAGE."
break
fi
PAGE_NAMES=$(echo "$RESP" | grep -o "\"name\":\"patrick\"" | wc -l || echo 0)
echo "Page $PAGE: Found $PAGE_NAMES name matches."
TOTAL_NAMES=$((TOTAL_NAMES + PAGE_NAMES))
PAGE=$((PAGE + 1))
if [ "$PAGE" -gt 100 ]; then break; fi
done
RAW_COUNT=$((TOTAL_NAMES / 2))
echo "COMMIT_VELOCITY=$RAW_COUNT" >> $GITHUB_ENV
echo "Final tally for Patrick: $RAW_COUNT"
- 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