[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 db42934270)

Co-authored-by: Seth Michael Larson <seth@python.org>
This commit is contained in:
Miss Islington (bot) 2024-09-03 01:15:48 +02:00 committed by GitHub
parent 59e2a0922b
commit f8124237e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 0 deletions

View 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()