-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(.builders): store hashes of all dependency resolution inputs in metadata.json #22952
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| RESOLUTION_DIR = REPO_DIR / '.deps' | ||
| LOCK_FILE_DIR = RESOLUTION_DIR / 'resolved' | ||
| DIRECT_DEP_FILE = REPO_DIR / 'agent_requirements.in' | ||
| WORKFLOW_FILE = REPO_DIR / '.github/workflows/resolve-build-deps.yaml' | ||
| CACHE_CONTROL = 'public, max-age=15' | ||
| VALID_PROJECT_NAME = re.compile(r'^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$', re.IGNORECASE) | ||
| UNNORMALIZED_PROJECT_NAME_CHARS = re.compile(r'[-_.]+') | ||
|
|
@@ -76,6 +77,24 @@ def hash_file(path: Path) -> str: | |
| return sha256(f.read()).hexdigest() | ||
|
|
||
|
|
||
| def hash_directory(path: Path) -> str: | ||
| """Compute a combined SHA256 hash of all files in a directory, sorted by relative path.""" | ||
| h = sha256() | ||
| for file_path in sorted(path.rglob('*')): | ||
| if file_path.is_file(): | ||
| h.update(file_path.read_bytes()) | ||
|
||
| return h.hexdigest() | ||
|
|
||
|
|
||
| def compute_input_hashes() -> dict[str, str]: | ||
| """Compute SHA256 hashes for all dependency resolution inputs.""" | ||
| return { | ||
| 'agent_requirements.in': sha256(DIRECT_DEP_FILE.read_bytes()).hexdigest(), | ||
| '.github/workflows/resolve-build-deps.yaml': sha256(WORKFLOW_FILE.read_bytes()).hexdigest(), | ||
| '.builders': hash_directory(BUILDER_DIR), | ||
| } | ||
|
|
||
|
|
||
| def _build_number_of_wheel(wheel_info: dict) -> int: | ||
| """Extract the build number from wheel information.""" | ||
| wheel_name = PurePosixPath(wheel_info['name']).stem | ||
|
|
@@ -281,6 +300,7 @@ def generate_lockfiles(targets_dir, lockfiles): | |
| with RESOLUTION_DIR.joinpath('metadata.json').open('w', encoding='utf-8') as f: | ||
| contents = json.dumps( | ||
| { | ||
| 'inputs': compute_input_hashes(), | ||
| 'sha256': sha256(DIRECT_DEP_FILE.read_bytes()).hexdigest(), | ||
| }, | ||
| indent=2, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example:
(dirty+heavy+not tested, there's probably a much better way to achieve the same)