-
Notifications
You must be signed in to change notification settings - Fork 1
Refactoring/399 ensure all ptb versions updated #400
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
Merged
ArBridgeman
merged 10 commits into
main
from
refactoring/399_ensure_all_ptb_versions_updated
Apr 11, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
180c146
Fix typos in workflow.py docstring
ArBridgeman a30e724
Bump PTB to version 1.0.0, as missed in many updates
ArBridgeman 85bb579
Remove python-version: '3.9' in templates and correct template to poi…
ArBridgeman 888151d
fixup! Fix typos in workflow.py docstring
ArBridgeman 0e3a5fb
Modify `release:prepare` to update `.github/actions` with new PTB ver…
ArBridgeman b57b6a8
Update test_update_versions dummy text for more variety
ArBridgeman af7ec45
Change pathlib iterator as actions/folder/file layout not actions/file
ArBridgeman 5b8fb9c
Skip changelog step if on main
ArBridgeman 747732a
Ensure changelog check does not run on main or master
ArBridgeman 50ac7a3
Adapted .github/workflows/checks.yml per review to be consistent with…
ArBridgeman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,15 +50,14 @@ jobs: | |
| Changelog: | ||
| name: Changelog Update Check | ||
| runs-on: ubuntu-24.04 | ||
| if: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/master' }} | ||
|
|
||
| steps: | ||
| - name: SCM Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Python & Poetry Environment | ||
| uses: ./.github/actions/python-environment | ||
| with: | ||
| python-version: "3.9" | ||
| uses: exasol/python-toolbox/.github/actions/[email protected] | ||
|
|
||
| - name: Run changelog update check | ||
| run: poetry run -- nox -s changelog:updated | ||
|
|
@@ -149,8 +148,6 @@ jobs: | |
|
|
||
| - name: Setup Python & Poetry Environment | ||
| uses: exasol/python-toolbox/.github/actions/[email protected] | ||
| with: | ||
| python-version: "3.9" | ||
|
|
||
| - name: Run format check | ||
| run: poetry run -- nox -s project:format | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,59 @@ | ||
| import re | ||
| from dataclasses import dataclass | ||
| from enum import Enum | ||
| from pathlib import Path | ||
| from typing import List | ||
|
|
||
|
|
||
| def update_workflow(template: Path, version: str) -> None: | ||
| """Updates versions of XYZ in GitHub workflow ...""" | ||
| def update_github_yml(template: Path, version: str) -> None: | ||
| """Updates versions in GitHub workflows and actions""" | ||
| with open(template, encoding="utf-8") as file: | ||
| content = file.readlines() | ||
|
|
||
| content = update_versions( | ||
| lines=content, matcher="exasol/python-toolbox/.github/", version=version | ||
| ) | ||
| content = update_versions(lines=content, version=version) | ||
|
|
||
| with open(template, "w", encoding="utf-8") as file: | ||
| file.writelines(content) | ||
|
|
||
|
|
||
| def is_update_required(line, matcher): | ||
| return matcher in line and "@" in line | ||
| @dataclass(frozen=True) | ||
| class Pattern: | ||
| match_pattern: str | ||
| break_pattern: str | ||
|
|
||
| @property | ||
| def version_pattern(self) -> str: | ||
| return r"[0-9]+\.[0-9]+\.[0-9]+" | ||
|
|
||
| @property | ||
| def full_pattern(self) -> str: | ||
| return f"{self.match_pattern}{self.break_pattern}{self.version_pattern}" | ||
|
|
||
| def replace_version(self, line: str, version: str) -> str: | ||
| return re.sub( | ||
| f"{self.break_pattern}{self.version_pattern}", | ||
| f"{self.break_pattern}{version}", | ||
| line, | ||
| ) | ||
|
|
||
|
|
||
| class ToolboxPattern(Enum): | ||
| github = Pattern( | ||
| match_pattern="exasol/python-toolbox/.github/[^/]+/[^/]+", | ||
| break_pattern="@", | ||
| ) | ||
| pypi = Pattern( | ||
| match_pattern="exasol-toolbox", | ||
| break_pattern="==", | ||
| ) | ||
|
|
||
|
|
||
| def update_version(line, version): | ||
| keep = line[: line.index("@") + 1] | ||
| updated = f"{version}\n" | ||
| return f"{keep}{updated}" | ||
| def _update_line_with_version(line: str, version: str) -> str: | ||
| for pattern in ToolboxPattern: | ||
| match = re.search(pattern.value.full_pattern, line) | ||
| if match: | ||
| return pattern.value.replace_version(line=line, version=version) | ||
| return line | ||
|
|
||
|
|
||
| def update_versions(lines, matcher, version) -> list[str]: | ||
| result = [] | ||
| for line in lines: | ||
| if is_update_required(line, matcher): | ||
| line = update_version(line, version) | ||
| result.append(line) | ||
| return result | ||
| def update_versions(lines: list[str], version: str) -> list[str]: | ||
| return [_update_line_with_version(line=line, version=version) for line in lines] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,59 +1,59 @@ | ||
| import pytest | ||
|
|
||
| from exasol.toolbox.tools.replace_version import ( | ||
| is_update_required, | ||
| update_version, | ||
| _update_line_with_version, | ||
| update_versions, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "line,matcher,expected", | ||
| "line,expected", | ||
| [ | ||
| ("hallo/world@all", "hallo", True), | ||
| ("hallo/world@all", "foo", False), | ||
| ("hallo/world/all", "hallo", False), | ||
| ("hallo/world/all", "foo", False), | ||
| pytest.param( | ||
ArBridgeman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "exasol/python-toolbox/.github/actions/[email protected]", | ||
| "exasol/python-toolbox/.github/actions/[email protected]", | ||
| id="github_action", | ||
| ), | ||
| pytest.param( | ||
| "pip install exasol-toolbox==1.0.0\n", | ||
| "pip install exasol-toolbox==2.0.0\n", | ||
| id="pypi_version", | ||
| ), | ||
| pytest.param( | ||
| "- name: Create Security Issue Report", | ||
| "- name: Create Security Issue Report", | ||
| id="no_change_expected", | ||
| ), | ||
| ], | ||
| ) | ||
| def test_is_update_required(line, matcher, expected): | ||
| actual = is_update_required(line, matcher) | ||
| def test_update_line_with_version(line: str, expected: str): | ||
| actual = _update_line_with_version(line=line, version="2.0.0") | ||
| assert actual == expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "line,version,expected", | ||
| "line_to_change, expected", | ||
| [ | ||
| ("hallo/[email protected]\n", "2.3.4", "hallo/[email protected]\n"), | ||
| ("hallo/[email protected]\n", "9.9.9", "hallo/[email protected]\n"), | ||
| pytest.param( | ||
| "exasol/python-toolbox/.github/actions/[email protected]", | ||
| "exasol/python-toolbox/.github/actions/[email protected]", | ||
| id="github_action", | ||
| ), | ||
| pytest.param( | ||
| "pip install exasol-toolbox==1.0.0\n", | ||
| "pip install exasol-toolbox==2.0.0\n", | ||
| id="pypi_version", | ||
| ), | ||
| ], | ||
| ) | ||
| def test_update_version(line, version, expected): | ||
| actual = update_version(line, version) | ||
| assert actual == expected | ||
|
|
||
| def test_update_versions(line_to_change, expected): | ||
| dummy_lines = [ | ||
| "exasol/python-toolbox/.github/actions/python-environment@dummy\n", | ||
| "- name: Create Security Issue Report\n", | ||
| "pip install exasol-toolbox==dummy\n", | ||
| ] | ||
| lines = dummy_lines + [line_to_change] | ||
| expected_lines = dummy_lines + [expected] | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "lines,matcher,version,expected", | ||
| [ | ||
| ( | ||
| [ | ||
| "hallo/[email protected]\n", | ||
| "foo/[email protected]\n", | ||
| "hallo/world/3.4.5\n", | ||
| "foo/world/3.4.5\n", | ||
| ], | ||
| "hallo", | ||
| "4.5.6", | ||
| [ | ||
| "hallo/[email protected]\n", | ||
| "foo/[email protected]\n", | ||
| "hallo/world/3.4.5\n", | ||
| "foo/world/3.4.5\n", | ||
| ], | ||
| ) | ||
| ], | ||
| ) | ||
| def test_update_versions(lines, matcher, version, expected): | ||
| actual = update_versions(lines, matcher, version) | ||
| assert actual == expected | ||
| actual = update_versions(lines=lines, version="2.0.0") | ||
| assert actual == expected_lines | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.