Skip to content

gh-123458: Skip SBOM generation if no git repository is detected #123507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Tools/build/generate_sbom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()

Expand Down
Loading