Skip to content

Commit 7a08471

Browse files
ArBridgemantomuben
andauthored
Refactoring/399 ensure all ptb versions updated (#400)
* Fix typos in workflow.py docstring * Bump PTB to version 1.0.0, as missed in many updates * Modify `release:prepare` to update `.github/actions` with new PTB version * Skip changelog step if on main Co-authored-by: Thomas Ubensee <34603111+tomuben@users.noreply.github.com> --------- Co-authored-by: Thomas Ubensee <34603111+tomuben@users.noreply.github.com>
1 parent 9d6891b commit 7a08471

File tree

9 files changed

+111
-84
lines changed

9 files changed

+111
-84
lines changed

.github/actions/security-issues/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ runs:
3939
- name: Install Python Toolbox / Security tool
4040
shell: bash
4141
run: |
42-
pip install exasol-toolbox==0.8.0
42+
pip install exasol-toolbox==1.0.0
4343
4444
- name: Create Security Issue Report
4545
shell: bash

.github/workflows/checks.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,16 @@ jobs:
4040
Changelog:
4141
name: Changelog Update Check
4242
runs-on: ubuntu-24.04
43+
if: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/master' }}
4344

4445
steps:
4546
- name: SCM Checkout
4647
uses: actions/checkout@v4
4748

48-
- name: Fetch the main branch
49-
run: git fetch origin main
50-
5149
- name: Setup Python & Poetry Environment
5250
uses: ./.github/actions/python-environment
53-
with:
54-
python-version: "3.9"
5551

5652
- name: Run changelog update check
57-
if: ${{ github.ref != 'refs/heads/main' }}
5853
run: poetry run -- nox -s changelog:updated
5954

6055
build-matrix:
@@ -147,8 +142,6 @@ jobs:
147142

148143
- name: Setup Python & Poetry Environment
149144
uses: ./.github/actions/python-environment
150-
with:
151-
python-version: "3.9"
152145

153146
- name: Run format check
154147
run: poetry run -- nox -s project:format

doc/changes/unreleased.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
## Bugfixes
44

5-
* #397: Fix handling empty coverage
5+
* #397: Fixed handling empty coverage
6+
7+
## Refactorings
8+
9+
* #399: Modified `release:prepare` to update `.github/actions` with new PTB version

exasol/toolbox/nox/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def prepare_release_update_version(self, session, config, version):
4141
@hookspec
4242
def prepare_release_add_files(self, session, config):
4343
"""
44-
Files which should be added to the prepare relase commit should be added using add.
44+
Files which should be added to the prepare release commit should be added using add.
4545
4646
Args:
4747
session (nox.Session):
@@ -64,7 +64,7 @@ def pre_integration_tests_hook(self, session, config, context):
6464
6565
This function acts as a hook that gets called before the execution of integration tests.
6666
It can be used to execute any project-specific tasks that need to be performed before
67-
the tests run, such as starting or initalizing a database.
67+
the tests run, such as starting or initializing a database.
6868
6969
Args:
7070
session (nox.Session):

exasol/toolbox/templates/github/workflows/checks.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,14 @@ jobs:
5050
Changelog:
5151
name: Changelog Update Check
5252
runs-on: ubuntu-24.04
53+
if: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/master' }}
5354

5455
steps:
5556
- name: SCM Checkout
5657
uses: actions/checkout@v4
5758

5859
- name: Setup Python & Poetry Environment
59-
uses: ./.github/actions/python-environment
60-
with:
61-
python-version: "3.9"
60+
uses: exasol/python-toolbox/.github/actions/python-environment@1.0.0
6261

6362
- name: Run changelog update check
6463
run: poetry run -- nox -s changelog:updated
@@ -149,8 +148,6 @@ jobs:
149148

150149
- name: Setup Python & Poetry Environment
151150
uses: exasol/python-toolbox/.github/actions/python-environment@1.0.0
152-
with:
153-
python-version: "3.9"
154151

155152
- name: Run format check
156153
run: poetry run -- nox -s project:format
Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,59 @@
1+
import re
2+
from dataclasses import dataclass
3+
from enum import Enum
14
from pathlib import Path
2-
from typing import List
35

46

5-
def update_workflow(template: Path, version: str) -> None:
6-
"""Updates versions of XYZ in GitHub workflow ..."""
7+
def update_github_yml(template: Path, version: str) -> None:
8+
"""Updates versions in GitHub workflows and actions"""
79
with open(template, encoding="utf-8") as file:
810
content = file.readlines()
911

10-
content = update_versions(
11-
lines=content, matcher="exasol/python-toolbox/.github/", version=version
12-
)
12+
content = update_versions(lines=content, version=version)
1313

1414
with open(template, "w", encoding="utf-8") as file:
1515
file.writelines(content)
1616

1717

18-
def is_update_required(line, matcher):
19-
return matcher in line and "@" in line
18+
@dataclass(frozen=True)
19+
class Pattern:
20+
match_pattern: str
21+
break_pattern: str
22+
23+
@property
24+
def version_pattern(self) -> str:
25+
return r"[0-9]+\.[0-9]+\.[0-9]+"
26+
27+
@property
28+
def full_pattern(self) -> str:
29+
return f"{self.match_pattern}{self.break_pattern}{self.version_pattern}"
30+
31+
def replace_version(self, line: str, version: str) -> str:
32+
return re.sub(
33+
f"{self.break_pattern}{self.version_pattern}",
34+
f"{self.break_pattern}{version}",
35+
line,
36+
)
37+
38+
39+
class ToolboxPattern(Enum):
40+
github = Pattern(
41+
match_pattern="exasol/python-toolbox/.github/[^/]+/[^/]+",
42+
break_pattern="@",
43+
)
44+
pypi = Pattern(
45+
match_pattern="exasol-toolbox",
46+
break_pattern="==",
47+
)
2048

2149

22-
def update_version(line, version):
23-
keep = line[: line.index("@") + 1]
24-
updated = f"{version}\n"
25-
return f"{keep}{updated}"
50+
def _update_line_with_version(line: str, version: str) -> str:
51+
for pattern in ToolboxPattern:
52+
match = re.search(pattern.value.full_pattern, line)
53+
if match:
54+
return pattern.value.replace_version(line=line, version=version)
55+
return line
2656

2757

28-
def update_versions(lines, matcher, version) -> list[str]:
29-
result = []
30-
for line in lines:
31-
if is_update_required(line, matcher):
32-
line = update_version(line, version)
33-
result.append(line)
34-
return result
58+
def update_versions(lines: list[str], version: str) -> list[str]:
59+
return [_update_line_with_version(line=line, version=version) for line in lines]

exasol/toolbox/tools/workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def update_workflow(
6868
Path("./.github/workflows"), help="target directory to install the workflow to."
6969
),
7070
confirm: bool = typer.Option(
71-
False, help="Automatically confirm overwritting exsisting workflow(s)"
71+
False, help="Automatically confirm overwriting the existing workflow(s)"
7272
),
7373
) -> None:
7474
"""Similar to install but checks for existing workflows and shows diff"""

noxconfig.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,34 @@
77
from pathlib import Path
88

99
from exasol.toolbox.nox.plugin import hookimpl
10-
from exasol.toolbox.tools.replace_version import update_workflow
10+
from exasol.toolbox.tools.replace_version import update_github_yml
1111

1212

1313
class UpdateTemplates:
1414
TEMPLATE_PATH: Path = Path(__file__).parent / "exasol" / "toolbox" / "templates"
15+
PARENT_PATH: Path = Path(__file__).parent
1516

1617
@property
17-
def workflows(self):
18+
def template_workflows(self) -> list[Path]:
1819
gh_workflows = self.TEMPLATE_PATH / "github" / "workflows"
19-
gh_workflows = [f for f in gh_workflows.iterdir() if f.is_file()]
20-
return gh_workflows
20+
return [f for f in gh_workflows.iterdir() if f.is_file()]
21+
22+
@property
23+
def actions(self) -> list[Path]:
24+
gh_actions = self.PARENT_PATH / ".github" / "actions"
25+
return [f for f in gh_actions.rglob("*") if f.is_file()]
2126

2227
@hookimpl
2328
def prepare_release_update_version(self, session, config, version):
24-
for workflow in self.workflows:
25-
update_workflow(workflow, version)
29+
for workflow in self.template_workflows:
30+
update_github_yml(workflow, version)
31+
32+
for action in self.actions:
33+
update_github_yml(action, version)
2634

2735
@hookimpl
2836
def prepare_release_add_files(self, session, config):
29-
return self.workflows
37+
return self.template_workflows + self.actions
3038

3139

3240
@dataclass(frozen=True)

test/unit/replace_version_test.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
import pytest
22

33
from exasol.toolbox.tools.replace_version import (
4-
is_update_required,
5-
update_version,
4+
_update_line_with_version,
65
update_versions,
76
)
87

98

109
@pytest.mark.parametrize(
11-
"line,matcher,expected",
10+
"line,expected",
1211
[
13-
("hallo/world@all", "hallo", True),
14-
("hallo/world@all", "foo", False),
15-
("hallo/world/all", "hallo", False),
16-
("hallo/world/all", "foo", False),
12+
pytest.param(
13+
"exasol/python-toolbox/.github/actions/python-environment@1.0.0",
14+
"exasol/python-toolbox/.github/actions/python-environment@2.0.0",
15+
id="github_action",
16+
),
17+
pytest.param(
18+
"pip install exasol-toolbox==1.0.0\n",
19+
"pip install exasol-toolbox==2.0.0\n",
20+
id="pypi_version",
21+
),
22+
pytest.param(
23+
"- name: Create Security Issue Report",
24+
"- name: Create Security Issue Report",
25+
id="no_change_expected",
26+
),
1727
],
1828
)
19-
def test_is_update_required(line, matcher, expected):
20-
actual = is_update_required(line, matcher)
29+
def test_update_line_with_version(line: str, expected: str):
30+
actual = _update_line_with_version(line=line, version="2.0.0")
2131
assert actual == expected
2232

2333

2434
@pytest.mark.parametrize(
25-
"line,version,expected",
35+
"line_to_change, expected",
2636
[
27-
("hallo/world@1.2.3\n", "2.3.4", "hallo/world@2.3.4\n"),
28-
("hallo/world@0.0.0\n", "9.9.9", "hallo/world@9.9.9\n"),
37+
pytest.param(
38+
"exasol/python-toolbox/.github/actions/python-environment@1.0.0",
39+
"exasol/python-toolbox/.github/actions/python-environment@2.0.0",
40+
id="github_action",
41+
),
42+
pytest.param(
43+
"pip install exasol-toolbox==1.0.0\n",
44+
"pip install exasol-toolbox==2.0.0\n",
45+
id="pypi_version",
46+
),
2947
],
3048
)
31-
def test_update_version(line, version, expected):
32-
actual = update_version(line, version)
33-
assert actual == expected
34-
49+
def test_update_versions(line_to_change, expected):
50+
dummy_lines = [
51+
"exasol/python-toolbox/.github/actions/python-environment@dummy\n",
52+
"- name: Create Security Issue Report\n",
53+
"pip install exasol-toolbox==dummy\n",
54+
]
55+
lines = dummy_lines + [line_to_change]
56+
expected_lines = dummy_lines + [expected]
3557

36-
@pytest.mark.parametrize(
37-
"lines,matcher,version,expected",
38-
[
39-
(
40-
[
41-
"hallo/world@3.4.5\n",
42-
"foo/world@3.4.5\n",
43-
"hallo/world/3.4.5\n",
44-
"foo/world/3.4.5\n",
45-
],
46-
"hallo",
47-
"4.5.6",
48-
[
49-
"hallo/world@4.5.6\n",
50-
"foo/world@3.4.5\n",
51-
"hallo/world/3.4.5\n",
52-
"foo/world/3.4.5\n",
53-
],
54-
)
55-
],
56-
)
57-
def test_update_versions(lines, matcher, version, expected):
58-
actual = update_versions(lines, matcher, version)
59-
assert actual == expected
58+
actual = update_versions(lines=lines, version="2.0.0")
59+
assert actual == expected_lines

0 commit comments

Comments
 (0)