-
Notifications
You must be signed in to change notification settings - Fork 43
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
Emit <!--Start PulumiCodeChooser -->
instead of {{% examples %}}
#1689
Conversation
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.
Looks great! Thanks for waddling through this and making the changes!
I had a few questions to help me understand the code and I think it'd be great if we can split up the new parsing logic into a few functions to make it easier to understand!
Also, do you think it'd make sense to add a few more regression tests? Maybe from some non-aws providers or some of the more visited docs pages?
Lastly, do the new HTML comments require a PR somewhere else before we can ship this?
// to reconvert them. But we need to surround them in the examples shortcode for rendering on the registry | ||
// to reconvert them. | ||
// | ||
//TODO: This only works if the incoming docs already have an {{% example }} shortcode, and if they are |
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.
Does this introduce a regression in this PR? Or is this a TODO for the future?
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 is not a regression. This is an issue where third party (and internal) docs writers are working with the current status quo and marking up their docs with shortcodes.
See here for an internal example.
The TODO here is to write code to handle expected legacy behavior on users' behalf, or ask them to migrate.
Currently, the registry will continue to accept old shortcode behavior, as many native providers expect to use them.
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.
Can you open an issue for this and link it with the TODO.
pkg/tfgen/docs.go
Outdated
inCodeBlock = false | ||
} | ||
} else { | ||
// Keep track of header locations. These should never be inside code blocks. |
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.
Should we add an error if this assumption is violated?
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.
What I was trying to say was "we never look for a header inside a code block" - describing behavior, not assumption.
The new code is a bit more clear - we never look for a header if we are inside a code block.
header, wroteHeader := section[0], false | ||
isFrontMatter, isExampleUsage := !strings.HasPrefix(header, "## "), header == "## Example Usage" | ||
// Now we know where the headers and code fences are. | ||
textStart := 0 |
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.
There's quite a few interactions and context one needs to keep when reading here, would this also make sense to be split into a few functions?
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 🙏
if output.Len() > 0 { | ||
fprintf(output, "\n") | ||
} else { | ||
// Take already-valid code blocks as-is. |
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.
Is this covered by a regression test?
Okay, I think you've opened pulumi/pulumi#15475 to parse the new HTML comments, great! |
@@ -25,5 +25,5 @@ | |||
"ips": "The set of IPs on the Address Map.", | |||
"memberships": "Zones and Accounts which will be assigned IPs on this Address Map." | |||
}, | |||
"Import": "## Import\n\n```sh\u003cbreak\u003e $ pulumi import MISSING_TOK example \u003caccount_id\u003e/\u003caddress_map_id\u003e \u003cbreak\u003e```\u003cbreak\u003e\u003cbreak\u003e" | |||
"Import": "## Import\n\n```sh\n$ pulumi import MISSING_TOK example \u003caccount_id\u003e/\u003caddress_map_id\u003e\n```\n\n" |
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.
Remaining issue with MISSING_TOK? Should that be an error instead?
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'm happy to file an issue here but it's out of scope for this change I think!
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.
lgtm
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.
LGTM
This pull request depends on corresponding changes in the pulumi-terraform bridge. The bridge will mark up each code section it finds (not just ones found under an "Example Usage" header) with an HTML comment - currently this will be `<!--Begin Code Chooser -->` and `<!--End Code Chooser -->` but the name is subject to change. In this PR, we are adding logic to detect if an incoming Description block has an `{{% examples }}` shortcode markup: if yes, we will process it as before. If no, we will switch to new functionality that relies on documentation with code sections having no short codes, no "Examples Section" logic, and will generate every code section it finds in an incoming schema that is in the Description/Content section of a registry page with a chooser and language choosables. This work is part of pulumi/pulumi-aws#2624. Edit: unit tests are added This PR is a prerequisite for pulumi/pulumi-terraform-bridge#1689. It aims to support both legacy and new behavior. <!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description <!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. --> Fixes # (issue) ## Checklist - [x] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [x] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [x] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
convertExamplesInner
convertExamplesInner
Is this blocked by #1699? From the description there it looks like we'd be regressing in some providers if we merge this. |
I don't know about 1699. |
I don't believe that it is blocked on #1699. |
Yup, I confirmed it with the docs team - #1699 is not a blocker but the bridge has yet to pick up pulumi/pulumi#15475 |
…re they are written in. Still needs: how have we been adding short codes to hand written docs?
…r the TF markdown with less nesting and fewer tracking variables. This also removes the need for <break> placeholders in the import section processing. However, every Description entry now ends with a double newline and I'm not yet sure why.
…now. At least it's consistent.
…ructs. Add tests. Rename some consts and vars. Remove need for writeTrailingNewline.
Test changes are due to HCL->PCL improvements. The do not effect the new code AFAIK.
8c29d7f
to
87f8e4f
Compare
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.
lgtm
convertExamplesInner
<!--Start PulumiCodeChooser -->
instead of {{% examples %}}
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1689 +/- ##
==========================================
- Coverage 59.75% 59.19% -0.56%
==========================================
Files 301 308 +7
Lines 42046 42471 +425
==========================================
+ Hits 25123 25141 +18
- Misses 15490 15903 +413
+ Partials 1433 1427 -6 ☔ View full report in Codecov by Sentry. |
IMPORTANT This cannot be merged until the bridge has updated pulumi/pulumi to a version that includes these changes.
After that, merging will be safe.
Note: pulumi/pulumi#15475 needs to be merged first for these changes to be safe.
This PR aims to remove the nested "Example Usage" logic from the bridge, as discussed here.
The issue this is aimed at fixing is pulumi/pulumi-aws#2624 but there should be a myriad of other issues that will be addressed by this change.
In a nutshell, this PR removes any
{{% example(s) }}
injection from theDescription
fields of a resource and instead detects any and all code conversions from TF/HCL --> pulumi languages, and surrounds them with an HTML comment.This is currently
Marking up any converted code blocks using the new format will serve only as a marker for registry docsgen to surround this converted code with a language chooser.
I refrained from going full Markdown parser because I believe it would be an even larger rewrite. Instead, we detect code fences in the docstring input, and append text and converted code section to the output, with the following caveats:
<break>
placeholders for the Import section.convertExamplesInner
: it is valid code and will be retained as suchexampleTitle
, and this change affects only the wording of logging output.isFrontMatter
variable was removed as well. To the best of my knowledge, Hugo front matter does not get piped through the bridge, and is generated by the registry instead.convertExamplesInner
, with an added caveat that both third party and our own docs may add the old example shortcodes. This change will allow us to remove some of these. Registry docsgen will continue to support the shortcode way of doing things, since native providers conform to that expectation separately.