Skip to content

Commit 9520086

Browse files
committed
Fix version bump command and improve regex pattern matching to ensure correct and accurate execution
1 parent 0125f5b commit 9520086

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

.github/workflows/cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ jobs:
205205
206206
- name: Bump version
207207
id: bump-version
208-
run: uv run bump-version --verbose=true version=${VERSION}
208+
run: uv run bump-version --verbose=true ${VERSION}
209209

210210
- name: Update Git Version
211211
id: update-git-version

src/utils/bump_version.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import tomllib
3131
from pathlib import Path
3232
from typing import Any
33-
from warnings import warn
3433

3534
# ## Local First Party Imports ----
3635
from toolbox_python.dictionaries import DotDict
@@ -98,30 +97,32 @@ def update_files(files: list[DotDict]) -> None:
9897
### Extract variables ----
9998
filepath = Path(file.file)
10099
pattern: str = file.pattern
101-
search_pattern: str = pattern.replace("{VERSION}", ".*?")
100+
search_pattern: str = "^" + pattern.replace("{VERSION}", ".*?")
102101

103102
### Check ----
104103
if args.verbose:
105104
print(f"- {file.file}")
106105

107106
### Check if the file exists ----
108107
if not filepath.exists():
109-
warn(f"-- File does not exist: {file.file}")
108+
print(f"-- File does not exist: {file.file}")
110109
continue
111110

112111
### Read the file ----
113112
content: str = filepath.read_text()
114113

115114
### Check if the pattern exists in the file ----
116-
if not re.search(search_pattern, content):
117-
warn(f"-- Pattern not found in file: {file.pattern}")
115+
if not re.search(pattern=search_pattern, string=content, flags=re.MULTILINE):
116+
print(f"-- !! Pattern not found in file: {file.pattern}")
118117
continue
119118

120119
new_content: list[str] = []
121120
for line in content.splitlines():
122-
if re.search(search_pattern, line):
121+
if re.search(pattern=search_pattern, string=line, flags=re.MULTILINE):
123122
new_line: str = re.sub(
124-
search_pattern, pattern.replace("{VERSION}", args.version), line
123+
pattern=search_pattern,
124+
repl=pattern.replace("{VERSION}", args.version),
125+
string=line,
125126
)
126127
new_content.append(new_line)
127128
if args.verbose:

0 commit comments

Comments
 (0)