name: Update Code Statistics on: push: paths: - 'public/code-stats.json' - 'public/heatmap.json' - 'public/abuseipdb.json' workflow_dispatch: jobs: sync-stats: runs-on: ubuntu-latest container: image: ghcr.io/catthehacker/ubuntu:act-24.04 steps: - name: Manual Internal Checkout run: | git clone --filter=blob:none https://git.beane.me/${{ github.repository }}.git . git checkout ${{ github.ref_name }} - name: Sync with upstream run: | git fetch origin git rebase origin/${{ github.ref_name }} - name: Install dependencies env: DEBIAN_FRONTEND: noninteractive run: | set -eu if ! command -v jq >/dev/null 2>&1 || ! command -v python3 >/dev/null 2>&1; then apt-get update apt-get install -y --no-install-recommends jq python3 fi - name: Process Statistics and Update README run: | # 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=$(jq -er '.total_code' public/code-stats.json) FORMATTED_LOC=$(python3 -c \ 'import sys; print(f"{int(sys.argv[1]):,}")' "$LOC") echo "FORMATTED_LOC=$FORMATTED_LOC" >> "$GITHUB_ENV" # Pushed by infra-monitor's push_profile_stats.py. Shown rounded down to # the thousand ("31,000+"); falls back to the last hand-written figure # if the file hasn't been published yet. ABUSE_FILE="public/abuseipdb.json" if [ -f "$ABUSE_FILE" ]; then ABUSE_REPORTS=$(jq -er '.total_reports' "$ABUSE_FILE") FORMATTED_ABUSE=$(python3 -c \ 'import sys; n=int(sys.argv[1]); print(f"{n // 1000 * 1000:,}+")' "$ABUSE_REPORTS") else FORMATTED_ABUSE="30,000+" fi echo "AbuseIPDB reports: $FORMATTED_ABUSE" 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" | \ sed "s/REPLACE_ME_ABUSE/$FORMATTED_ABUSE/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 https://patrick:${{ secrets.PAT_TOKEN }}@git.beane.me/${{ github.repository }}.git ${{ github.ref_name }} fi