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

Is it even possible to template your dependencies yaml file? #355

Open
grepwood opened this issue Jul 13, 2023 · 1 comment
Open

Is it even possible to template your dependencies yaml file? #355

grepwood opened this issue Jul 13, 2023 · 1 comment

Comments

@grepwood
Copy link

Hi,

I have a file that starts like so:

options:
  buildHeader: [ "load(\"@io_bazel_rules_scala//scala:scala_import.bzl\", \"scala_import\")" ]
  languages: [ "java", "scala:2.12.10" ]

The project in question is a gargantuan monorepo. Therefore it stands to reason that I would like to change the Scala version in one place and see the change affect literally everything, to save myself work.

I have made the following changes:

  1. Add a file in my root directory called "scala_version.bzl" that contains SCALA_VERSION = "2.12.10"
  2. I have modified my dependencies yaml like this:
options:
  buildHeader: [ "load(\"@io_bazel_rules_scala//scala:scala_import.bzl\", \"scala_import\")" , "load(\"//:scala_version\", \"SCALA_VERSION\")" ]
  languages: [ "java", "scala:" + SCALA_VERSION ]

This is where the cookie crumbles - I have no idea how to template this file. I tried:

  • "scala:" + SCALA_VERSION
  • "scala:${SCALA_VERSION}"
  • "scala:{SCALA_VERSION}"
  • at this point I changed SCALA_VERSION to "scala:2.12.10" and tried "{{SCALA_VERSION}}" because that's a standard in YAML format

Unfortunately, none of those worked. Can someone help please?

@johnynek
Copy link
Collaborator

this code uses snakeyaml to parse the yaml.

you can see the extent of the Yaml interop here:

new ObjectMapper(new YAMLFactory()).registerModule(CirceJsonModule)

I have never used yaml templating like this. It is possible snakeyaml requires some configurations to work with jackson to support templates.

I am willing to review code with tests to add support, but I will not have time to add support or debug this myself.

I would recommend you use another tool to convert templated yaml into the version you pass to this tool if you don't want to dig into snakeyaml.

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

No branches or pull requests

2 participants