|
1 | 1 | name: Generate README |
2 | 2 | on: |
3 | 3 | push: |
4 | | - pull_request: |
5 | | - paths: |
6 | | - - "README.md" # This isn't needed, but it's a good sanity check |
7 | | - - "README.tmpl.md" |
| 4 | + pull_request: { paths: ["README.md", "README.tmpl.md"] } |
8 | 5 | workflow_dispatch: |
9 | 6 | jobs: |
10 | 7 | generate-readme: |
11 | | - runs-on: ubuntu-latest |
12 | | - permissions: |
13 | | - contents: write |
14 | | - steps: |
15 | | - - uses: actions/checkout@master |
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 |
34 | | - printf '%s\n' "<!-- This file is generated from README.tmpl.md -->" > README.md |
35 | | - cat README.tmpl.md >> README.md |
36 | | -
|
37 | | - - name: CLOC |
38 | | - if: ${{ steps.commit-count.outcome == 'success' }} |
39 | | - uses: docker://aldanial/cloc |
40 | | - with: # Exclude YAML to avoid counting lock files |
41 | | - args: ${{ github.sha }} --md --report-file=cloc.md --hide-rate --exclude-lang=YAML |
42 | | - |
43 | | - - name: output cloc.md |
44 | | - if: ${{ steps.commit-count.outcome == 'success' }} |
45 | | - run: cat cloc.md |
46 | | - |
47 | | - # Note: initial newline is required because git files don't end with one |
48 | | - - name: Update README |
49 | | - if: ${{ steps.commit-count.outcome == 'success' }} |
50 | | - run: | |
51 | | - printf '\n' >> README.md |
52 | | - printf '%s\n' '### Lines of code' "<sup><sub>Generated at commit ${{ github.sha }}</sub></sup>" >> README.md |
53 | | - cat cloc.md >> README.md |
54 | | - rm cloc.md |
55 | | - - name: Commit README |
56 | | - uses: stefanzweifel/git-auto-commit-action@v4 |
57 | | - if: ${{ steps.commit-count.outcome == 'success' }} |
58 | | - with: |
59 | | - commit_message: "chore: Generate README" |
60 | | - # Note: README.tmpl.md is needed in the first case |
61 | | - file_pattern: README.md README.tmpl.md |
| 8 | + permissions: { contents: write } |
| 9 | + uses: aarondill/github-actions/.github/workflows/gen-readme.yml@main |
0 commit comments