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

💡 [IMPROVEMENT] - Single source of truth for the version string #219

Open
xuoe opened this issue Nov 22, 2023 · 2 comments
Open

💡 [IMPROVEMENT] - Single source of truth for the version string #219

xuoe opened this issue Nov 22, 2023 · 2 comments

Comments

@xuoe
Copy link
Contributor

xuoe commented Nov 22, 2023

Summary

I imagine these are difficult to keep in sync (note alpha2 vs. alpha5):

> rg --no-ignore '1.6.0.+alpha'
[...]
opentofu-repo/version/VERSION
1:1.6.0-alpha5

opentofu-repo/website/docs/intro/install/portable-install.sh
3:TOFU_VERSION="1.6.0-alpha2"

opentofu-repo/website/docs/intro/install/portable-install.ps1
1:$TOFU_VERSION="1.6.0-alpha2"

It would be great if opentofu-repo/version/VERSION could be used to populate those other files.

Basic Example

I've been working on an interpolation Docusaurus plugin that could achieve this by specifying a config object such as:

{
  TOFU_VERSION: async () => {
    const path = require('path').join('opentofu-repo', 'version', 'VERSION');
    const version = await require('fs/promises').readFile(path, { encoding: 'utf8' });
    return version.trim();
  }
  // Other variables...
}

With that in place, replacing 1.6.0-alpha2 with %TOFU_VERSION% in the lagging files outputs the correct version string.

It also makes it available in the global namespace under the variable name TOFU_VERSION.

Drawbacks

One downside is that those particular files are included as raw files, without webpack/Docusaurus really touching them. Currently, they're included via raw-loader imports, which is a great way of declaring raw files where they're needed instead of specifying a whitelist in some config. However, this approach doesn't allow other plugins to hook into the processing of the imported files.

To add to that, raw-loader is officially deprecated in favor of Asset Modules (asset/source, specifically). Instead of using !!raw-loader!./file, the webpack docs recommend appending a ?raw query string to indicate that a file is to be included in raw form. This opens the door for injecting other logic in the processing of raw files, like injecting a version string. 😉

All in all, it can be done, though the solution is a bit too webpacky. That said, it does allow for site-wide interpolation for any sort of value, not just a computed version string.

Unresolved questions

If there's interest, I will open a PR.

@ghost
Copy link

ghost commented Nov 23, 2023

Hey @xuoe, this is a great suggestion! However, regarding the install script, if we parse variables in them, that will interfere with the script language (bash/powershell) itself and make the scripts untestable in their raw form.

@xuoe
Copy link
Contributor Author

xuoe commented Nov 26, 2023

@janosdebugs, I see. I hadn't thought of that.

In any event, I'll tag you here when I publish the plugin, just in case. Feel free to close the issue if you wish.

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

1 participant