@@ -13,20 +13,42 @@ jobs:
13
13
contents : write
14
14
steps :
15
15
- 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
18
34
printf '%s\n' "<!-- This file is generated from README.tmpl.md -->" > README.md
19
35
cat README.tmpl.md >> README.md
20
36
- name : CLOC
37
+ if : ${{ steps.commit-count.outcome == 'success' }}
21
38
uses : djdefi/cloc-action@6
22
39
with :
23
40
options : --md --report-file=cloc.md --hide-rate
24
41
# 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
27
47
cat cloc.md >> README.md
28
48
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' }}
30
52
with :
31
53
commit_message : " chore: Generate README"
32
54
# Note: README.tmpl.md is needed in the first case
0 commit comments