Skip to content

Updtaed line of code workflow #7

Updtaed line of code workflow

Updtaed line of code workflow #7

Workflow file for this run

name: Update README with code stats
on:
push:
branches:
- main
jobs:
update-readme:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4 # Use a version compatible with Node.js 20
- name: Use Node.js 20
uses: actions/setup-node@v4 # Use version 4 or higher to support Node.js 20
with:
node-version: "20"
- name: Install tokei
run: |
curl -sSL https://github.com/XAMPPRocky/tokei/releases/download/v12.1.2/tokei-x86_64-unknown-linux-gnu.tar.gz | tar xz
mv tokei /usr/local/bin/
- name: Get code stats
run: |
stats=$(tokei .)
echo "$stats"
- name: Format code stats
run: |
stats_formatted=$(echo "$stats" | awk 'BEGIN{printf "%-21s%-12s%-12s%-12s%-12s\n", "Language", "Files", "Lines", "Code", "Comments"} {if(NR==1 || NR==2 || NF>2) print}' | sed 's/Total/-------------------------------------------------------------------------/g' | sed 's/\s\+|/-/g')
echo "$stats_formatted"
- name: Update README
run: |
stats=$(tokei .)
stats_formatted=$(echo "$stats" | awk 'BEGIN{printf "%-21s%-12s%-12s%-12s%-12s\n", "Language", "Files", "Lines", "Code", "Comments"} {if(NR==1 || NR==2 || NF>2) print}' | sed 's/Total/-------------------------------------------------------------------------/g' | sed 's/\s\+|/-/g')
sed -i "s/<!-- CODE_STATS_TABLE_PLACEHOLDER -->/\`\`\`$stats_formatted\`\`\`/g" README.md
- name: Commit changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add README.md
git commit -m "Update README with code stats" || echo "No changes to commit"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: main
force: true