Skip to content

Commit f812423

Browse files
[3.13] gh-123458: Skip SBOM generation if no git repository is detected (GH-123507) (#123616)
gh-123458: Skip SBOM generation if no git repository is detected (GH-123507) (cherry picked from commit db42934) Co-authored-by: Seth Michael Larson <[email protected]>
1 parent 59e2a09 commit f812423

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Tools/build/generate_sbom.py

+18
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ def error_if(value: bool, error_message: str) -> None:
9696
sys.exit(1)
9797

9898

99+
def is_root_directory_git_index() -> bool:
100+
"""Checks if the root directory is a git index"""
101+
try:
102+
subprocess.check_call(
103+
["git", "-C", str(CPYTHON_ROOT_DIR), "rev-parse"],
104+
stdout=subprocess.DEVNULL,
105+
stderr=subprocess.DEVNULL,
106+
)
107+
except subprocess.CalledProcessError:
108+
return False
109+
return True
110+
111+
99112
def filter_gitignored_paths(paths: list[str]) -> list[str]:
100113
"""
101114
Filter out paths excluded by the gitignore file.
@@ -341,6 +354,11 @@ def create_externals_sbom() -> None:
341354

342355

343356
def main() -> None:
357+
# Don't regenerate the SBOM if we're not a git repository.
358+
if not is_root_directory_git_index():
359+
print("Skipping SBOM generation due to not being a git repository")
360+
return
361+
344362
create_source_sbom()
345363
create_externals_sbom()
346364

0 commit comments

Comments
 (0)