def test_maven_version_are_never_of_certain_types():
    release = MavenVersion(32, 0)
    assert not release.is_beta
    assert not release.is_release_candidate

    with pytest.raises(TypeError):
        MavenVersion(32, 0, is_beta=True)

    with pytest.raises(TypeError):
        MavenVersion(32, 0, is_release_candidate=True)
Esempio n. 2
0
def get_decision_parameters(graph_config, parameters):
    pr_number = os.environ.get("MOBILE_PULL_REQUEST_NUMBER", None)
    parameters["pull_request_number"] = None if pr_number is None else int(
        pr_number)
    parameters["base_rev"] = os.environ.get("MOBILE_BASE_REV")
    version = get_version()
    parameters["version"] = version
    parameters.setdefault("next_version", None)

    if parameters["tasks_for"] == "github-release":
        head_tag = parameters["head_tag"].decode("utf-8")
        if not head_tag:
            raise ValueError(
                "Cannot run github-release if `head_tag` is not defined. Got {}"
                .format(head_tag))
        # XXX: tags are in the format of `v<semver>`
        if head_tag[1:] != version:
            raise ValueError(
                "Cannot run github-release if tag {} is different than in-tree "
                "{} from buildconfig.yml".format(head_tag[1:], version))
        parameters["target_tasks_method"] = "release"
        version_string = parameters["version"]
        version = MavenVersion.parse(version_string)
        if version.is_release:
            next_version = version.bump("patch_number")
        else:
            raise ValueError("Unsupported version type: {}".format(
                version.version_type))

        parameters["next_version"] = str(next_version).decode("utf-8")
def test_maven_version_constructor_and_str(major_number, minor_number, patch_number, is_snapshot, expected_output_string):
    assert str(MavenVersion(
        major_number=major_number,
        minor_number=minor_number,
        patch_number=patch_number,
        is_snapshot=is_snapshot,
    )) == expected_output_string
Esempio n. 4
0
def _generate_beetmover_template_args_maven(task, release_props):
    tmpl_args = {
        "artifact_id": task["payload"]["artifact_id"],
        "template_key": "maven_{}".format(release_props["appName"])
    }

    # Geckoview follows the FirefoxVersion pattern
    if release_props.get("appName") == "geckoview":
        payload_version = FirefoxVersion.parse(task["payload"]["version"])
        # Change version number to major.minor.buildId because that's what the build task produces
        version = [
            payload_version.major_number, payload_version.minor_number,
            release_props["buildid"]
        ]
    else:
        payload_version = MavenVersion.parse(task["payload"]["version"])
        version = [
            payload_version.major_number, payload_version.minor_number,
            payload_version.patch_number
        ]

    if any(number is None for number in version):
        raise TaskVerificationError(
            "At least one digit is undefined. Got: {}".format(version))
    tmpl_args["version"] = ".".join(str(n) for n in version)

    # XXX: some appservices maven.zip files have a different structure,
    # encompassing only `pom` and `jar` files. We toggle that behavior in the
    # mapping by using this flag
    tmpl_args["is_jar"] = task["payload"].get("is_jar")

    return tmpl_args
def _generate_beetmover_template_args_maven(task, release_props):
    tmpl_args = {
        'artifact_id': task['payload']['artifact_id'],
        'template_key': 'maven_{}'.format(release_props['appName']),
    }

    # FIXME: this is a temporarily solution while we sanitize the payload
    # under https://github.com/mozilla-releng/beetmoverscript/issues/196
    if 'SNAPSHOT' in task['payload']['version']:
        payload_version = MavenVersion.parse(task['payload']['version'])
    else:
        payload_version = FirefoxVersion.parse(task['payload']['version'])
    # Change version number to major.minor.buildId because that's what the build task produces
    version = [
        payload_version.major_number, payload_version.minor_number,
        release_props.get('buildid', payload_version.patch_number)
    ]
    if any(number is None for number in version):
        raise TaskVerificationError(
            'At least one digit is undefined. Got: {}'.format(version))
    tmpl_args['version'] = '.'.join(str(n) for n in version)

    if isinstance(payload_version,
                  MavenVersion) and payload_version.is_snapshot:
        tmpl_args['snapshot_version'] = payload_version
        tmpl_args['date_timestamp'] = "{{date_timestamp}}"
        tmpl_args['clock_timestamp'] = "{{clock_timestamp}}"
        tmpl_args['build_number'] = "{{build_number}}"

    return tmpl_args
Esempio n. 6
0
def get_latest_version(versions, exclude_snapshots=False):
    maven_versions = [MavenVersion.parse(version) for version in versions]
    if exclude_snapshots:
        maven_versions = [
            version for version in maven_versions if not version.is_snapshot
        ]
    if not maven_versions:
        return None
    latest_version = reduce(lambda x, y: x if x >= y else y, maven_versions)
    return str(latest_version)
