Skip to content

Commit a94e68b

Browse files
authored
Update update-readme.yml
1 parent 782ba42 commit a94e68b

1 file changed

Lines changed: 12 additions & 30 deletions

File tree

.github/workflows/update-readme.yml

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,23 @@ jobs:
2323
2424
- name: Get commit counts by author
2525
run: |
26-
git shortlog -sn | head -n 5 | awk '{print "👤 " $2 " " $1}' > authors.txt
26+
AUTHORS=$(git shortlog -sn | head -n 5 | awk '{print "👤 " $2 " " $1}' | paste -sd '\n')
27+
echo "AUTHORS<<EOF" >> $GITHUB_ENV
28+
echo "$AUTHORS" >> $GITHUB_ENV
29+
echo "EOF" >> $GITHUB_ENV
2730
2831
- name: Update README.md
2932
run: |
30-
STATS="📄 Total lines of code: $TOTAL_LINES\n🐍 Number of Python files: $PY_FILES\n\n🔢 Top contributors:"
33+
STATS="📄 Total lines of code: $TOTAL_LINES\n🐍 Number of Python files: $PY_FILES\n\n🔢 Top contributors:\n$AUTHORS"
3134
DATE="🕒 Last updated: $(date -u +"%Y-%m-%d %H:%M UTC")"
3235
33-
{
34-
echo "<!-- STATS:START -->"
35-
echo -e "$STATS"
36-
cat authors.txt
37-
echo "<!-- STATS:END -->"
38-
} > stats_block.txt
39-
40-
{
41-
echo "<!-- UPDATED:START -->"
42-
echo "$DATE"
43-
echo "<!-- UPDATED:END -->"
44-
} > updated_block.txt
45-
46-
awk '
47-
BEGIN { stats=0; updated=0 }
48-
/<!-- STATS:START -->/ { print; stats=1; next }
49-
/<!-- STATS:END -->/ {
50-
while ((getline line < "stats_block.txt") > 0) print line
51-
stats=0
52-
next
53-
}
54-
/<!-- UPDATED:START -->/ { print; updated=1; next }
55-
/<!-- UPDATED:END -->/ {
56-
while ((getline line < "updated_block.txt") > 0) print line
57-
updated=0
58-
next
59-
}
60-
stats || updated { next }
36+
awk -v stats="$STATS" -v date="$DATE" '
37+
BEGIN { statsBlock=0; dateBlock=0 }
38+
/<!-- STATS:START -->/ { print; print stats; statsBlock=1; next }
39+
/<!-- STATS:END -->/ { print; statsBlock=0; next }
40+
/<!-- UPDATED:START -->/ { print; print date; dateBlock=1; next }
41+
/<!-- UPDATED:END -->/ { print; dateBlock=0; next }
42+
statsBlock || dateBlock { next }
6143
{ print }
6244
' README.md > README.tmp && mv README.tmp README.md
6345

0 commit comments

Comments
 (0)