|
1 | | -# github-docs |
| 1 | +# github-docs |
| 2 | + |
| 3 | +github-docs is CLI application that automatically generates documentation for your GitHub actions & workflows. It was inspired by [terraform-docs](https://github.com/terraform-docs/terraform-docs). |
| 4 | + |
| 5 | +This was an Everpure Hackathon project by Andrei Gatea, Miroslav Brabenec & [Radek Sprta](https://github.com/radek-sprta). |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- render documentation in Markdown |
| 10 | +- print output to stdout or save into file |
| 11 | +- inject generated documentation into README.md, or completely replace it |
| 12 | +- run as [pre-commit hook](https://pre-commit.com/) |
| 13 | +- take one or more files or directories as input (directories are searched recursively) |
| 14 | +- shell completion |
| 15 | + |
| 16 | +## Requirements |
| 17 | +github-docs requires Python 3.11 or newer to run. |
| 18 | + |
| 19 | +## Installation |
| 20 | +You can build and install the package manually. The repository requires SSH |
| 21 | +certificate authentication, so the clone URL carries the organisation's SSH |
| 22 | +alias and HTTPS will not work: |
| 23 | + |
| 24 | +```sh |
| 25 | +git clone git@github.com:PureStorage-OpenConnect/github-docs.git |
| 26 | +cd github-docs |
| 27 | +uv build |
| 28 | +pip install --user dist/*.whl |
| 29 | +``` |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +For help, run `github-docs --help`. Here are some common patterns: |
| 34 | + |
| 35 | +**Print action docs to stdout** |
| 36 | + |
| 37 | +`github-docs action action.yml` |
| 38 | + |
| 39 | +**Inject actions docs to file** |
| 40 | + |
| 41 | +`github-docs action action.yml --output-file README.md` |
| 42 | + |
| 43 | +Docs will be injected between `<!-- BEGIN_GITHUB_DOCS_BLOCK -->` & `<!-- END_GITHUB_DOCS_BLOCK -->` markers in your file. If the file has neither marker, the block is appended to its end. |
| 44 | + |
| 45 | +**Replace file with workflow docs** |
| 46 | + |
| 47 | +`github-docs workflow .github/workflows --output-file README.md --mode replace` |
| 48 | + |
| 49 | +**Document several definitions at once** |
| 50 | + |
| 51 | +`github-docs action .github/actions --output-file README.md` |
| 52 | + |
| 53 | +You can pass any number of files and directories. `--output-file` is a |
| 54 | +**filename**, not a path — it is written beside each definition, in the |
| 55 | +directory its source file lives in. Definitions that share a directory share |
| 56 | +one document, so the command above writes one `README.md` per action |
| 57 | +directory under `.github/actions`, while pointing `workflow` at |
| 58 | +`.github/workflows` (where every reusable workflow lives flat in one |
| 59 | +directory) writes a single shared `README.md` there. With no `--output-file`, |
| 60 | +everything still concatenates to stdout, following the order the paths were |
| 61 | +given, with definitions inside a directory sorted by path. |
| 62 | + |
| 63 | +Directories are searched recursively, because the conventional layout puts each |
| 64 | +action in its own subdirectory (`.github/actions/<name>/action.yml`); a |
| 65 | +non-recursive search of `.github/actions` would find nothing. Overlapping |
| 66 | +arguments are de-duplicated, so passing both a directory and a file inside it |
| 67 | +documents that definition once. |
| 68 | + |
| 69 | + |
| 70 | +### Pre-commit hook |
| 71 | + |
| 72 | +To use the with the [pre-commit](https://pre-commit.com) framework, add the following to your `pre-commit-config.yaml`: |
| 73 | + |
| 74 | +The hook rewrites the output file beside each changed definition; pre-commit |
| 75 | +fails the commit when any file was modified by the hook. Re-stage the rewritten |
| 76 | +files and commit again. Your `args` choose the subcommand and the output |
| 77 | +filename. |
| 78 | + |
| 79 | +### Actions |
| 80 | +```yaml |
| 81 | +--- |
| 82 | +repos: |
| 83 | + - repo: git@github.com:PureStorage-OpenConnect/github-docs.git |
| 84 | + rev: pre-commit |
| 85 | + hooks: |
| 86 | + - id: github-docs |
| 87 | + args: [action, --output-file, README.md] |
| 88 | +``` |
| 89 | +
|
| 90 | +### Workflows |
| 91 | +```yaml |
| 92 | +--- |
| 93 | +repos: |
| 94 | + - repo: git@github.com:PureStorage-OpenConnect/github-docs.git |
| 95 | + rev: pre-commit |
| 96 | + hooks: |
| 97 | + - id: github-docs-workflow |
| 98 | +``` |
| 99 | +
|
| 100 | +The workflow hook documents every reusable workflow in `.github/workflows` |
| 101 | +whenever any of them changes, writing `README.md` there by default. Your |
| 102 | +`args` replace the default ones, so keep `--output-file` in them, e.g. |
| 103 | +`args: [--output-file, README.md, --mode, replace]`; without it the docs only |
| 104 | +go to stdout and no file is updated. |
| 105 | + |
| 106 | + |
| 107 | +### Contact |
| 108 | +[rsprta@everpuredata.com](mailto:rsprta@everpuredata.com) |
0 commit comments