diff options
author | Seth Michael Larson <seth@python.org> | 2024-09-02 19:35:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-02 19:35:30 (GMT) |
commit | db42934270c5c23be9f6804cad98dfd8234caf6f (patch) | |
tree | 5f09514e082342f3df0906dba7bc327487b84f1b /Tools/build | |
parent | fbb26f067a7a3cd6dc6eed31cce12892cc0fedbb (diff) | |
download | cpython-db42934270c5c23be9f6804cad98dfd8234caf6f.zip cpython-db42934270c5c23be9f6804cad98dfd8234caf6f.tar.gz cpython-db42934270c5c23be9f6804cad98dfd8234caf6f.tar.bz2 |
gh-123458: Skip SBOM generation if no git repository is detected (#123507)
Diffstat (limited to 'Tools/build')
-rw-r--r-- | Tools/build/generate_sbom.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Tools/build/generate_sbom.py b/Tools/build/generate_sbom.py index 88f311b..020f874 100644 --- a/Tools/build/generate_sbom.py +++ b/Tools/build/generate_sbom.py @@ -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. @@ -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() |