-
Notifications
You must be signed in to change notification settings - Fork 2
51 lines (47 loc) · 1.74 KB
/
README from docs.yaml
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
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 README.md
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