Files
.profile/.gitea/workflows/update-readme.yaml

63 lines
2.2 KiB
YAML

name: Update Code Statistics
on:
push:
paths:
- 'public/code-stats.json'
- 'public/heatmap.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: |
if ! command -v jq &> /dev/null; then
if command -v apk &> /dev/null; then apk add --no-cache jq;
elif command -v apt-get &> /dev/null; then apt-get update && apt-get install -y jq; fi
fi
if ! command -v python3 &> /dev/null; then
if command -v apk &> /dev/null; then apk add --no-cache python3;
elif command -v apt-get &> /dev/null; then apt-get update && apt-get install -y python3; fi
fi
# Use our own heatmap.json instead of Gitea API
HEATMAP_FILE="public/heatmap.json"
TOTAL_COMMITS=$(jq '[.days[] | .count] | add' "$HEATMAP_FILE")
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
python3 scripts/generate_heatmap_svg.py public/heatmap.json public/heatmap.svg
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 public/heatmap.svg
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "chore: sync profile metrics [skip ci]"
git push http://patrick:${{ secrets.PAT_TOKEN }}@gitea-http:3000/${{ github.repository }}.git ${{ github.ref_name }}
fi