Skip to content
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

Add option to filter edit rules by location in docs conversion pipeline and apply for installation docs #2435

Merged
merged 10 commits into from
Oct 2, 2024

Conversation

guineveresaenger
Copy link
Contributor

@guineveresaenger guineveresaenger commented Sep 20, 2024

This code is required to successfully apply the edit rules needed for pulumi/pulumi-libvirt#426.

It covers the case for when the upstream file's code sections need to be adjusted for code conversion to work.

It adds a complete index file test which tests the entire plainDocsParser function.
In support of https://github.com/pulumi/home/issues/3598.

  • Run provider-supplied edit rules before example conversion. Add complete file tests, with and without provider-supplied edits
  • clean up tests

Add complete file tests, with and without provider-supplied edits
@guineveresaenger guineveresaenger requested a review from a team September 20, 2024 18:42
Copy link

codecov bot commented Sep 20, 2024

Codecov Report

Attention: Patch coverage is 84.90566% with 8 lines in your changes missing coverage. Please review.

Project coverage is 57.12%. Comparing base (1cb7594) to head (cdf7074).
Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
pkg/tfgen/installation_docs.go 50.00% 7 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2435      +/-   ##
==========================================
- Coverage   57.43%   57.12%   -0.31%     
==========================================
  Files         369      370       +1     
  Lines       50209    51030     +821     
==========================================
+ Hits        28836    29152     +316     
- Misses      19795    20289     +494     
- Partials     1578     1589      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@guineveresaenger guineveresaenger force-pushed the guin/run-provider-edits-first branch from 507aa1b to c55ae3c Compare September 21, 2024 00:36
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When edit rules are applied is important. Can we add a note to info.DocsEdit that tells the user "your edit will be applied before any other edits"?

I think the change is OK as is, but it also feels like this makes edit rules application even more complicated and special for installation docs.

We can merge as is if we really need to, but I'd love if we took the opportunity to re-unify behavior for edit rules. For that, see 👇.


Instead of making bridge supplied edit rules special, I propose that we:

  1. Add a field to info.DocsEdit to control where the edit rule is applied. Initially, I would suggest an enum with: EditPreTranslation (the zero value, since this is what we do for normal pages) and EditPostTranslation.
  2. Edit apply to also take a phase (pre or post) and then filter edit rules applied.
  3. Move the existing "special" edit rules for installation docs into defaultEditRules (in edit_rules.go), specifying EditPostTranslation as needed.

pkg/tfgen/installation_docs.go Outdated Show resolved Hide resolved
pkg/tfgen/installation_docs.go Outdated Show resolved Hide resolved
pkg/tfgen/installation_docs.go Outdated Show resolved Hide resolved
pkg/tfgen/installation_docs.go Outdated Show resolved Hide resolved
@guineveresaenger
Copy link
Contributor Author

Hmm, I like this idea, and I think that edit rules should be applied mostly after code conversion. The main case for applying them pre-conversion is to fix any mistakes in the provided code, as was discovered here. Having both options would not only allow us to fix incorrect TF code and make it convertable (convertible? 🚗 ), but also give us far more freedom in translating "Terraform" strings for "Pulumi" ones.

Refactor tests to run directly on editRules.apply.

Make removeTfVersionMentions and skipSectionHeadersEdit match any path, as we'll specify the index file when calling g.editRules.apply
@guineveresaenger guineveresaenger changed the title Run provider-supplied edit rules before example code conversion Add option to filter edit rules by location in docs conversion pipeline and apply for installation docs Sep 30, 2024
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some comment nits, but otherwise LGTM

pkg/tfbridge/info/info.go Show resolved Hide resolved
pkg/tfbridge/info/info.go Outdated Show resolved Hide resolved
pkg/tfgen/edit_rules.go Show resolved Hide resolved
@guineveresaenger guineveresaenger enabled auto-merge (squash) October 1, 2024 21:06
@guineveresaenger guineveresaenger merged commit 413a578 into master Oct 2, 2024
17 checks passed
@guineveresaenger guineveresaenger deleted the guin/run-provider-edits-first branch October 2, 2024 17:32
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v3.92.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants