|
12 | 12 | import functools
|
13 | 13 | import getpass
|
14 | 14 | import itertools
|
| 15 | +import json |
15 | 16 | import os
|
16 | 17 | import pathlib
|
17 | 18 | import re
|
|
34 | 35 |
|
35 | 36 | import release as release_mod
|
36 | 37 | from buildbotapi import BuildBotAPI
|
| 38 | +import sbom |
37 | 39 |
|
38 | 40 | API_KEY_REGEXP = re.compile(r"(?P<major>\w+):(?P<minor>\w+)")
|
39 | 41 |
|
@@ -486,6 +488,26 @@ def test_release_artifacts(db: DbfilenameShelf) -> None:
|
486 | 488 | raise ReleaseException("Test failed!")
|
487 | 489 |
|
488 | 490 |
|
| 491 | +def build_sbom_artifacts(db): |
| 492 | + |
| 493 | + # Skip building an SBOM if there isn't an 'Misc/sbom.spdx.json' file. |
| 494 | + if not (db["git_repo"] / "Misc/sbom.spdx.json").exists(): |
| 495 | + print("Skipping building an SBOM, missing 'Misc/sbom.spdx.json'") |
| 496 | + return |
| 497 | + |
| 498 | + release_version = db["release"] |
| 499 | + # For each source tarball build an SBOM. |
| 500 | + for ext in (".tgz", ".tar.xz"): |
| 501 | + tarball_name = f"Python-{release_version}{ext}" |
| 502 | + tarball_path = str(db["git_repo"] / str(db["release"]) / "src" / tarball_name) |
| 503 | + |
| 504 | + print(f"Building an SBOM for artifact '{tarball_name}'") |
| 505 | + sbom_data = sbom.create_sbom_for_source_tarball(tarball_path) |
| 506 | + |
| 507 | + with open(tarball_path + ".spdx.json", mode="w") as f: |
| 508 | + f.write(json.dumps(sbom_data, indent=2, sort_keys=True)) |
| 509 | + |
| 510 | + |
489 | 511 | class MySFTPClient(paramiko.SFTPClient):
|
490 | 512 | def put_dir(self, source, target, progress=None):
|
491 | 513 | for item in os.listdir(source):
|
@@ -1020,6 +1042,7 @@ def _api_key(api_key):
|
1020 | 1042 | Task(create_tag, "Create tag"),
|
1021 | 1043 | Task(build_release_artifacts, "Building release artifacts"),
|
1022 | 1044 | Task(test_release_artifacts, "Test release artifacts"),
|
| 1045 | + Task(build_sbom_artifacts, "Building SBOM artifacts"), |
1023 | 1046 | Task(upload_files_to_server, "Upload files to the PSF server"),
|
1024 | 1047 | Task(place_files_in_download_folder, "Place files in the download folder"),
|
1025 | 1048 | Task(upload_docs_to_the_docs_server, "Upload docs to the PSF docs server"),
|
|
0 commit comments