Skip to content

Commit 16c96f2

Browse files
authored
[experimental] generate wiki docs from action/workflow YAML (#21)
* add some ansible to generate MD from actions/workflows * overridable workflow/action output dirs * workflow to generate and push wiki docs * add pr trigger for testing * remove workflow_dispatch * fix wiki path use * add a .gitignore * fix wiki path * typo * testings * fix path ending * removed PR testing stuff
1 parent c222145 commit 16c96f2

File tree

11 files changed

+215
-0
lines changed

11 files changed

+215
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
name: Generate Wiki Docs
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- .github/workflows/_shared*
8+
- .github/workflows/generate-wiki-docs.yml
9+
- actions/**/action.yml
10+
11+
jobs:
12+
generate:
13+
env:
14+
# this path is going to be used with rsync, it MUST end in a forward slash [/]
15+
WIKI: ${{ github.workspace }}/wiki/
16+
ANSIBLE_COLLECTIONS_PATHS: ${{ github.workspace }}/.internal/ansible
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
21+
- name: Checkout wiki
22+
uses: actions/checkout@v2
23+
with:
24+
repository: ${{ github.repository }}.wiki
25+
path: ${{ env.WIKI }}
26+
27+
- uses: actions/setup-python@v2
28+
with:
29+
python-version: '3.9'
30+
31+
- name: Install Ansible
32+
run: pip install 'ansible-core>=2.12,<2.13' --disable-pip-version-check
33+
34+
- name: Generate new docs
35+
run: >-
36+
ansible-playbook
37+
internal.gha_docs.generate_docs
38+
-e "action_output_dir=$WIKI/actions"
39+
-e "workflow_output_dir=$WIKI/workflows"
40+
41+
- name: Publish docs
42+
# @v2 https://github.com/Andrew-Chen-Wang/github-wiki-action/releases/tag/v2
43+
uses: Andrew-Chen-Wang/github-wiki-action@b386aca0ddc5ec22b6003ba4cb50fa0b17243f6c
44+
env: # this action is written such that the inputs must be specified as env vars
45+
WIKI_DIR: ${{ env.WIKI }}
46+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
GH_MAIL: ${{ github.event.head_commit.author.email }}
48+
GH_NAME: ${{ github.event.head_commit.author.name }}[bot]
49+
WIKI_PUSH_MESSAGE: 'Docs for ${{ github.repository }}/${{ github.event.head_commit.id }} : ${{ github.event.head_commit.message }}'

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.vscode
2+
.test/simple-build/build
3+
wiki/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## `internal.gha_docs`
2+
3+
An internal collection for generating markdown docs from the actions and shared workflows in this repo.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
namespace: internal
3+
name: gha_docs
4+
description: A collection internal to this repository for generating documentation from GHA content.
5+
version: 0.1.0
6+
readme: README.md
7+
authors:
8+
- Brian Scholer (@briantist)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
requires_ansible: '>=2.11,<2.13'
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
- hosts: localhost
3+
gather_facts: false
4+
vars:
5+
# <root>/.internal/ansible/ansible_collections/internal/gha_docs/playbooks
6+
# ^6 ^5 ^4 ^3 ^2 ^1 ^ playbook_dir
7+
repo_root: >-
8+
{{
9+
playbook_dir
10+
| dirname
11+
| dirname
12+
| dirname
13+
| dirname
14+
| dirname
15+
| dirname
16+
}}
17+
actions_root: '{{ repo_root }}/actions'
18+
workflows_root: '{{ repo_root }}/.github/workflows'
19+
output_root: '{{ role_path }}/files/output'
20+
action_output_dir: '{{ output_root }}'
21+
workflow_output_dir: '{{ output_root }}'
22+
tasks:
23+
- name: Find actions
24+
ansible.builtin.find:
25+
paths: '{{ actions_root }}'
26+
recurse: true
27+
patterns: action.yml
28+
register: actions
29+
30+
- name: Generate actions docs
31+
ansible.builtin.include_role:
32+
name: internal.gha_docs.generate
33+
vars:
34+
type: action
35+
file: '{{ item.path }}'
36+
output: '{{ action_output_dir }}/action_{{ item.path | dirname | basename }}.md'
37+
loop: '{{ actions.files }}'
38+
39+
- name: Generate workflow docs
40+
ansible.builtin.include_role:
41+
name: internal.gha_docs.generate
42+
vars:
43+
type: workflow
44+
file: '{{ item }}'
45+
output: '{{ workflow_output_dir }}/workflow{{ item | basename | splitext | first }}.md'
46+
with_fileglob: '{{ workflows_root }}/_shared-*.yml'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**
2+
!.gitignore
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
argument_specs:
3+
main:
4+
options:
5+
file:
6+
type: path
7+
required: true
8+
description: The path to the action or workflow file to parse.
9+
10+
type:
11+
type: str
12+
required: true
13+
description: The type of input file.
14+
choices:
15+
- action
16+
- workflow
17+
18+
output:
19+
type: path
20+
required: true
21+
description: The path to the output file.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
- name: Load the file
3+
set_fact:
4+
_src: "{{ lookup('ansible.builtin.file', file) | from_yaml }}"
5+
6+
- name: Template the workflow docs
7+
when: type == 'workflow'
8+
vars:
9+
full: '{{ _src }}'
10+
name: '{{ _src.name }}'
11+
reference: '{{ file | basename }}'
12+
jobs: '{{ _src.jobs }}'
13+
inputs: '{{ _src[true].workflow_call.inputs | default({}) }}'
14+
outputs: '{{ _src[true].workflow_call.outputs | default({}) }}'
15+
ansible.builtin.template:
16+
src: workflow.md.j2
17+
dest: '{{ output }}'
18+
force: true
19+
mode: '644'
20+
21+
- name: Template the action docs
22+
when: type == 'action'
23+
vars:
24+
full: '{{ _src }}'
25+
name: '{{ _src.name }}'
26+
reference: '{{ file | dirname | basename }}'
27+
description: '{{ _src.description }}'
28+
inputs: '{{ _src.inputs | default({}) }}'
29+
outputs: '{{ _src.outputs | default({}) }}'
30+
ansible.builtin.template:
31+
src: action.md.j2
32+
dest: '{{ output }}'
33+
force: true
34+
mode: '644'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# `{{ reference }}`
2+
## {{ name }}
3+
4+
{{ description }}
5+
6+
### Inputs
7+
| Name (✅required) | Default | Description |
8+
| ----------------- | ------- | ----------- |
9+
{% for name, inp in inputs.items() %}
10+
| `{{ name }}`{% if inp.required %}{% endif %} | {% if inp.default is defined %}{% if "\n" in inp.default %}✳ _see `action.yml` for full default value_{% else %}<code>{{ inp.default.replace('`', '\`') }}</code>{% endif %}{% endif %} | {{ (inp.description.replace("\n", '<br />')) }} |
11+
{% endfor %}
12+
13+
<hr />
14+
15+
### Outputs
16+
| Name | Description |
17+
| ---- | ----------- |
18+
{% for name, out in outputs.items() %}
19+
| `{{ name }}` | {{ (out.description | default('')).replace("\n", '<br />') }} |
20+
{% endfor %}

0 commit comments

Comments
 (0)