-
Notifications
You must be signed in to change notification settings - Fork 565
[FR] Adapt PyPi semver Library and Remove Custom #2503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
53023fd
b715e48
273a6ab
3b79faa
ed82c8c
5239ff7
22c6cd1
9391f64
0ba644f
532c156
0888b65
77960b1
352dee0
81dfe38
397c76e
72d88b9
386a913
0d09298
774e258
2b2fbe5
9454d0d
22aed7d
90898eb
7606932
11207a6
d140209
880130a
09eb6cd
6e351e8
346156e
f11c663
e0ef91e
06a450a
f578bb9
7f1afb7
0d91e6f
8a4eb0a
4aa700e
d63abe6
3ee7fab
0a8222d
a694ceb
82ec97c
49ae652
b9bba39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
import click | ||
import requests.exceptions | ||
from semver import Version | ||
import yaml | ||
from elasticsearch import Elasticsearch | ||
from eql.table import Table | ||
|
@@ -33,7 +34,10 @@ | |
from .endgame import EndgameSchemaManager | ||
from .eswrap import CollectEvents, add_range_to_dsl | ||
from .ghwrap import GithubClient, update_gist | ||
from .integrations import (build_integrations_manifest, build_integrations_schemas, find_latest_compatible_version, | ||
from .integrations import (build_integrations_manifest, | ||
build_integrations_schemas, | ||
find_latest_compatible_version, | ||
find_latest_integration_version, | ||
load_integrations_manifests) | ||
from .main import root | ||
from .misc import PYTHON_LICENSE, add_client, client_error | ||
|
@@ -43,9 +47,8 @@ | |
ThreatMapping, TOMLRule) | ||
from .rule_loader import RuleCollection, production_filter | ||
from .schemas import definitions, get_stack_versions | ||
from .semver import Version | ||
from .utils import (dict_hash, get_etc_path, get_path, load_dump, save_etc_dump, | ||
load_etc_dump) | ||
from .utils import (dict_hash, get_etc_path, get_path, load_dump, | ||
load_etc_dump, save_etc_dump) | ||
from .version_lock import VersionLockFile, default_version_lock | ||
|
||
RULES_DIR = get_path('rules') | ||
|
@@ -152,43 +155,45 @@ def build_integration_docs(ctx: click.Context, registry_version: str, pre: str, | |
return docs | ||
|
||
|
||
@dev_group.command("bump-versions") | ||
@click.option("--major", is_flag=True, help="bump the major version") | ||
@click.option("--minor", is_flag=True, help="bump the minor version") | ||
@click.option("--patch", is_flag=True, help="bump the patch version") | ||
@click.option("--package", is_flag=True, help="Update the package version in the packages.yml file") | ||
@click.option("--kibana", is_flag=True, help="Update the kibana version in the packages.yml file") | ||
@click.option("--registry", is_flag=True, help="Update the registry version in the packages.yml file") | ||
def bump_versions(major, minor, patch, package, kibana, registry): | ||
@dev_group.command("bump-pkg-versions") | ||
@click.option("--major-release", is_flag=True, help="bump the major version") | ||
@click.option("--minor-release", is_flag=True, help="bump the minor version") | ||
@click.option("--patch-release", is_flag=True, help="bump the patch version") | ||
@click.option("--maturity", type=click.Choice(['beta', 'ga'], case_sensitive=False), | ||
required=True, help="beta or production versions") | ||
def bump_versions(major_release: bool, minor_release: bool, patch_release: bool, maturity: str): | ||
"""Bump the versions""" | ||
|
||
package_data = load_etc_dump('packages.yml')['package'] | ||
ver = package_data["name"] | ||
new_version = Version(ver).bump(major, minor, patch) | ||
|
||
kibana_version = f"^{new_version}.0" if not patch else f"^{new_version}" | ||
registry_version = f"{new_version}.0-dev.0" if not patch else f"{new_version}-dev.0" | ||
|
||
# print the new versions | ||
click.echo(f"New package version: {new_version}") | ||
click.echo(f"New registry data version: {registry_version}") | ||
click.echo(f"New Kibana version: {kibana_version}") | ||
|
||
if package: | ||
# update package version | ||
package_data["name"] = str(new_version) | ||
|
||
if kibana: | ||
# update kibana version | ||
package_data["registry_data"]["conditions"]["kibana.version"] = kibana_version | ||
pkg_data = load_etc_dump('packages.yml')['package'] | ||
kibana_ver = Version.parse(pkg_data["name"], optional_minor_and_patch=True) | ||
pkg_ver = Version.parse(pkg_data["registry_data"]["version"]) | ||
pkg_kibana_ver = Version.parse(pkg_data["registry_data"]["conditions"]["kibana.version"].lstrip("^")) | ||
if major_release: | ||
pkg_data["name"] = str(kibana_ver.bump_major()).rstrip(".0") | ||
pkg_data["registry_data"]["conditions"]["kibana.version"] = f"^{pkg_kibana_ver.bump_major()}" | ||
pkg_data["registry_data"]["version"] = str(pkg_ver.bump_major().bump_prerelease("beta")) | ||
if minor_release: | ||
pkg_data["name"] = str(kibana_ver.bump_minor()).rstrip(".0") | ||
pkg_data["registry_data"]["conditions"]["kibana.version"] = f"^{pkg_kibana_ver.bump_minor()}" | ||
pkg_data["registry_data"]["version"] = str(pkg_ver.bump_minor().bump_prerelease("beta")) | ||
pkg_data["registry_data"]["release"] = maturity | ||
if patch_release: | ||
latest_patch_release_ver = find_latest_integration_version("security_detection_engine", | ||
maturity, pkg_data["name"]) | ||
if maturity == "ga": | ||
pkg_data["registry_data"]["version"] = str(latest_patch_release_ver.bump_patch()) | ||
pkg_data["registry_data"]["release"] = maturity | ||
else: | ||
pkg_data["registry_data"]["version"] = str(latest_patch_release_ver.bump_prerelease("beta")) | ||
pkg_data["registry_data"]["release"] = maturity | ||
|
||
if registry: | ||
# update registry version | ||
package_data["registry_data"]["version"] = registry_version | ||
# update packages.yml | ||
click.echo(f"Kibana version: {pkg_data['name']}") | ||
click.echo(f"Package Kibana version: {pkg_data['registry_data']['conditions']['kibana.version']}") | ||
click.echo(f"Package version: {pkg_data['registry_data']['version']}") | ||
|
||
if package or kibana or registry: | ||
save_etc_dump({"package": package_data}, "packages.yml") | ||
# we only save major and minor version bumps | ||
# patch version bumps are OOB packages and thus we keep the base versioning | ||
save_etc_dump({"package": pkg_data}, "packages.yml") | ||
|
||
|
||
@dataclasses.dataclass | ||
|
@@ -249,7 +254,7 @@ def prune_staging_area(target_stack_version: str, dry_run: bool, exception_list: | |
} | ||
exceptions.update(exception_list.split(",")) | ||
|
||
target_stack_version = Version(target_stack_version)[:2] | ||
target_stack_version = Version.parse(target_stack_version, optional_minor_and_patch=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these ignored patch - how does this change handle that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great question as this command is important to the backporting workflow. The |
||
|
||
# load a structured summary of the diff from git | ||
git_output = subprocess.check_output(["git", "diff", "--name-status", "HEAD"]) | ||
|
@@ -270,7 +275,8 @@ def prune_staging_area(target_stack_version: str, dry_run: bool, exception_list: | |
dict_contents = RuleCollection.deserialize_toml_string(change.read()) | ||
min_stack_version: Optional[str] = dict_contents.get("metadata", {}).get("min_stack_version") | ||
|
||
if min_stack_version is not None and target_stack_version < Version(min_stack_version)[:2]: | ||
if min_stack_version is not None and \ | ||
(target_stack_version < Version.parse(min_stack_version, optional_minor_and_patch=True)): | ||
# rule is incompatible, add to the list of reversions to make later | ||
reversions.append(change) | ||
|
||
|
@@ -896,13 +902,13 @@ def trim_version_lock(min_version: str, dry_run: bool): | |
stack_versions = get_stack_versions() | ||
assert min_version in stack_versions, f'Unknown min_version ({min_version}), expected: {", ".join(stack_versions)}' | ||
|
||
min_version = Version(min_version) | ||
min_version = Version.parse(min_version) | ||
version_lock_dict = default_version_lock.version_lock.to_dict() | ||
removed = {} | ||
|
||
for rule_id, lock in version_lock_dict.items(): | ||
if 'previous' in lock: | ||
prev_vers = [Version(v) for v in list(lock['previous'])] | ||
prev_vers = [Version.parse(v, optional_minor_and_patch=True) for v in list(lock['previous'])] | ||
outdated_vers = [v for v in prev_vers if v <= min_version] | ||
|
||
if not outdated_vers: | ||
|
@@ -1212,7 +1218,9 @@ def show_latest_compatible_version(package: str, stack_version: str) -> None: | |
return | ||
|
||
try: | ||
version = find_latest_compatible_version(package, "", stack_version, packages_manifest) | ||
version = find_latest_compatible_version(package, "", | ||
Version.parse(stack_version, optional_minor_and_patch=True), | ||
packages_manifest) | ||
click.echo(f"Compatible integration {version=}") | ||
except Exception as e: | ||
click.echo(f"Error finding compatible version: {str(e)}") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this code change tested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested after renaming file to a lower version and running the refresh-data command.