From 2e9e01816e57e6605991b9360e7db5aea1eeb888 Mon Sep 17 00:00:00 2001 From: dan_the_3rd <43445237+danthe3rd@users.noreply.github.com> Date: Fri, 13 Jan 2023 19:44:20 +0000 Subject: [PATCH] Build on tags even if it's a RC (fairinternal/xformers#429) Co-authored-by: danthe3rd __original_commit__ = fairinternal/xformers@ce9dd66dc9e59620ffe3f78ed1db418fd62aed74 --- .github/workflows/wheels.yml | 2 +- packaging/build_conda.py | 13 ++++++++----- packaging/compute_wheel_version.py | 24 +++++++++++++++--------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 8b091e6750..fc66d606e4 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -6,7 +6,7 @@ on: branches: - main tags: - - "v?[0-9]+.[0-9]+.[0-9]+" + - "v[0-9]+*" # this yaml file can be cleaned up using yaml anchors, but they're not supported in github actions yet # https://github.com/actions/runner/issues/1182 diff --git a/packaging/build_conda.py b/packaging/build_conda.py index c06ab84ca7..f28c2c2ea7 100644 --- a/packaging/build_conda.py +++ b/packaging/build_conda.py @@ -8,6 +8,7 @@ import subprocess from dataclasses import dataclass, field from pathlib import Path +from typing import Optional import compute_wheel_version @@ -75,11 +76,13 @@ class Build: conda_dirty: bool = False build_inside_tree: bool = False upload: bool = False - is_release: bool = field(default_factory=compute_wheel_version.is_exact_version) + tagged_version: Optional[str] = field( + default_factory=compute_wheel_version.get_tagged_version + ) - def _get_build_version(self): - if self.is_release: - return compute_wheel_version.code_version + def _get_build_version(self) -> str: + if self.tagged_version is not None: + return self.tagged_version git_hash = subprocess.check_output( ["git", "rev-parse", "--short", "HEAD"], text=True ).strip() @@ -137,7 +140,7 @@ def _get_build_args(self): if not self.build_inside_tree: args += ["--croot", "../build"] if self.upload: - if self.is_release: + if self.tagged_version is not None: args += ["--user", "xformers"] else: args += ["--user", "xformers", "--label", "dev"] diff --git a/packaging/compute_wheel_version.py b/packaging/compute_wheel_version.py index ca87194fdc..fd2d334ed5 100644 --- a/packaging/compute_wheel_version.py +++ b/packaging/compute_wheel_version.py @@ -4,13 +4,16 @@ # LICENSE file in the root directory of this source tree. import subprocess from pathlib import Path +from typing import Optional + +from packaging import version # TODO: consolidate with the code in build_conda.py THIS_PATH = Path(__file__).resolve() -version = (THIS_PATH.parents[1] / "version.txt").read_text().strip() +version_from_file = (THIS_PATH.parents[1] / "version.txt").read_text().strip() -def is_exact_version() -> bool: +def get_tagged_version() -> Optional[str]: """ Return whether we are at an exact version (namely the version variable). """ @@ -21,15 +24,17 @@ def is_exact_version() -> bool: stderr=subprocess.DEVNULL, ).strip() except subprocess.CalledProcessError: # no tag - return False + return None if not tag.startswith("v"): - return False + return None + # Should match the version in `version.txt` + # (except for the suffix like `rc` tag) assert ( - version == tag[1:] - ), f"The version in version.txt ({version}) does not match the given tag ({tag})" - return True + version.parse(version_from_file).release == version.parse(tag[1:]).release + ), f"The version in version.txt ({version_from_file}) does not match the given tag ({tag})" + return tag[1:] def get_dev_version() -> str: @@ -40,7 +45,8 @@ def get_dev_version() -> str: if __name__ == "__main__": - if is_exact_version(): - print(version, end="") + tagged_version = get_tagged_version() + if tagged_version is not None: + print(tagged_version, end="") else: print(get_dev_version(), end="")