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 support for yaml config files #7031

Closed
matfax opened this issue Aug 19, 2020 · 24 comments
Closed

Add support for yaml config files #7031

matfax opened this issue Aug 19, 2020 · 24 comments
Labels
priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others status:requirements Full requirements are not yet known, so implementation should not be started type:feature Feature (new functionality)

Comments

@matfax
Copy link

matfax commented Aug 19, 2020

What would you like Renovate to be able to do?

JSON isn't considered the best choice for configuration files anymore. This blog post on lucidchart explains some of the reasons for it. Most services (e.g., GitHub actions) use YAML as the new standard. In my opinion, YAML support for configuration files would make a helpful addition to Renovate. The configuration would be more comprehensible and also easier to edit, especially when using GitHub's online edit feature.

Did you already have any implementation ideas?

Since yaml is a superset of json, the config file could be parsed using the yaml library, and then, equally processed as the json-derived config object.

Is this a feature you'd be interested in implementing yourself?

Depends on your feedback and the level of interest in this feature.

@matfax matfax changed the title Add support for yaml config file Add support for yaml config files Aug 19, 2020
@viceice viceice added type:feature Feature (new functionality) priority-4-low Low priority, unlikely to be done unless it becomes important to more people labels Aug 19, 2020
@viceice

This comment has been minimized.

@rarkins
Copy link
Collaborator

rarkins commented Aug 19, 2020

No, let's stick with JSON. We have a lot of config examples in our documentation and it would be painful to maintain both. In addition we have the JSON schema now which can be used for validation in IDEs. YAML is far from perfect too, and while the blog post may argue that JSON's strictness is a weakness, I think that YAML's lack of strictness can be equally problematic.

@rarkins rarkins closed this as completed Aug 19, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 15, 2020
@renovatebot renovatebot unlocked this conversation Jan 27, 2021
@rarkins rarkins reopened this Jan 27, 2021
@rarkins
Copy link
Collaborator

rarkins commented Jan 27, 2021

Reopening this for reconsideration.

We could support YAML config even if all our examples are JSON. People choosing to use YAML would need to accept that.

Ideally one day all JSON code snippets in our markdown docs could be processed to generate the equivalent in YAML and then display both in docs (switchable).

We also need to consider the impact of YAML on presets. We currently check for default.json and renovate.json, which already means some 404s. We wouldn't want more try/fail/try attempts. Maybe if they're YAML then the full filename with extension needs to be referenced.

@rarkins rarkins added priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others status:requirements Full requirements are not yet known, so implementation should not be started and removed priority-4-low Low priority, unlikely to be done unless it becomes important to more people labels Jan 27, 2021
@davidspek
Copy link

As I just discussed with @rarkins, I'd be willing to manually go through the docs to update them with YAML examples. People that would like to migrate from JSON to YAML can use yq to convert their file easily with yq eval -P sample.json > sample.yaml.

@rarkins
Copy link
Collaborator

rarkins commented Jan 27, 2021

What I was hoping for visually in our docs is something like this mockup (ignore the languages/example):

image

Ideally JSON would be our single source of truth - therefore not many docs need changing - but we can transform them on the way to HTML so that tabbed examples can be shown, similar to the above.

@davidspek
Copy link

Where did you get that example from? I've been trying to find just that so I can try and find how to create it online.

@rarkins
Copy link
Collaborator

rarkins commented Jan 27, 2021

I found it in a meta Stack Overflow post discussing adding the feature to SO. But better news - it seems like such tabs are supported by Docusaurus, which we were planning to switch to.

Exactly what we need: https://v2.docusaurus.io/docs/markdown-features/#multi-language-support-code-blocks

@davidspek
Copy link

That indeed looks like the perfect fit, what a coincidence.

@rarkins
Copy link
Collaborator

rarkins commented Jan 27, 2021

