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

66 lines
2.0 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=1000"
wget -qO response.json --header="Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$URL"
echo "API Response Preview:"
head -n 10 response.json
RAW_COUNT=$(grep -c "\"url\":" response.json || echo 0)
echo "Final count detected: $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