]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-123458: Skip SBOM generation if no git repository is detected (GH-123507...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 2 Sep 2024 23:21:40 +0000 (01:21 +0200)
committerGitHub <noreply@github.com>
Mon, 2 Sep 2024 23:21:40 +0000 (01:21 +0200)
gh-123458: Skip SBOM generation if no git repository is detected (GH-123507)
(cherry picked from commit db42934270c5c23be9f6804cad98dfd8234caf6f)

Co-authored-by: Seth Michael Larson <seth@python.org>
Tools/build/generate_sbom.py

index 1b000c3b16a17a772357466c26643e2c56dd4eab..9cc89b8caee15018014e895614b3618e921a7975 100644 (file)
@@ -96,6 +96,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.
@@ -341,6 +354,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()