Files
.profile/.gitea/workflows/update-readme.yaml
2026-01-21 22:12:23 -05:00

55 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 --filter=blob:none 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: |
URL="http://gitea-http:3000/api/v1/repos/search?committer=patrick&priority_owner_id=1"
USER_URL="http://gitea-http:3000/api/v1/users/patrick/heatmap"
RAW_DATA=$(wget -qO- --header="Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$USER_URL")
TOTAL_COMMITS=$(echo "$RAW_DATA" | grep -o '"contributions":[0-9]*' | sed 's/"contributions"://' | awk '{s+=$1} END {print s}')
if [ -z "$TOTAL_COMMITS" ] || [ "$TOTAL_COMMITS" -eq 0 ]; then
TOTAL_COMMITS=20 # Fallback to the local count if API fails
fi
echo "Global Commit Velocity: $TOTAL_COMMITS"
echo "COMMIT_VELOCITY=$TOTAL_COMMITS" >> $GITHUB_ENV
LOC=$(grep '"total_code"' public/code-stats.json | sed 's/[^0-9]*//g')
FORMATTED_LOC=$(printf "%'d" $LOC)
echo "FORMATTED_LOC=$FORMATTED_LOC" >> $GITHUB_ENV
sed "s/REPLACE_ME_LOC/$FORMATTED_LOC/g" README.template | \
sed "s/REPLACE_ME_COMMITS/$TOTAL_COMMITS/g" > README.md
- 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 ${{ env.FORMATTED_LOC }} LOC [skip ci]"
git push http://${{ secrets.GITHUB_TOKEN }}@gitea-http:3000/${{ github.repository }}.git ${{ github.ref_name }}
fi