-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new: Add generated documentation website #639
base: dev
Are you sure you want to change the base?
Conversation
a28e46a
to
9bb4769
Compare
45fb447
to
c4da9d4
Compare
baf5659
to
8f1cd4f
Compare
|
||
return self._handle_list_items(list_items, parsed) | ||
|
||
def build_parser( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split this into multiple functions so we can extract the generated usage text for use in the docs
relevant_lines = None | ||
|
||
for i, line in enumerate(target_lines): | ||
def __simplify(sentence: str) -> Optional[str]: | ||
# Edge case for descriptions starting with a note | ||
if line.lower().startswith("__note__"): | ||
continue | ||
if sentence.lower().startswith("__note__"): | ||
return None | ||
|
||
sentence = strip_techdocs_prefixes(sentence) | ||
|
||
relevant_lines = target_lines[i:] | ||
break | ||
# Check that the sentence still has content after stripping prefixes | ||
if len(sentence) < 2: | ||
return None | ||
|
||
if relevant_lines is None: | ||
return sentence + "." | ||
|
||
# Find the first relevant sentence | ||
result = next( | ||
simplified | ||
for simplified in iter( | ||
__simplify(sentence) | ||
for sentence in REGEX_SENTENCE_DELIMITER.split(description) | ||
) | ||
if simplified is not None | ||
) | ||
|
||
if result is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I overhauled the logic in this function to account for some new cases I ran into
result_no_links, links = extract_markdown_links(result) | ||
|
||
if len(links) > 0: | ||
description += f" See: {'; '.join(links)}" | ||
result_no_links += f" See: {'; '.join(links)}" | ||
|
||
return unescape(markdown_to_rich_markup(description)), unescape(description) | ||
return unescape(markdown_to_rich_markup(result_no_links)), unescape(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was updated to store one mostly unchanged version and one fully formatted version of the description, giving us more flexibility in the docs
@@ -40,7 +41,7 @@ def __init__(self, version, base_url, skip_config=False): | |||
self.config = CLIConfig(self.base_url, skip_config=skip_config) | |||
self.load_baked() | |||
|
|||
def bake(self, spec): | |||
def bake(self, spec: Dict[str, Any], file: Optional[IO[bytes]] = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes allow us to construct a mock CLI from a custom spec in unit tests
T = TypeVar("T") | ||
|
||
|
||
def sorted_actions_smart( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't live with the rest of the util functions because it can also be used in the command --help pages
📝 Description
This pull request implements a new generated documentation site that is automatically pushed to GitHub Pages.
The below preview URLs can be preview the documentation site in your browser:
Rendering
This PR uses Sphinx with the Read the Docs theme to render documentation. The Sphinx configuration and all relevant static files are stored under the
docs
directory.Command Documentation Generation
Due to the complexity and abundance of CLI commands, the logic to generate documentation pages for CLI commands is located in the
linodecli/documentation
directory.The
linodecli/documentation/templates
directory contains various Jinja2 templates which are dynamically rendered using the structures defined inlinodecli/documentation/template_data.py
.CLI documentation pages are rendered to a user-defined directory when
linode-cli generate-docs
is called. This is an indirect dependency of themake generate-docs
target, which will automatically render the command documentation into thedocs/_generated
directory before executing any Sphinx commands.Publishing
To automatically publish the documentation to a publicly available URL, this PR adds a new documentation.yml GitHub Actions workflow file.
This workflow has three jobs:
Build the documentation and upload it as an artifact
Pull down the built docs from the first step and commit them to the
_documentation
branchmain
,dev
)_documentation
branch automatically be created if it does not already exist.Pull down the built docs from the first step and upload them as a release asset.
The Documentation Branch
This PR uses a dedicated documentation branch because it allows us to make multiple versions of the documentation available at at time. Additionally, this allows us to manually rebase any sensitive/unwanted documentation details.
This branch stores all relevant versions as subdirectories, with the
latest
directory andindex.html
files being updated on-demand by job #2 (mentioned above).✔️ Testing
The following test steps assume you have pulled down this PR locally and run
make install
.Unit Testing
Documentation Rendering
generate-docs
target:Ensure the documentation generates successfully.
Open the documentation index in your browser:
Publishing
new/doc-generation
branch on your fork containing the changes from this PR:Build
andCommit to Pages Branch
jobs under theBuild Documentation
workflow run successfully under your fork.Deploy from a branch
, the target branch to the_documentation
branch, and the path to/ (root)
.MYGHUSERNAME.github.io/linode-cli/new/doc-generation
.new/doc-generation
branch.new/doc-generation
branch with the formatvX.X.X
.MYGHUSERNAME.github.io/linode-cli/latest
.📷 Preview
Configuration Page