OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[GHA] Store sha-256 checksums for artifacts (#29122)
Alina Kladieva9b44e485c156
diff --git a/.github/actions/store_artifacts/store_artifacts.py b/.github/actions/store_artifacts/store_artifacts.pyindex 7b761d042b6..ff796bee4f5 100644--- a/.github/actions/store_artifacts/store_artifacts.py+++ b/.github/actions/store_artifacts/store_artifacts.py@@ -4,6 +4,7 @@from __future__ import annotationsimport argparse+import hashlibimport loggingimport osimport sys@@ -62,6 +63,33 @@ def rotate_dir(directory: Path) -> bool:return True+def generate_sha256sum(file_path: str | Path) -> str:+ """+ Generates the SHA-256 checksum for the given file.++ :param file_path: Path to the file+ :return: SHA-256 checksum as a hexadecimal string+ """+ sha256 = hashlib.sha256()+ with open(file_path, 'rb') as file:+ for chunk in iter(lambda: file.read(4096), b''):+ sha256.update(chunk)+ return sha256.hexdigest()+++def store_checksums(artifact_path: Path) -> None:+ """+ Generates SHA-256 checksums for a given artifact and stores them in separate files.++ :param artifact_path: Path to either a single artifact file or the directory with files to generate checksums for+ """+ files = [path for path in artifact_path.rglob('*') if path.is_file] if artifact_path.is_dir() else [artifact_path]+ for file in files:+ hashsum_filepath = file.with_suffix('.sha256')+ with open(hashsum_filepath, 'w') as hashsum_file:+ hashsum_file.write(generate_sha256sum(file))++def main():action_utils.init_logger()logger = logging.getLogger(__name__)@@ -79,6 +107,14 @@ def main():error_found = Falsefor artifact in args.artifacts.split():artifact_path = Path(artifact)++ logger.debug(f"Calculating checksum for {artifact_path}")+ try:+ store_checksums(artifact_path)+ except Exception as e:+ logger.error(f'Failed to calculate checksum for {artifact}: {e}')+ error_found = True+logger.debug(f"Copying {artifact_path} to {storage / artifact_path.name}")try:with preserve_stats_context():@@ -87,6 +123,9 @@ def main():else:storage.mkdir(parents=True, exist_ok=True)shutil.copy2(artifact_path, storage / artifact_path.name)+ if artifact_path.with_suffix('.sha256').exists():+ shutil.copy2(artifact_path.with_suffix('.sha256'),+ storage / artifact_path.with_suffix('.sha256').name)except Exception as e:logger.error(f'Failed to copy {artifact}: {e}')error_found = True