-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (55 loc) · 2.13 KB
/
gen-readme.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
55
name: Generate README
on:
push:
pull_request:
paths:
- "README.md" # This isn't needed, but it's a good sanity check
- "README.tmpl.md"
workflow_dispatch:
jobs:
generate-readme:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@master
with: # We need to fetch enough commits to check if we've waited long enough
fetch-depth: 12
- name: Check if we've waited long enough (10+ commits)
id: commit-count
continue-on-error: true
run: |
[ '${{ github.event_name }}' != 'workflow_dispatch' ] || exit 0
last_sha=$(git log --oneline --format=format:%H --grep="^chore: Generate README$" -1)
echo "last_sha=$last_sha"
if [ -n "$last_sha" ]; then # success if last_sha is empty
count=$(git rev-list $last_sha..HEAD --count)
echo "count=$count"
[ $count -gt 10 ] || exit 1
fi
- name: Initialize README.md
if: ${{ steps.commit-count.outcome == 'success' }}
run: |
[ -f README.tmpl.md ] || cp README.md README.tmpl.md
printf '%s\n' "<!-- This file is generated from README.tmpl.md -->" > README.md
cat README.tmpl.md >> README.md
- name: CLOC
if: ${{ steps.commit-count.outcome == 'success' }}
uses: djdefi/cloc-action@6
with:
options: --md --report-file=cloc.md --hide-rate
# Note: initial newline is required because files don't end with one
- name: Update README
if: ${{ steps.commit-count.outcome == 'success' }}
run: |
printf '\n' >> README.md
printf '%s\n' '### Lines of code' "<sup><sub>Generated at commit $(git rev-parse HEAD)</sub></sup>" >> README.md
cat cloc.md >> README.md
rm cloc.md
- name: Commit README
uses: stefanzweifel/git-auto-commit-action@v4
if: ${{ steps.commit-count.outcome == 'success' }}
with:
commit_message: "chore: Generate README"
# Note: README.tmpl.md is needed in the first case
file_pattern: README.md README.tmpl.md