-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (44 loc) · 1.91 KB
/
lines-of-code.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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@v3
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