]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-123458: Skip SBOM generation if no git repository is detected (#123507)
authorSeth Michael Larson <seth@python.org>
Mon, 2 Sep 2024 19:35:30 +0000 (14:35 -0500)
committerGitHub <noreply@github.com>
Mon, 2 Sep 2024 19:35:30 +0000 (22:35 +0300)
Tools/build/generate_sbom.py

index 88f311bf6b40d1fe19d7f09b24b90999e86d6813..020f874cffeaef7116997daa1eb0cab0cd3c271c 100644 (file)
@@ -93,6 +93,19 @@ def error_if(value: bool, error_message: str) -> None:
         sys.exit(1)
 
 
+def is_root_directory_git_index() -> bool:
+    """Checks if the root directory is a git index"""
+    try:
+        subprocess.check_call(
+            ["git", "-C", str(CPYTHON_ROOT_DIR), "rev-parse"],
+            stdout=subprocess.DEVNULL,
+            stderr=subprocess.DEVNULL,
+        )
+    except subprocess.CalledProcessError:
+        return False
+    return True
+
+
 def filter_gitignored_paths(paths: list[str]) -> list[str]:
     """
     Filter out paths excluded by the gitignore file.
@@ -338,6 +351,11 @@ def create_externals_sbom() -> None:
 
 
 def main() -> None:
+    # Don't regenerate the SBOM if we're not a git repository.
+    if not is_root_directory_git_index():
+        print("Skipping SBOM generation due to not being a git repository")
+        return
+
     create_source_sbom()
     create_externals_sbom()