Skip to content

Commit

Permalink
Fix: Fix updating version in src/version.js for pre releases
Browse files Browse the repository at this point in the history
Ensure that updating the version information in the optional
src/version.js file works for JS projects too.
  • Loading branch information
bjoernricks committed Mar 3, 2023
1 parent 3588b25 commit c4ae708
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
7 changes: 2 additions & 5 deletions pontos/version/javascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,8 @@ def _update_version_file(self, new_version: Version) -> bool:

content = GREENBONE_JS_VERSION_FILE.read_text(encoding="utf-8")
content = re.sub(
pattern=(
r'VERSION = (?P<quote>[\'"])[\d+\.]{2,3}'
r"{.dev[\d]}(?P=quote);"
),
repl=f"VERSION = {new_version};",
pattern=r'VERSION = "(?P<version>.*)";',
repl=f'VERSION = "{new_version}";',
string=content,
)
GREENBONE_JS_VERSION_FILE.write_text(content, encoding="utf-8")
Expand Down
34 changes: 34 additions & 0 deletions tests/version/test_javascript_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,40 @@ def test_update_version_file(self):

self.assertEqual(fake_package["version"], "22.4.0")

def test_update_js_version_file(self):
content = '{"name":"foo", "version":"1.2.3"}'
js_content = """const foo = "bar";
const VERSION = "1.2.3";
const func = () => ();
"""

with temp_directory(change_into=True) as temp_dir:
package_json = temp_dir / "package.json"
package_json.write_text(content, encoding="utf8")
js_version_file = temp_dir / GREENBONE_JS_VERSION_FILE
js_version_file.parent.mkdir()
js_version_file.write_text(js_content, encoding="utf8")

cmd = JavaScriptVersionCommand()
updated = cmd.update_version(Version("22.4.0"))

self.assertEqual(updated.previous, Version("1.2.3"))
self.assertEqual(updated.new, Version("22.4.0"))
self.assertEqual(
updated.changed_files, [package_json, GREENBONE_JS_VERSION_FILE]
)

with package_json.open(mode="r", encoding="utf-8") as fp:
fake_package = json.load(fp)

self.assertEqual(fake_package["version"], "22.4.0")

self.assertEqual(
js_version_file.read_text(encoding="utf8"),
'const foo = "bar";\nconst VERSION = "22.4.0";\n'
"const func = () => ();\n",
)

def test_update_version_develop(self):
content = '{"name":"foo", "version":"1.2.3"}'

Expand Down

0 comments on commit c4ae708

Please sign in to comment.