Update bump_version.py to append also the time to nightlies and add possibility to set manual a nightly version (#114300)
This commit is contained in:
parent
9ea666b5e1
commit
aaecbbdc40
2 changed files with 26 additions and 9 deletions
2
.github/workflows/builder.yml
vendored
2
.github/workflows/builder.yml
vendored
|
@ -105,7 +105,7 @@ jobs:
|
|||
python3 -m pip install "$(grep '^uv' < requirements_test.txt)"
|
||||
uv pip install packaging tomli
|
||||
uv pip install .
|
||||
version="$(python3 script/version_bump.py nightly)"
|
||||
python3 script/version_bump.py nightly --set-nightly-version "${{ needs.init.outputs.version }}"
|
||||
|
||||
if [[ "$(ls home_assistant_frontend*.whl)" =~ ^home_assistant_frontend-(.*)-py3-none-any.whl$ ]]; then
|
||||
echo "Found frontend wheel, setting version to: ${BASH_REMATCH[1]}"
|
||||
|
|
|
@ -24,7 +24,9 @@ def _bump_release(release, bump_type):
|
|||
return major, minor, patch
|
||||
|
||||
|
||||
def bump_version(version, bump_type):
|
||||
def bump_version(
|
||||
version: Version, bump_type: str, *, nightly_version: str | None = None
|
||||
) -> Version:
|
||||
"""Return a new version given a current version and action."""
|
||||
to_change = {}
|
||||
|
||||
|
@ -83,11 +85,14 @@ def bump_version(version, bump_type):
|
|||
to_change["pre"] = ("b", 0)
|
||||
|
||||
elif bump_type == "nightly":
|
||||
# Convert 0.70.0d0 to 0.70.0d20190424, fails when run on non dev release
|
||||
# Convert 0.70.0d0 to 0.70.0d201904241254, fails when run on non dev release
|
||||
if not version.is_devrelease:
|
||||
raise ValueError("Can only be run on dev release")
|
||||
|
||||
to_change["dev"] = ("dev", dt_util.utcnow().strftime("%Y%m%d"))
|
||||
to_change["dev"] = (
|
||||
"dev",
|
||||
nightly_version or dt_util.utcnow().strftime("%Y%m%d%H%M"),
|
||||
)
|
||||
|
||||
else:
|
||||
raise ValueError(f"Unsupported type: {bump_type}")
|
||||
|
@ -146,7 +151,7 @@ def write_ci_workflow(version: Version) -> None:
|
|||
fp.write(content)
|
||||
|
||||
|
||||
def main():
|
||||
def main() -> None:
|
||||
"""Execute script."""
|
||||
parser = argparse.ArgumentParser(description="Bump version of Home Assistant")
|
||||
parser.add_argument(
|
||||
|
@ -157,8 +162,15 @@ def main():
|
|||
parser.add_argument(
|
||||
"--commit", action="store_true", help="Create a version bump commit."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--set-nightly-version", help="Set the nightly version to", type=str
|
||||
)
|
||||
|
||||
arguments = parser.parse_args()
|
||||
|
||||
if arguments.set_nightly_version and arguments.type != "nightly":
|
||||
parser.error("--set-nightly-version requires type set to nightly.")
|
||||
|
||||
if (
|
||||
arguments.commit
|
||||
and subprocess.run(["git", "diff", "--quiet"], check=False).returncode == 1
|
||||
|
@ -167,7 +179,9 @@ def main():
|
|||
return
|
||||
|
||||
current = Version(const.__version__)
|
||||
bumped = bump_version(current, arguments.type)
|
||||
bumped = bump_version(
|
||||
current, arguments.type, nightly_version=arguments.set_nightly_version
|
||||
)
|
||||
assert bumped > current, "BUG! New version is not newer than old version"
|
||||
|
||||
write_version(bumped)
|
||||
|
@ -181,7 +195,7 @@ def main():
|
|||
subprocess.run(["git", "commit", "-nam", f"Bump version to {bumped}"], check=True)
|
||||
|
||||
|
||||
def test_bump_version():
|
||||
def test_bump_version() -> None:
|
||||
"""Make sure it all works."""
|
||||
import pytest
|
||||
|
||||
|
@ -204,10 +218,13 @@ def test_bump_version():
|
|||
assert bump_version(Version("0.56.0.dev0"), "minor") == Version("0.56.0")
|
||||
assert bump_version(Version("0.56.2.dev0"), "minor") == Version("0.57.0")
|
||||
|
||||
today = dt_util.utcnow().strftime("%Y%m%d")
|
||||
now = dt_util.utcnow().strftime("%Y%m%d%H%M")
|
||||
assert bump_version(Version("0.56.0.dev0"), "nightly") == Version(
|
||||
f"0.56.0.dev{today}"
|
||||
f"0.56.0.dev{now}"
|
||||
)
|
||||
assert bump_version(
|
||||
Version("0.56.0.dev0"), "nightly", nightly_version="1234"
|
||||
) == Version("0.56.0.dev1234")
|
||||
with pytest.raises(ValueError):
|
||||
assert bump_version(Version("0.56.0"), "nightly")
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue