Skip to content
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

Add argument to specify minimal version in cfbs generate-release-information #215

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cfbs/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ def get_arg_parser():
help="Check whether masterfiles from cfengine.com and github.com match in 'cfbs generate-release-information'",
action="store_true",
)
parser.add_argument(
"--from",
help="Specify minimum version in 'cfbs generate-release-information'",
dest="minimum_version",
)
parser.add_argument(
"--masterfiles", help="Add masterfiles on cfbs init choose between"
)
Expand Down
4 changes: 4 additions & 0 deletions cfbs/cfbs.1
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ Use existing masterfiles instead of downloading in 'cfbs generate-release-inform
\fB\-\-check\-against\-git\fR
Check whether masterfiles from cfengine.com and github.com match in 'cfbs generate-release-information'

.TP
\fB\-\-from\fR
Specify minimum version in 'cfbs generate-release-information'

.TP
\fB\-\-masterfiles\fR \fI\,MASTERFILES\/\fR
Add masterfiles on cfbs init choose between
Expand Down
6 changes: 4 additions & 2 deletions cfbs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,5 +1208,7 @@ def get_input_command(name, outfile):


@cfbs_command("generate-release-information")
def generate_release_information_command(omit_download=False, check=False):
generate_release_information(omit_download, check)
def generate_release_information_command(
omit_download=False, check=False, min_version=None
):
generate_release_information(omit_download, check, min_version)
10 changes: 9 additions & 1 deletion cfbs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ def main() -> int:
% args.command
)

if args.minimum_version and args.command != "generate-release-information":
user_error(
"The option --from is only for 'cfbs generate-release-information', not 'cfbs %s'"
% args.command
)

if args.non_interactive and args.command not in (
"init",
"add",
Expand Down Expand Up @@ -105,7 +111,9 @@ def main() -> int:

if args.command == "generate-release-information":
return commands.generate_release_information_command(
omit_download=args.omit_download, check=args.check_against_git
omit_download=args.omit_download,
check=args.check_against_git,
min_version=args.minimum_version,
)

if not is_cfbs_repo():
Expand Down
6 changes: 6 additions & 0 deletions cfbs/masterfiles/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,9 @@ def version_as_comparable_list_negated(version):
vcl[1] = [-x for x in vcl[1]]

return vcl


def version_is_at_least(version, min_version):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have a couple of versions compare functions in utils.py for the different comparison operators > , < , >= , <= , == , and != along with unit tests. This is probably out of the scope of this PR. But feel free to do that in a follow-up PR, if you are up for the challenge 😉 I believe we compare versions in multiple places throughout this project. cfbs add is one example.

return min_version is None or (
version_as_comparable_list(version) >= version_as_comparable_list(min_version)
)
28 changes: 17 additions & 11 deletions cfbs/masterfiles/download_all_versions.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
import shutil

from cfbs.masterfiles.analyze import version_is_at_least
from cfbs.utils import FetchError, fetch_url, get_json, mkdir, user_error

ENTERPRISE_RELEASES_URL = "https://cfengine.com/release-data/enterprise/releases.json"


def get_download_urls_enterprise():
def get_download_urls_enterprise(min_version=None):
download_urls = {}
reported_checksums = {}

Expand All @@ -17,6 +18,9 @@ def get_download_urls_enterprise():
for release_data in data["releases"]:
version = release_data["version"]

if not version_is_at_least(version, min_version):
continue

if version == "3.10.0":
# for 3.10.0, for some reason, the "Masterfiles ready-to-install tarball" is a .tar.gz tarball, rather than a .pkg.tar.gz tarball
# download the .pkg.tar.gz tarball from an unlisted analoguous URL instead
Expand Down Expand Up @@ -91,22 +95,24 @@ def download_versions_from_urls(download_path, download_urls, reported_checksums
return downloaded_versions


def download_all_versions(download_path):
download_urls, reported_checksums = get_download_urls_enterprise()
def download_all_versions(download_path, min_version=None):
download_urls, reported_checksums = get_download_urls_enterprise(min_version)

# add masterfiles versions which do not appear in Enterprise releases but appear in Community releases
# 3.12.0b1
version = "3.12.0b1"
download_url = "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.12.0b1/misc/cfengine-masterfiles-3.12.0b1.pkg.tar.gz"
digest = "ede305dae7be3edfac04fc5b7f63b46adb3a5b1612f4755e855ee8e6b8d344d7"
download_urls[version] = download_url
reported_checksums[version] = digest
if version_is_at_least(version, min_version):
download_url = "https://cfengine-package-repos.s3.amazonaws.com/community_binaries/Community-3.12.0b1/misc/cfengine-masterfiles-3.12.0b1.pkg.tar.gz"
digest = "ede305dae7be3edfac04fc5b7f63b46adb3a5b1612f4755e855ee8e6b8d344d7"
download_urls[version] = download_url
reported_checksums[version] = digest
# 3.10.0b1
version = "3.10.0b1"
download_url = "https://cfengine-package-repos.s3.amazonaws.com/tarballs/cfengine-masterfiles-3.10.0b1.pkg.tar.gz"
digest = "09291617254705d79dea2531b23dbd0754f09029e90ce0b43b275aa02c1223a3"
download_urls[version] = download_url
reported_checksums[version] = digest
if version_is_at_least(version, min_version):
download_url = "https://cfengine-package-repos.s3.amazonaws.com/tarballs/cfengine-masterfiles-3.10.0b1.pkg.tar.gz"
digest = "09291617254705d79dea2531b23dbd0754f09029e90ce0b43b275aa02c1223a3"
download_urls[version] = download_url
reported_checksums[version] = digest

downloaded_versions = download_versions_from_urls(
download_path, download_urls, reported_checksums
Expand Down
12 changes: 10 additions & 2 deletions cfbs/masterfiles/generate_release_information.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from cfbs.masterfiles.analyze import version_is_at_least
from cfbs.masterfiles.download_all_versions import download_all_versions
from cfbs.masterfiles.generate_vcf_download import generate_vcf_download
from cfbs.masterfiles.generate_vcf_git_checkout import generate_vcf_git_checkout
Expand All @@ -7,16 +8,23 @@
DOWNLOAD_PATH = "downloaded_masterfiles"


def generate_release_information(omit_download=False, check=False):
def generate_release_information(omit_download=False, check=False, min_version=None):
if not omit_download:
print("Downloading masterfiles...")

downloaded_versions = download_all_versions(DOWNLOAD_PATH)
downloaded_versions = download_all_versions(DOWNLOAD_PATH, min_version)

print("Download finished. Every reported checksum matches.")
else:
downloaded_versions = immediate_subdirectories(DOWNLOAD_PATH)

downloaded_versions = list(
jakub-nt marked this conversation as resolved.
Show resolved Hide resolved
filter(
lambda v: version_is_at_least(v, min_version),
downloaded_versions,
)
)

print(
"Downloading releases of masterfiles from cfengine.com and generating release information..."
)
Expand Down
Loading