Skip to content

Fix/Refactor: Prerelease #435

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

Conversation

jacksbox
Copy link
Contributor

@jacksbox jacksbox commented Apr 7, 2022

Ready for review

Related to #434

When digging into the issue I encountered some more misalignments in my previous provided code for the prerelease feature.
With this PR I want to fix this issues and also do some normalisation work in the package.

@danth @williamluke4 @relekang
Curiously, locally all tests pass. I checked and the test fail because of methods which traverse the git log...
Locally all commits starting from the current branch are analysed (ending with the init commit) - but in the ci pipeline, there is only one commit (Some merge commit I can't find nowhere else... ). Any Idea why this is happening and how to prevent it?

Solved: The problem was, that by default githubs actions/checkout@v2 checks out a single merge commit. It has to be instructed to checkout the actual brach with its full history.

Main changes:

  • The way new versions are determined now utilise the semvar package
  • normalised the way versions are matched via regex
  • Better and unified way to get the current release version

Unsolved Issues:

Possible improvements:
There are now two similar methods to get the current version:
get_current_version: gets the last version, whatever is the last tag or in the config file
get_current_release_version: gets the last not-prerelease version (this is needed to determine the correct level_bump)
for ease of use (they are mostly used together) and further development, this two methods could be merged and return a tuple (current_version, current_release_version)

@@ -46,7 +54,7 @@ def from_variable(config_str: str):
"""
path, variable = config_str.split(":", 1)
pattern = (
rf'{variable} *[:=] *["\']{PatternVersionDeclaration.version_regex}["\']'
rf'{variable} *[:=] *["\']{version_regex}["\']'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced to use a single source of truth

@@ -57,7 +65,7 @@ def from_pattern(config_str: str):
regular expression matching the version number.
"""
path, pattern = config_str.split(":", 1)
pattern = pattern.format(version=PatternVersionDeclaration.version_regex)
pattern = pattern.format(version=version_regex)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced to use a single source of truth

continue
matches = re.match(r"v?(\d+.\d+.\d+)", commit_message)
if matches:
match = re.search(rf"{release_version_pattern}", commit_message)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced to use a single source of truth


match = re.search(rf"{pattern}", i.name)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced to use a single source of truth

@@ -14,5 +14,8 @@ force_grid_wrap=0
use_parentheses=True
line_length=88

[flake8]
max-line-length = 120
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I remove this again?

if config.get("version_source") == "tag":
return get_current_release_version_by_tag()
else:
return get_current_release_version_by_commits()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_current_release_version should give us the last not-prerelease version.
As the config file does not give us any history, we have to analyse commits here instead of just looking into the config file.

release_version_pattern = f"(\d+.\d+.\d+(?!{prerelease_pattern}))"

release_version_regex = rf"{release_version_pattern}"
version_regex = rf"{version_pattern}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this variables as single source of truth for regex version matching, for ease of use once as string and once as regex.

@jacksbox jacksbox changed the title WIP: Fix/Refactor: Prerelease Fix/Refactor: Prerelease Apr 7, 2022
@jacksbox jacksbox force-pushed the feature/prerelease-reworked branch 9 times, most recently from 6611e10 to 6ef2404 Compare April 13, 2022 06:38
Copy link
Member

@danth danth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes so far look good to me, although there are some conflicts which need to be fixed.

Are you still working on this or is it ready to be merged?

Copy link
Contributor

@williamluke4 williamluke4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jacksbox jacksbox force-pushed the feature/prerelease-reworked branch from 6ef2404 to 73059ed Compare April 25, 2022 07:52
@jacksbox
Copy link
Contributor Author

rebased

@jacksbox
Copy link
Contributor Author

jacksbox commented May 2, 2022

@danth / @williamluke4
can you hit merge ;)

@danth danth merged commit 94c9494 into python-semantic-release:master May 2, 2022
@danth
Copy link
Member

danth commented May 2, 2022

@jacksbox Done!

EDIT: since merging it seems that the tests are now failing.

@jacksbox
Copy link
Contributor Author

jacksbox commented May 9, 2022

@danth probably we should rollback for now - until we decided / come up with a more secure way of parsing the commit history.

sorry for introducing this issues :(

@ghost
Copy link

ghost commented May 27, 2022

Just picked up this change in my pipeline. Seems the negative lookback in the release version check is stripping all but the first digit of the patch version.

debug: Parsing current version: path=PosixPath('src/analytics_calc/init.py') pattern='version *[:=] *"\'["\']' num_matches=1
debug: Regex matched version: 0.0.24
debug: get_current_version_by_config_file -> 0.0.24
debug: get_current_release_version_by_commits()
debug: Checking commit 19569b7cf15c3d21c7ed45dc335a386aed4d997e
debug: Checking commit 32ae4df6ee88c31e145f5109aa89c782c1c4795c
debug: Checking commit ccee325f58b449cdce1e623313efe7e1bbe6657d
debug: Checking commit 9a951310467c011f7050efead12059a5ce8537bc
debug: Checking commit c22ae08de4193e9c450d3d24fd07722d1a10fe6f
debug: Checking commit f453ba3f1e76e6d62c5a49ddc15f475401d8d66d
debug: Version matches regex 0.0.24-beta.0
debug:
debug: Automatically generated by python-semantic-release
debug: get_current_release_version_by_commits -> 0.0.2
Current version: 0.0.24, Current release version: 0.0.2
debug: evaluate_version_bump('0.0.24', 'patch')
debug: evaluate_version_bump -> patch
debug: get_new_version('0.0.24', '0.0.2', 'patch', True)

Tested the current regex in isolation against the current version and I am indeed seeing a stripped version number returned as match[1] - (\d+.\d+.\d+(?!-beta.\d+)) matched on 0.0.24-beta.0 gives 0.0.2

Removing the "-" from before beta in the regex seems to provide the desired output 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants