Skip to content

Commit 3e41eac

Browse files
committed
use git version if no npm version is defined in package/publish scripts
1 parent f4f72e9 commit 3e41eac

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

scripts/package.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import os
12
from pathlib import Path
23
from subprocess import run
34

45
from git.repo import Repo
56
from semantic_version import Version
67

78

8-
def get_current_version(repo: Repo) -> Version:
9+
def get_current_version_from_git() -> Version:
10+
repo = Repo(Path.cwd())
11+
912
result = None
1013
for tag in repo.tags:
1114
v = tag.name
@@ -30,9 +33,11 @@ def main() -> None:
3033
if not dist_path.exists():
3134
dist_path.mkdir()
3235

33-
repo = Repo(Path.cwd())
36+
if "npm_package_version" in os.environ:
37+
current_version = Version(os.environ["npm_package_version"])
38+
else:
39+
current_version = get_current_version_from_git()
3440

35-
current_version = get_current_version(repo)
3641
pre_release = current_version.minor % 2 != 0
3742

3843
run(

scripts/publish.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
from semantic_version import Version
77

88

9-
def get_current_version(repo: Repo) -> Version:
9+
def get_current_version_from_git() -> Version:
10+
repo = Repo(Path.cwd())
11+
1012
result = None
1113
for tag in repo.tags:
1214
v = tag.name
@@ -32,9 +34,10 @@ def main() -> None:
3234
if not dist_path.exists():
3335
raise FileNotFoundError(f"dist folder '{dist_path}' not exists")
3436

35-
repo = Repo(Path.cwd())
36-
37-
current_version = get_current_version(repo)
37+
if "npm_package_version" in os.environ:
38+
current_version = Version(os.environ["npm_package_version"])
39+
else:
40+
current_version = get_current_version_from_git()
3841

3942
vsix_path = Path(dist_path, f"robotcode-{current_version}.vsix")
4043

scripts/update_versions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ def replace_in_file(filename: Path, pattern: "re.Pattern[str]", to: str) -> None
1111

1212

1313
def main() -> None:
14-
# version = Version(os.environ["npm_package_version"])
15-
version = Version("0.7.1")
14+
version = Version(os.environ["npm_package_version"])
15+
1616
preview = version.minor % 2 != 0
1717

1818
for f in ["robotcode/_version.py", "pyproject.toml"]:

0 commit comments

Comments
 (0)