Automated Documentation Generation - Studio-Lovelies/GG-JointJustice-Unity GitHub Wiki
This document is best read with a basic understanding of...
- object-oriented programming-specific concepts like statically- vs. dynamically-typed languages
- C# and language-specific features like LINQ, Reflection and Assemblies
- Unity-specific concepts like ScriptableObjects, the Unity Input System and Unity Test Runner
- GitHub Actions
The full list of Actions is generated based on the C# code and code comments of the ActionDecoder class.
The documentation is automatically regenerated for every relevant code change.
For this to work, this GitHub Action is ran every time a PR is created or updated, executing the following logic:
- Compile and run the program located inside
/docs_generator
- Compare the docs generated by this program to the existing docs of the repository
- If the generated docs differ from the current ones, Add a commit to the source branch of the Pull Request automatically
To make changes to the source code of the documentation generator...
- Install the latest .NET 8 SDK
- Make changes to the source code inside
/docs_generator
- Compile the app
- Run the generated executable with
/unity-ggjj
set as current working directory - All files inside
/docs
will be cleared and then re-generated
The documentation generator works by utilizing the ability of C# to parse other C# code and operates as follows:
- Parses the file at
Assets/Scripts/TextDecoder/ActionDecoder.cs
inside the current working directory usingSyntaxFactory.ParseCompilationUnit()
- Finds any method containing only
A-Z
(uppercase) and_
- The following information is extracted for each method:
- All comments (used to generate more information later on)
- The name of the method
- The list of parameters and their types (used to generate more information later on)
- Whether or not
OnActionDone?.Invoke()
is called directly (and NOT inside another method) inside that method body (if so, this marks the method as instant)
- For each parameter of a given method, if its corresponding comment contains a
validFiles
-attribute, every file matching that qualifier is added to the constants document for this parameter type - The
<summary>
,<param>
and<example>
xml documentation values are used for the documentation of that method - Methods are grouped based on the value of the
<category>
xml documentation tag - For each created group a
.md
-file is created using the value as file name and generated documentation for all methods of that category as file content - The constants document is generated containing all files matching the
validFiles
-attribute value for every parameter type
As outlined above, the documents generated on pull request creation or update, are stored inside a subdirectory of our main repository.
While the underlying Wiki
-tab of GitHub repositories is actually just another Git repository (https://github.com/Studio-Lovelies/GG-JointJustice-Unity.wiki.git), the Wiki
-tab does not support branches.
Having the docs instead be pushed to the .wiki
repository would introduce two limitations:
- potential changes to documentation as a result of changes to the
ActionDecoder
inside a branch, would not be visible inside the Pull Request -
EITHER...
- the changes would not become visible until the branch is merged OR...
- the changes would already be applied before a pull request is merged, resulting in out-of-date documentation