Skip to content

Commit db42934

Browse files
authored
gh-123458: Skip SBOM generation if no git repository is detected (#123507)
1 parent fbb26f0 commit db42934

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Tools/build/generate_sbom.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,19 @@ def error_if(value: bool, error_message: str) -> None:
9393
sys.exit(1)
9494

9595

96+
def is_root_directory_git_index() -> bool:
97+
"""Checks if the root directory is a git index"""
98+
try:
99+
subprocess.check_call(
100+
["git", "-C", str(CPYTHON_ROOT_DIR), "rev-parse"],
101+
stdout=subprocess.DEVNULL,
102+
stderr=subprocess.DEVNULL,
103+
)
104+
except subprocess.CalledProcessError:
105+
return False
106+
return True
107+
108+
96109
def filter_gitignored_paths(paths: list[str]) -> list[str]:
97110
"""
98111
Filter out paths excluded by the gitignore file.
@@ -338,6 +351,11 @@ def create_externals_sbom() -> None:
338351

339352

340353
def main() -> None:
354+
# Don't regenerate the SBOM if we're not a git repository.
355+
if not is_root_directory_git_index():
356+
print("Skipping SBOM generation due to not being a git repository")
357+
return
358+
341359
create_source_sbom()
342360
create_externals_sbom()
343361

0 commit comments

Comments
 (0)