So, approximate steps:

  1. Migrate to docusaurus. Note: I'm starting to think it should remain in its own repo, because it will need to pull from multiple repos, not just this one.
  2. Use .mdx extension instead of .md. Not sure if a bulk rename simply works or if there's any downsides?
  3. Add post-processing for our markdown files to convert all ` json blocks into Docusaurus tabulated code blocks with a YAML equivalent (automatically generated)

This way users can keep writing simple markdown with JSON blocks as is today, but the docs published to docs.renovatebot.com have multi-language examples.

One more thing: need to think about the admin config (config.js, config.json) too.

@nejch
Copy link
Contributor

nejch commented Jun 27, 2021

@rarkins I would love to see support for yaml!

You don't even need to wait to migrate to docusaurus, as mkdocs supports this natively, so this shouldn't be a blocker to continue with the feature.

See renovatebot/renovatebot.github.io#65 for a quick implementation of a post-processor with mkdocs (it's a few lines of code really), and below a short demo:

renovate-yaml-2021-06-27_13.51.04.mp4

The caveat is that examples need to be valid json (so currently a few are skipped), I think this would be the case with any post-processor anyway.

@rarkins
Copy link
Collaborator

rarkins commented Jun 29, 2021

Wow, cool! I'd like all our examples to be fully valid JSON anyway, so would be happy to add further linting to try to ensure it.

I'm currently on vacation so struggling to keep up with the usual volume of issues and PRs. @viceice what do you think?

@viceice
Copy link
Member

viceice commented Jun 29, 2021

Sounds good. but before we add the docs we need to allow the yaml config files.

Ideas:

  1. We should force file ending for preset config files, so we don't need to more api requests to find files.
  2. Maybe the platform apis have some filters, so we can get all files starting with the filename /path prefix and then use the returned name and fetch contents. that way we need 2 api calls instead of one before and we don't need file extensions.

@nejch
Copy link
Contributor

nejch commented Jun 29, 2021

Re: filtering repo files, @viceice I'll just give you what I know for GitLab.

Sadly on gitlab the most useful endpoint (search repo blobs) is a premium feature: https://docs.gitlab.com/ee/api/search.html#scope-blobs

Second best, before actually looping over all possible filepaths, might be the repo tree endpoint:
https://docs.gitlab.com/ee/api/repositories.html#list-repository-tree

But again, if there are a lot of files in the repo that are returned before a renovate config file is found, the pagination might trigger more requests than just looping over ~10 files. This is better if you leave out recursive, but then you need a 2nd call to list files in the .gitlab/ directory as well (to support .gitlab/renovate.json).

So there would need to be a balance, maybe benchmark based on the average repo tree size. Just some thoughts on options :)

@rarkins
Copy link
Collaborator

rarkins commented Jun 29, 2021

I think if we cache the found config file name then it should be ok to have a small impact on the first run because it will be 0 impact indefinitely after that

@viceice
Copy link
Member

viceice commented Jun 29, 2021

What about preset filenames?

@rarkins
Copy link
Collaborator

rarkins commented Jun 29, 2021

Good point. For backwards compatibility, no extension means .json. For .yaml or .json5 the extension must be included

@nejch
Copy link
Contributor

nejch commented Jun 30, 2021

I think if we cache the found config file name then it should be ok to have a small impact on the first run because it will be 0 impact indefinitely after that

Is this something that's basically already done at least for per-repo config?

const cache = getCache();
let { configFileName } = cache;
if (configFileName) {
let configFileParsed = await platform.getJsonFile(configFileName);
if (configFileParsed) {
if (configFileName === 'package.json') {
configFileParsed = configFileParsed.renovate;
}
return { configFileName, configFileParsed };
}
logger.debug('Existing config file no longer exists');
}

@viceice
Copy link
Member

viceice commented Jun 30, 2021

Good point. For backwards compatibility, no extension means .json. For .yaml or .json5 the extension must be included

Can we cache the resolved preset file names? that way we can suppress extension for preset too. 🤔

@rarkins
Copy link
Collaborator

rarkins commented Jun 30, 2021

Depends whether you consider the current lack of file extensions a feature or a bug :)

Less a user needs to type the better. But then we should try to avoid ambiguity and confusion too.

BTW such caching could already be added today for the default.json/renovate.json check. Question is for how long? Eg 24 hours? Never, as long as the cached file name resolves?

@viceice
Copy link
Member

viceice commented Jun 30, 2021

My idea waas to cache those in the repo json cache file, where we already have the repo config filename.

I think we can cache the filenames as long as they resolve.

We should also prefer json over yaml, if a user has both available. Should be documented of cause.

@rarkins
Copy link
Collaborator

rarkins commented Jun 30, 2021

So if there are 100 repos referencing a particular preset then we'd "try/fail" that preset once per downstream repo but then cache it in each downstream repo after that?

Slightly inefficient but on the upside it resolves any concerns about caching private results

@JuliusHenke
Copy link
Contributor

JuliusHenke commented May 13, 2022

Are there any updates on plans to support renovate.yaml for the repo specific config? The self-hosted admin config already works great with YAML and I love using it. Adding renovate.yaml support would make it more consistent and easier to work with.
This was also proposed in: #10682

@Kurt-von-Laven
Copy link

JSON schemas work just as well with YAML as they do with JSON since the two languages are essentially different representations of the same underlying structure. VSCode users get autocomplete, documentation, etc. from schemas that have been added to JSONSchema for example.

In addition we have the JSON schema now which can be used for validation in IDEs.

@rarkins
Copy link
Collaborator

rarkins commented May 24, 2023

This topic came up again recently, so I will add a recent opinion: I don't want to support this unless a regular contributor to Renovate wants to add it and support it in the longer term. While one-off PRs are usually appreciated, in this case it would be like gifting a puppy - we'd be left behind to clean up after it and look after it all its life.

@rarkins rarkins closed this as not planned Won't fix, can't repro, duplicate, stale May 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others status:requirements Full requirements are not yet known, so implementation should not be started type:feature Feature (new functionality)
Projects
None yet
Development

No branches or pull requests

7 participants