Skip to content

Commit

Permalink
autorelease: improve versioning logic
Browse files Browse the repository at this point in the history
Consider the following versioning case (rare, but thinkable):
- the previous version has a beta tag
- update_major.txt exists
- update_beta.txt does not exist

The previous code would fail to remove the existing beta tag.
This change fixes the problem. It also adds some comments to make the
logic easier to understand.
  • Loading branch information
mara004 committed Sep 30, 2022
1 parent f37a0cf commit 16c0169
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions setupsrc/pl_setup/autorelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
)


AutoreleaseDir = join(SourceTree, "autorelease")
MajorUpdateFile = join(AutoreleaseDir, "update_major.txt")
BetaUpdateFile = join(AutoreleaseDir, "update_beta.txt")
AutoreleaseDir = join(SourceTree, "autorelease")
MajorUpdateFile = join(AutoreleaseDir, "update_major.txt")
BetaUpdateFile = join(AutoreleaseDir, "update_beta.txt")


def run_local(*args, **kws):
Expand Down Expand Up @@ -70,28 +70,38 @@ def do_versioning(latest):
raise RuntimeError("Neither pypdfium2 code nor pdfium binaries updated. Making a new release would be pointless.")

ver_changes = dict()

if c_updates:
# denote pdfium update (independent change)
ver_changes["V_LIBPDFIUM"] = str(latest)

if inc_major:
ver_changes["V_MAJOR"] = VerNamespace["V_MAJOR"]+1
# major update
ver_changes["V_MAJOR"] = VerNamespace["V_MAJOR"] + 1
ver_changes["V_MINOR"] = 0
ver_changes["V_PATCH"] = 0
os.remove(MajorUpdateFile)
else:
if v_beta is None:
if c_updates:
ver_changes["V_MINOR"] = VerNamespace["V_MINOR"]+1
ver_changes["V_PATCH"] = 0
else:
ver_changes["V_PATCH"] = VerNamespace["V_PATCH"]+1
elif not inc_beta:
ver_changes["V_BETA"] = None
elif v_beta is None:
# if we're not doing a major update and the previous version was not a beta, update minor and/or patch
# however, we still want to run this if adding a new beta tag
if c_updates:
# pdfium update -> increment minor version and reset patch version
ver_changes["V_MINOR"] = VerNamespace["V_MINOR"] + 1
ver_changes["V_PATCH"] = 0
else:
# no pdfium update -> increment patch version
ver_changes["V_PATCH"] = VerNamespace["V_PATCH"] + 1

if inc_beta:
# if the new version shall be a beta, set or increment the tag (independent change)
if v_beta is None:
v_beta = 0
v_beta += 1
ver_changes["V_BETA"] = v_beta
os.remove(BetaUpdateFile)
elif v_beta is not None:
# if the previous version was a beta but the new one shall not be, remove the tag (independent change)
ver_changes["V_BETA"] = None

did_change = set_versions(ver_changes)
assert did_change
Expand Down

0 comments on commit 16c0169

Please sign in to comment.