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

Generic JSON updater can't replace version in a string field #2244

Closed
0xdbe opened this issue Mar 15, 2024 · 1 comment · Fixed by #2253
Closed

Generic JSON updater can't replace version in a string field #2244

0xdbe opened this issue Mar 15, 2024 · 1 comment · Fixed by #2253
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@0xdbe
Copy link
Contributor

0xdbe commented Mar 15, 2024

Environment details

  • OS: Linux
  • Node.js version: 20.11
  • npm version: yarn 1
  • release-please version: 16.10.0 with release-please-action@v4

Steps to reproduce

  1. Create a shared preset for Renovate
{
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
  "extends": [
    "github>abc/foo:xyz/sub#1.2.3",
    "github>abc/bar:xyz/sub#1.2.3"
  ]
}
  1. Configure release please to update tags in preset file
{
  "release-type": "node",
  "packages": {
    ".": {
      "extra-files": [
        {
          "type": "json",
          "path": "presets/base.json",
          "jsonpath": "$.extends[*]"
        }
      ]
    }
  }
}

Result

Release Please overrides the content of each line:

{
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
  "extends": [
    "1.2.4",
    "1.2.4"
  ]
}

Expected Result

Release Please should replace version in each line:

{
  "$schema": "https://docs.renovatebot.com/renovate-schema.json",
  "extends": [
    "github>abc/foo:xyz/sub#1.2.4",
    "github>abc/bar:xyz/sub#1.2.4"
  ]
}

Fix

in generic-json.ts, the function return only version number:

const nodes = jp.apply(data, this.jsonpath, _val => {
      return this.version.toString();
 });

In order to replace version in a sting:

const VERSION_REGEX =
  /(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(-(?<preRelease>[\w.]+))?(\+(?<build>[-\w.]+))?/;
const nodes = jp.apply(data, this.jsonpath, (value) => {
     value.replace(VERSION_REGEX, this.version.toString())
});

Note: VERSION_REGEX comes from Generic Updater

This is the same issue as 2205, but it was for YAML. A workaround was found by using the Generic Updater. However, it is not possible for JSON files because comments are not supported in this file format.

@0xdbe 0xdbe added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Mar 15, 2024
@0xdbe
Copy link
Contributor Author

0xdbe commented Mar 26, 2024

any feedback on this issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@chingor13 @0xdbe and others