-
Notifications
You must be signed in to change notification settings - Fork 2
[ACIX-1061] Create BuildMetadata class for keeping track of build artifact's metadata
#185
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
Changes from 11 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
dac06e3
feat(build): Add `build` module and `BuildMetadata` class + tests
Ishirui 6e8f1c9
feat(build): Use UUIDs for `BuildMetadata` IDs
Ishirui cea5443
feat(build): Add `BuildMetadata.to_file` method
Ishirui a64d548
feat(build): Add `file_hash` to `BuildMetadata` schema
Ishirui 709f50b
feat(git): Add `__len__` and `__bool__` to `ChangeSet`
Ishirui a6a463b
feat(build): Add `BuildMetadata.get_canonical_filename` method
Ishirui d2d90e8
feat(build): Add `ANY` values to `OS` and `Arch` enums
Ishirui 6ee94f4
feat(build): Default `to_file` to writing to a canonical filename
Ishirui 5f5c55b
refactor(build): Allow passing build components as arguments to `Buil…
Ishirui 6cf4ade
feat(build): Include worktree hash digest in canonical filename
Ishirui 1075e38
refactor(build): Make `Platform` a fully-fledged `Struct`
Ishirui c37d12e
refactor(build): Remove useless enum values + rename `ArtifactFormat.…
Ishirui 7597230
refactor(build): Move source info and uuid to end of `get_canonical_f…
Ishirui 67227fa
feat(fs): Create `Path.hexdigest` method + tests + use it for metadat…
Ishirui f844c10
refactor(metadata): Improve definition of `ArtifactFormat` and `Artif…
Ishirui 9d5eff5
feat(build): Support format-specific digest methods
Ishirui 3952ec8
feat(build): Support `OTHER` value in enum fields
Ishirui 4700548
refactor(build): Move digest-related logic to own file, and rename `e…
Ishirui 43fbb45
refactor(build): Split `BuildMetadata.this` into two
Ishirui 88ce1ce
feat(build): Add tests for decoding `OTHER` enum values
Ishirui 7ffd638
fix: linter issues
Ishirui 1ac971d
fix(fs): Fix `utils.fs` issues on Windows
Ishirui d9b5962
refactor(git): Remove `ChangeSet.__len__` and `ChangeSet.__bool__`
Ishirui df5316d
refactor(build): Rename `comp` to `bin`, following internal discussions
Ishirui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # SPDX-FileCopyrightText: 2025-present Datadog, Inc. <[email protected]> | ||
| # | ||
| # SPDX-License-Identifier: MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # SPDX-FileCopyrightText: 2025-present Datadog, Inc. <[email protected]> | ||
| # | ||
| # SPDX-License-Identifier: MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| # SPDX-FileCopyrightText: 2025-present Datadog, Inc. <[email protected]> | ||
| # | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| from enum import StrEnum, auto | ||
| from typing import ClassVar | ||
|
|
||
| from msgspec import Struct | ||
|
|
||
|
|
||
| class ArtifactType(StrEnum): | ||
| """ | ||
| The type of the build artifact, one of: | ||
| - `comp` (component) | ||
| - `dist` (distribution) | ||
| - `other` for miscellaneous artifacts: source code tarball, configuration files, etc. | ||
| """ | ||
|
|
||
| COMP = auto() | ||
| DIST = auto() | ||
| OTHER = auto() | ||
|
|
||
|
|
||
| class ArtifactFormat(StrEnum): | ||
| """ | ||
| The format of the build artifact. | ||
| """ | ||
|
|
||
| BIN = auto() | ||
| SRC = auto() # Source code tarball | ||
| DEB = auto() | ||
| RPM = auto() | ||
| MSI = auto() | ||
| CFG = auto() # Configuration files tarball | ||
Ishirui marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| DOCKER = auto() # Docker container image | ||
Ishirui marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def validate_for_type(self, artifact_type: ArtifactType) -> None: | ||
Ishirui marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """ | ||
| Validate that the artifact format is valid for the given artifact type. | ||
| """ | ||
| match artifact_type: | ||
| case ArtifactType.COMP: | ||
| if self not in {self.BIN, self.SRC}: | ||
| msg = f"Invalid artifact format for component artifact: {self}" | ||
| raise ValueError(msg) | ||
| case ArtifactType.DIST: | ||
| if self not in {self.DEB, self.RPM, self.MSI, self.DOCKER}: | ||
| msg = f"Invalid artifact format for distribution artifact: {self}" | ||
| raise ValueError(msg) | ||
| case ArtifactType.OTHER: | ||
| if self not in {self.SRC, self.CFG}: | ||
| msg = f"Invalid artifact format for other artifact: {self}" | ||
| raise ValueError(msg) | ||
|
|
||
| def get_file_identifier(self) -> str: | ||
| """ | ||
| Get the file identifier for the artifact format. | ||
| This is the string that will be used to identify the artifact format in the filename. | ||
| This usually corresponds to the file extension, but can include some other charactres before it. | ||
| """ | ||
| match self: | ||
| case self.BIN: | ||
| return "" | ||
| case self.SRC: | ||
| return "-source.tar.gz" | ||
| case self.DEB: | ||
| return ".deb" | ||
| case self.RPM: | ||
| return ".rpm" | ||
| case self.MSI: | ||
| return ".msi" | ||
| case self.CFG: | ||
| return "-config.tar.gz" | ||
| case self.DOCKER: | ||
| return "-dockerimage.tar.gz" | ||
| # Adding a default return value to satisfy mypy, even though we should never reach here | ||
| return "" | ||
|
|
||
|
|
||
| class OS(StrEnum): | ||
| """ | ||
| The operating system for which the build artifact is intended. | ||
| """ | ||
|
|
||
| LINUX = auto() | ||
| WINDOWS = auto() | ||
| MACOS = auto() | ||
|
|
||
| # Any OS - used for indicating compatibility with any operating system | ||
| ANY = auto() | ||
|
|
||
| @classmethod | ||
| def from_alias(cls, alias: str) -> "OS": | ||
| """ | ||
| Get the OS enum value from an alias. | ||
| """ | ||
| match alias.lower(): | ||
| case "linux": | ||
| return cls.LINUX | ||
| case "windows" | "nt" | "win": | ||
| return cls.WINDOWS | ||
| case "macos" | "darwin" | "osx": | ||
| return cls.MACOS | ||
| case "any": | ||
| return cls.ANY | ||
| case _: | ||
| msg = f"Invalid OS identifier: {alias}" | ||
| raise ValueError(msg) | ||
|
|
||
|
|
||
| class Arch(StrEnum): | ||
| """ | ||
| The CPU architecture for which the build artifact is intended. | ||
| """ | ||
|
|
||
| # x86 architectures - canonical name is amd64 | ||
| AMD64 = auto() | ||
|
|
||
| # ARM architectures - canonical name is arm64 | ||
| ARM64 = auto() | ||
|
|
||
| # ARMHF architectures | ||
| ARMHF = auto() | ||
|
|
||
| # Any architecture - used for indicating compatibility with any CPU architecture | ||
| ANY = auto() | ||
|
|
||
| @classmethod | ||
| def from_alias(cls, alias: str) -> "Arch": | ||
| """ | ||
| Get the Arch enum value from an alias. | ||
| """ | ||
| match alias.lower(): | ||
| case "amd64" | "x86_64" | "x86-64" | "x86" | "x64": | ||
| return cls.AMD64 | ||
| case "arm64" | "aarch64" | "arm" | "aarch": | ||
| return cls.ARM64 | ||
| case "any": | ||
| return cls.ANY | ||
| case _: | ||
| msg = f"Invalid Arch identifier: {alias}" | ||
| raise ValueError(msg) | ||
|
|
||
|
|
||
| class Platform(Struct, frozen=True): | ||
| """ | ||
| The platform for which the build artifact is intended. | ||
| """ | ||
|
|
||
| os: OS | ||
| arch: Arch | ||
|
|
||
| ANY: ClassVar["Platform"] | ||
|
|
||
| @classmethod | ||
| def from_alias(cls, os_alias: str, arch_alias: str) -> "Platform": | ||
| """ | ||
| Get the Platform enum value from an alias. | ||
| """ | ||
| return cls(os=OS.from_alias(os_alias), arch=Arch.from_alias(arch_alias)) | ||
|
|
||
| def __str__(self) -> str: | ||
| """ | ||
| Get the string representation of the platform. | ||
| """ | ||
| return f"{self.os}-{self.arch}" | ||
|
|
||
|
|
||
| # Initialize the ANY class variable after the class is fully defined | ||
| Platform.ANY = Platform(os=OS.ANY, arch=Arch.ANY) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.