Esempio n. 7
0
def get_latest_version(versions_per_path):
    maven_versions = []
    for path, version in versions_per_path.items():
        try:
            maven_versions.append(MavenVersion.parse(version))
        except PatternNotMatchedError as error:
            raise ValueError(
                '"{}" does not contain a valid version. See root error.'.
                format(path)) from error

    if not maven_versions:
        return None
    latest_version = reduce(lambda x, y: x if x >= y else y, maven_versions)
    return str(latest_version)
Esempio n. 8
0
def get_maven_version(context):
    """Extract and validate a valid Maven version"""
    version = context.task["payload"]["version"]
    release_props = context.release_props
    # TODO The following 'if' should be removed once GeckoView >= 84 is in mozilla-release.
    # This is a temporary solution to maintain compatibility while the 'version' field in
    # GeckoView's payload transitions from FirefoxVersion format to MavenVersion.
    if release_props.get("appName") == "geckoview":
        app_version = FirefoxVersion.parse(release_props["appVersion"])
        if int(app_version.major_number) < 84:
            # Change version number to major.minor.buildId because that's what the build task produces
            version = "{}.{}.{}".format(app_version.major_number,
                                        app_version.minor_number,
                                        release_props["buildid"])

    # Check that version is a valid maven version
    try:
        MavenVersion.parse(version)
    except (ValueError, PatternNotMatchedError) as e:
        raise ScriptWorkerTaskException(
            f"Version defined in the payload does not match the pattern of a MavenVersion. Got: {version}"
        ) from e

    return version
Esempio n. 9
0
def _generate_beetmover_template_args_maven(task, release_props):
    tmpl_args = {
        'artifact_id': task['payload']['artifact_id'],
        'template_key': 'maven_{}'.format(release_props['appName']),
    }

    # Geckoview follows the FirefoxVersion pattern
    if release_props.get('appName') == 'geckoview':
        payload_version = FirefoxVersion.parse(task['payload']['version'])
        # Change version number to major.minor.buildId because that's what the build task produces
        version = [
            payload_version.major_number,
            payload_version.minor_number,
            release_props['buildid'],
        ]
    else:
        payload_version = MavenVersion.parse(task['payload']['version'])
        version = [
            payload_version.major_number,
            payload_version.minor_number,
            payload_version.patch_number,
        ]

    if any(number is None for number in version):
        raise TaskVerificationError(
            'At least one digit is undefined. Got: {}'.format(version))
    tmpl_args['version'] = '.'.join(str(n) for n in version)

    # XXX: some appservices maven.zip files have a different structure,
    # encompassing only `pom` and `jar` files. We toggle that behavior in the
    # mapping by using this flag
    tmpl_args['is_jar'] = task['payload'].get('is_jar')

    if isinstance(payload_version,
                  MavenVersion) and payload_version.is_snapshot:
        tmpl_args['snapshot_version'] = payload_version
        tmpl_args['date_timestamp'] = "{{date_timestamp}}"
        tmpl_args['clock_timestamp'] = "{{clock_timestamp}}"
        tmpl_args['build_number'] = "{{build_number}}"

    return tmpl_args
def test_maven_version_hashable():
    hash(MavenVersion.parse('32.0.1'))
def test_maven_version_implements_eq_operator():
    assert MavenVersion.parse('32.0-SNAPSHOT') == MavenVersion.parse('32.0-SNAPSHOT')
    # raw strings are also converted
    assert MavenVersion.parse('32.0-SNAPSHOT') == '32.0-SNAPSHOT'
def test_base_version_raises_eq_operator(wrong_type):
    with pytest.raises(ValueError):
        assert MavenVersion.parse('32.0') == wrong_type
    # AttributeError is raised by LooseVersion and StrictVersion
    with pytest.raises((ValueError, AttributeError)):
        assert wrong_type == MavenVersion.parse('32.0')
def test_maven_version_implements_gt_operator(previous, next):
    assert MavenVersion.parse(previous) > MavenVersion.parse(next)
def test_maven_version_raises_when_invalid_version_is_given(version_string, ExpectedErrorType):
    with pytest.raises(ExpectedErrorType):
        MavenVersion.parse(version_string)
def test_maven_version_constructor_minimum_kwargs():
    assert str(MavenVersion(32, 0)) == '32.0'
    assert str(MavenVersion(32, 0, 1)) == '32.0.1'
    assert str(MavenVersion(32, 1, 0)) == '32.1.0'
    assert str(MavenVersion(32, 1, 0, False)) == '32.1.0'
    assert str(MavenVersion(32, 1, 0, True)) == '32.1.0-SNAPSHOT'
Esempio n. 16
0
def test_maven_version_is_of_a_defined_type(version_string, expected_type):
    release = MavenVersion.parse(version_string)
    assert getattr(release, 'is_{}'.format(expected_type))