-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use gen-readme from aarondill/github-actions
- Loading branch information
Showing
1 changed file
with
3 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,9 @@ | ||
name: Generate README | ||
on: | ||
push: | ||
pull_request: | ||
paths: | ||
- "README.md" # This isn't needed, but it's a good sanity check | ||
- "README.tmpl.md" | ||
pull_request: { paths: ["README.md", "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: docker://aldanial/cloc | ||
with: # Exclude YAML to avoid counting lock files | ||
args: ${{ github.sha }} --md --report-file=cloc.md --hide-rate --exclude-lang=YAML | ||
|
||
- name: output cloc.md | ||
if: ${{ steps.commit-count.outcome == 'success' }} | ||
run: cat cloc.md | ||
|
||
# Note: initial newline is required because git 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 ${{ github.sha }}</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 | ||
permissions: { contents: write } | ||
uses: aarondill/github-actions/.github/workflows/gen-readme.yml@main |