Generate README with GH Actions #13
Workflow file for this run
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
name: Generate README | |
on: | |
pull_request: | |
paths: | |
- "docs/**/*" | |
workflow_run: | |
workflows: | |
- "generate_help_docs" | |
jobs: | |
make-README: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Fill template | |
working-directory: "docs/" | |
timeout-minutes: 0.1 | |
run: | | |
sub_doc_parts_from() { | |
template="$1" | |
directory="$2" | |
for file in "$directory"/*; do | |
if [ -f "$file" ]; then | |
placeholder="{{ $(echo "${file^^}" | tr ./ _) }}" | |
echo "Saving $file to $placeholder with expanded environment variables" >&2 | |
# Export file contents to text following a pattern in template.md, e.g.: | |
# section/test_file.md would replace "{{ SECTION_TEST_FILE_MD }}"" | |
template="${template//"$placeholder"/"$(<"$file")"}" | |
fi | |
done | |
echo "$template" | |
} | |
sub_doc_parts_from "$(sub_doc_parts_from "$(<template.md)" "sections")" "help">../README.md | |
- name: Setup git | |
run: | | |
git config --local user.name "github-actions[bot]" | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git remote set-url origin https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} | |
- name: Push | |
run: | | |
git add docs/help/* | |
if git update-index --refresh && git diff-index --quiet HEAD --; then | |
git commit -m "Automated update of README.md from docs" | |
branch_name="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" | |
git push origin HEAD:$branch_name | |
fi |