Skip to content

Merge pull request #181 from SheetMetalConnect/claude/add-release-tra… #16

Merge pull request #181 from SheetMetalConnect/claude/add-release-tra…

Merge pull request #181 from SheetMetalConnect/claude/add-release-tra… #16

Workflow file for this run

name: Update Repository Stats
on:
push:
branches: [ main ]
schedule:
- cron: '0 0 * * 0' # Weekly on Sunday
workflow_dispatch:
jobs:
update-stats:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for accurate stats
- name: Calculate Stats
id: stats
run: |
# Total commits
COMMITS=$(git rev-list --count HEAD)
echo "commits=$COMMITS" >> $GITHUB_OUTPUT
# First commit date (inception)
INCEPTION=$(git log --reverse --format="%as" | head -1)
echo "inception=$INCEPTION" >> $GITHUB_OUTPUT
# Lines of code (TypeScript/JavaScript/CSS)
LOC=$(find src -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" -o -name "*.css" \) -exec cat {} + 2>/dev/null | wc -l)
LOC=${LOC:-0}
if [ "$LOC" -gt 1000 ]; then
LOC_K=$((LOC / 1000))
echo "loc=${LOC_K}K" >> $GITHUB_OUTPUT
else
echo "loc=$LOC" >> $GITHUB_OUTPUT
fi
# Commits in last 30 days
RECENT=$(git rev-list --count --since="30 days ago" HEAD)
echo "recent=$RECENT" >> $GITHUB_OUTPUT
- name: Update README
run: |
# Update badges in README
sed -i 's/!\[Commits\](https:\/\/img.shields.io\/badge\/commits-[^)]*)/![Commits](https:\/\/img.shields.io\/badge\/commits-${{ steps.stats.outputs.commits }}-blue)/' README.md
sed -i 's/!\[Inception\](https:\/\/img.shields.io\/badge\/inception-[^)]*)/![Inception](https:\/\/img.shields.io\/badge\/inception-${{ steps.stats.outputs.inception }}-lightgrey)/' README.md
sed -i 's/!\[LOC\](https:\/\/img.shields.io\/badge\/lines-[^)]*)/![LOC](https:\/\/img.shields.io\/badge\/lines-${{ steps.stats.outputs.loc }}-green)/' README.md
sed -i 's/!\[Velocity\](https:\/\/img.shields.io\/badge\/last_30d-[^)]*)/![Velocity](https:\/\/img.shields.io\/badge\/last_30d-${{ steps.stats.outputs.recent }}_commits-orange)/' README.md
- name: Commit changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git diff --quiet README.md || (git add README.md && git commit -m "chore: update stats [skip ci]" && git push)