Skip to content

chore: update gen-readme workflow #18

chore: update gen-readme workflow

chore: update gen-readme workflow #18

Workflow file for this run

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