Skip to content

Commit f40aaaa

Browse files
committed
chore: update gen-readme workflow
1 parent f113ce8 commit f40aaaa

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

.github/workflows/gen-readme.yml

+27-5
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,42 @@ jobs:
1313
contents: write
1414
steps:
1515
- uses: actions/checkout@master
16-
- run: |
17-
[ -f README.tmpl.md ] || cp README.md README.tmpl.md # Initialize README.tmpl.md
16+
with: # We need to fetch enough commits to check if we've waited long enough
17+
fetch-depth: 12
18+
- name: Check if we've waited long enough (10+ commits)
19+
id: commit-count
20+
continue-on-error: true
21+
run: |
22+
[ '${{ github.event_name }}' != 'workflow_dispatch' ] || exit 0
23+
last_sha=$(git log --oneline --format=format:%H --grep="^chore: Generate README$" -1)
24+
echo "last_sha=$last_sha"
25+
if [ -n "$last_sha" ]; then # success if last_sha is empty
26+
count=$(git rev-list $last_sha..HEAD --count)
27+
echo "count=$count"
28+
[ $count -gt 10 ] || exit 1
29+
fi
30+
- name: Initialize README.md
31+
if: ${{ steps.commit-count.outcome == 'success' }}
32+
run: |
33+
[ -f README.tmpl.md ] || cp README.md README.tmpl.md
1834
printf '%s\n' "<!-- This file is generated from README.tmpl.md -->" > README.md
1935
cat README.tmpl.md >> README.md
2036
- name: CLOC
37+
if: ${{ steps.commit-count.outcome == 'success' }}
2138
uses: djdefi/cloc-action@6
2239
with:
2340
options: --md --report-file=cloc.md --hide-rate
2441
# Note: initial newline is required because files don't end with one
25-
- run: |
26-
printf '\n%s\n' '### Lines of code' >> README.md
42+
- name: Update README
43+
if: ${{ steps.commit-count.outcome == 'success' }}
44+
run: |
45+
printf '\n' >> README.md
46+
printf '%s\n' '### Lines of code' "<sup><sub>Generated at commit $(git rev-parse HEAD)</sub></sup>" >> README.md
2747
cat cloc.md >> README.md
2848
rm cloc.md
29-
- uses: stefanzweifel/git-auto-commit-action@v4
49+
- name: Commit README
50+
uses: stefanzweifel/git-auto-commit-action@v4
51+
if: ${{ steps.commit-count.outcome == 'success' }}
3052
with:
3153
commit_message: "chore: Generate README"
3254
# Note: README.tmpl.md is needed in the first case

0 commit comments

Comments
 (0)