Automated Documentation Generation - Studio-Lovelies/GG-JointJustice-Unity GitHub Wiki

Knowledge Requirements

This document is best read with a basic understanding of...

Overview

The full list of Actions is generated based on the C# code and code comments of the ActionDecoder class.

Regeneration

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:

  1. Compile and run the program located inside /docs_generator
  2. Compare the docs generated by this program to the existing docs of the repository
  3. If the generated docs differ from the current ones, Add a commit to the source branch of the Pull Request automatically

Making Changes to the Generator and Running it Locally

To make changes to the source code of the documentation generator...

  1. Install the latest .NET 8 SDK
  2. Make changes to the source code inside /docs_generator
  3. Compile the app
  4. Run the generated executable with /unity-ggjj set as current working directory
  5. All files inside /docs will be cleared and then re-generated

Implementation

The documentation generator works by utilizing the ability of C# to parse other C# code and operates as follows:

  1. Parses the file at Assets/Scripts/TextDecoder/ActionDecoder.cs inside the current working directory using SyntaxFactory.ParseCompilationUnit()
  2. Finds any method containing only A-Z (uppercase) and _
  3. The following information is extracted for each method:
    1. All comments (used to generate more information later on)
    2. The name of the method
    3. The list of parameters and their types (used to generate more information later on)
    4. 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)
  4. 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
  5. The <summary>, <param> and <example> xml documentation values are used for the documentation of that method
  6. Methods are grouped based on the value of the <category> xml documentation tag
  7. 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
  8. The constants document is generated containing all files matching the validFiles-attribute value for every parameter type

Why not directly update the Wiki?

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
⚠️ **GitHub.com Fallback** ⚠️