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 sanity check on version in CMakeLists.txt file #1224

Merged
merged 7 commits into from
Jan 13, 2025
Merged
Changes from 6 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
41 changes: 41 additions & 0 deletions release.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Tuple
from urllib3.exceptions import RequestError
from urllib3.util import make_headers
import re
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -325,6 +326,44 @@ def sanity_check_sdformat_versions(package, version):

print_success("sdformat version in proper sdformat package")

def get_version_from_cmake(cmake_file="CMakeLists.txt"):
version_regex = re.compile(
r"project\s*\(\s*[a-z0-9-_]*\s*VERSION\s*([0-9.]*)", re.MULTILINE
)
# Note the re.DOTALL is used to match any newlines and arguments to
# gz_configure_project before VERSION_SUFFIX
suffix_regex = re.compile(
r"(?:gz|ign)_configure_project\s*\(.*VERSION_SUFFIX\s*(pre\d+)",
re.MULTILINE | re.DOTALL,
)
try:
with open(cmake_file) as f:
content = f.read()
version_match = re.search(version_regex, content)
suffix_match = re.search(suffix_regex, content)
if version_match:
cmake_version = version_match.group(1)
if suffix_match:
cmake_version = f"{cmake_version}~{suffix_match.group(1)}"
return cmake_version
else:
error("Error parsing version from CMakeLists.txt file")
except FileNotFoundError as e:
print(e)
error("Could not find CMakeLists file. Are you sure you're in the source directory?")

def sanity_check_cmake_version(package, version):
# These two packages do not follow the same formatting in their CMakeLists files.
# Since they are old versions, we'll simply not support them.
if package in ["ign-tools", "sdformat9"]:
print(f" + NOTE Sanity checking is not supported for {package}")
return

cmake_version = get_version_from_cmake()
if cmake_version != version:
error(f"Error in package version. CMakeLists version: {cmake_version}, provided version: {version}")
else:
print_success("Package version in CMakeLists")

def sanity_check_repo_name(repo_name):
if repo_name in OSRF_REPOS_SUPPORTED:
Expand Down Expand Up @@ -381,6 +420,8 @@ def sanity_checks(args, repo_dir):
if not NIGHTLY:
sanity_package_version(repo_dir, args.version, str(args.release_version))
sanity_check_sdformat_versions(args.package, args.version)
if not (args.bump_rev_linux_only or args.source_repo_uri):
Copy link
Contributor

Choose a reason for hiding this comment

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

args.source_repo_uri is designed to provide exact repository URI instead of retrieving it from the local github checkout. Nothing to do with the CMakeListst.txt bussiness I think.

You probably want to use here args.source_tarball_uri that represents an existing source stored out of the system. In that case the check for a local CMakeLists.txt file has less sense unless we download and unzip the tarball.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed this in c783ff8

sanity_check_cmake_version(args.package, args.version)
sanity_project_package_in_stable(args.version, args.upload_to_repository)

check_credentials(args.auth_input_arg)
Expand Down
Loading