Skip to content

Commit

Permalink
Build on tags even if it's a RC (fairinternal/xformers#429)
Browse files Browse the repository at this point in the history
Co-authored-by: danthe3rd <danthe3rd>

__original_commit__ = fairinternal/xformers@ce9dd66
  • Loading branch information
danthe3rd authored and xFormers Bot committed Jan 13, 2023
1 parent 9bfcebd commit 2e9e018
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions packaging/build_conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import subprocess
from dataclasses import dataclass, field
from pathlib import Path
from typing import Optional

import compute_wheel_version

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"]
Expand Down
24 changes: 15 additions & 9 deletions packaging/compute_wheel_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
"""
Expand All @@ -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:
Expand All @@ -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="")

0 comments on commit 2e9e018

Please sign in to comment.