def test_next_prerelease_invalid(): version = Version("1.1.1") with pytest.raises(TypeError): version.next_alpha("stuff") with pytest.raises(TypeError): version.next_beta("stuff") with pytest.raises(TypeError): version.next_release_candidate("stuff")
async def test_future_training_data_format_version_not_compatible(): next_minor = str(Version(LATEST_TRAINING_DATA_FORMAT_VERSION).next_minor()) incompatible_version = {KEY_TRAINING_DATA_FORMAT_VERSION: next_minor} with pytest.warns(UserWarning): assert not validation_utils.validate_training_data_format_version( incompatible_version, "")
def test_copy(): version1 = Version("1.0.0") version2 = copy(version1) assert version1 == version2 assert version1 is not version2 assert version1._version == version2._version assert version1._version is not version2._version assert version1._key == version2._key assert version1._key is not version2._key
async def test_compatible_training_data_format_version(): prev_major = str(Version("1.0")) compatible_version_1 = {KEY_TRAINING_DATA_FORMAT_VERSION: prev_major} compatible_version_2 = { KEY_TRAINING_DATA_FORMAT_VERSION: LATEST_TRAINING_DATA_FORMAT_VERSION } for version in [compatible_version_1, compatible_version_2]: with pytest.warns(None): assert validation_utils.validate_training_data_format_version(version, "")
def validate_code_is_release_ready(version: Version) -> None: """Make sure the code base is valid (e.g. Rasa SDK is up to date).""" sdk = Version(get_rasa_sdk_version()) sdk_version = (sdk.major, sdk.minor) rasa_version = (version.major, version.minor) if sdk_version != rasa_version: print() print( f"\033[91m There is a mismatch between the Rasa SDK version ({sdk}) " f"and the version you want to release ({version}). Before you can " f"release Rasa OSS, you need to release the SDK and update " f"the dependency. \033[0m") print() sys.exit(1)
def ask_version() -> Text: """Allow the user to confirm the version number.""" def is_valid_version_number(v: Text) -> bool: return v in {"major", "minor", "micro", "alpha", "rc" } or is_valid_version(v) current_version = Version(get_current_version()) next_micro_version = str(current_version.next_micro()) next_alpha_version = str(current_version.next_alpha()) version = questionary.text( f"What is the version number you want to release " f"('major', 'minor', 'micro', 'alpha', 'rc' or valid version number " f"e.g. '{next_micro_version}' or '{next_alpha_version}')?", validate=is_valid_version_number, ).ask() if version in PRERELEASE_FLAVORS and not current_version.pre: # at this stage it's hard to guess the kind of version bump the # releaser wants, so we ask them if version == "alpha": choices = [ str(current_version.next_alpha("minor")), str(current_version.next_alpha("micro")), str(current_version.next_alpha("major")), ] else: choices = [ str(current_version.next_release_candidate("minor")), str(current_version.next_release_candidate("micro")), str(current_version.next_release_candidate("major")), ] version = questionary.select( f"Which {version} do you want to release?", choices=choices, ).ask() if version: return version else: print("Aborting.") sys.exit(1)
def parse_next_version(version: Text) -> Version: """Find the next version as a proper semantic version string.""" if version == "major": return Version(get_current_version()).next_major() elif version == "minor": return Version(get_current_version()).next_minor() elif version == "micro": return Version(get_current_version()).next_micro() elif version == "alpha": return Version(get_current_version()).next_alpha() elif version == "rc": return Version(get_current_version()).next_release_candidate() elif is_valid_version(version): return Version(version) else: raise Exception(f"Invalid version number '{cmdline_args.next_version}'.")
def main(): tag_name = os.environ.get("GITHUB_TAG") if not tag_name: print("environment variable GITHUB_TAG not set", file=sys.stderr) return 1 token = os.environ.get("GITHUB_TOKEN") if not token: print("GITHUB_TOKEN not set", file=sys.stderr) return 1 slug = os.environ.get("GITHUB_REPO_SLUG") if not slug: print("GITHUB_REPO_SLUG not set", file=sys.stderr) return 1 version = Version(tag_name) if version.pre: md_body = "_Pre-release version_" else: md_body = parse_changelog(tag_name) if not md_body: print( "Failed to extract changelog entries for version from changelog.") return 2 if not create_github_release(slug, token, tag_name, md_body): print("Could not publish release notes:", file=sys.stderr) print(md_body, file=sys.stderr) return 5 print() print(f"Release notes for {tag_name} published successfully:") print(f"https://github.com/{slug}/releases/tag/{tag_name}") print() return 0
def test_next_micro(version_string, expected): version = Version(version_string) next_version = version.next_micro() assert isinstance(next_version, Version) assert next_version > version assert str(next_version) == expected
def test_is_release_candidate(version_string, expected): version = Version(version_string) assert version.is_release_candidate is expected
def test_is_beta(version_string, expected): version = Version(version_string) assert version.is_beta is expected
def test_next_rc(version_string, version_bump, expected): version = Version(version_string) next_version = version.next_release_candidate(version_bump) assert isinstance(next_version, Version) assert next_version > version assert str(next_version) == expected
def test_next_beta(version_string, version_bump, expected): version = Version(version_string) next_version = version.next_beta(version_bump) assert isinstance(next_version, Version) assert next_version > version assert str(next_version) == expected