-
Notifications
You must be signed in to change notification settings - Fork 0
chore: add Asset to Dependency #13
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 all commits
Commits
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
109 changes: 96 additions & 13 deletions
109
Sources/BinaryDependencyManager/Models/Dependency.swift
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 |
|---|---|---|
| @@ -1,22 +1,105 @@ | ||
| // Dependency representation | ||
| struct Dependency: Codable { | ||
|
|
||
| /// Repository in format "owner/repo" i.e. "MyRepo/MyAwesomeLibrary" | ||
| /// Dependency representation | ||
| struct Dependency: Equatable { | ||
| /// Repository in format "owner/repo" i.e. "MacPaw/CMMX-Panther-Engine" | ||
| let repo: String | ||
|
|
||
| /// Tag in format "0.0.47", Basically a release | ||
| let tag: String | ||
|
|
||
| /// Sha256 checksum of the zip archive | ||
| let checksum: String | ||
| /// List of assets to download. | ||
| let assets: [Asset] | ||
| } | ||
|
|
||
| // MARK: Decodable | ||
|
|
||
| extension Dependency: Decodable { | ||
| private enum CodingKeys: String, CodingKey { | ||
| case repo | ||
| case tag | ||
| case assets | ||
| } | ||
|
|
||
| init(from decoder: Decoder) throws { | ||
| let container = try decoder.container(keyedBy: CodingKeys.self) | ||
| self.repo = try container.decode(String.self, forKey: .repo) | ||
| self.tag = try container.decode(String.self, forKey: .tag) | ||
| var assets = try container.decodeIfPresent([Asset].self, forKey: .assets) ?? [] | ||
|
|
||
| // If there are no nested assets, try to decode a single asset params from the dependency level. | ||
| if assets.isEmpty { | ||
| assets = try [Asset(from: decoder)] | ||
| } | ||
|
|
||
| self.assets = assets | ||
| } | ||
| } | ||
|
|
||
| // MARK: Encodable | ||
|
|
||
| /// Optional. If provided, the contents of `contents` director in archive will be copied to output directory | ||
| let contents: String? | ||
| extension Dependency: Encodable { | ||
| func encode(to encoder: Encoder) throws { | ||
| var container = encoder.container(keyedBy: CodingKeys.self) | ||
| try container.encode(repo, forKey: .repo) | ||
| try container.encode(tag, forKey: .tag) | ||
| try container.encode(assets, forKey: .assets) | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Dependency.Asset | ||
|
|
||
| extension Dependency { | ||
| struct Asset: Equatable { | ||
| /// SHA-256 checksum of the zip archive. | ||
| let checksum: String | ||
| /// Regex pattern to a specific artifact, if multiple artifacts are added to the the release assets. | ||
| let pattern: String? | ||
| /// If provided, the contents of `contents` directory in the Source Code archive will be copied to output directory. | ||
| /// - Warning: if provided it takes precedence over the `pattern`. | ||
| let contents: String? | ||
| /// Custom output directory for the asset. | ||
| let outputDirectory: String? | ||
|
|
||
| init ( | ||
| checksum: String, | ||
| pattern: String? = nil, | ||
| contents: String? = nil, | ||
| outputDirectory: String? = nil | ||
| ) { | ||
| self.checksum = checksum | ||
| self.pattern = pattern | ||
| self.contents = contents | ||
| self.outputDirectory = outputDirectory | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // MARK: Decodable | ||
|
|
||
| extension Dependency.Asset: Decodable { | ||
| private enum CodingKeys: String, CodingKey { | ||
| case checksum | ||
| case pattern | ||
| case contents | ||
| case outputDirectory = "output" | ||
| } | ||
|
|
||
| init(from decoder: any Decoder) throws { | ||
| let container = try decoder.container(keyedBy: CodingKeys.self) | ||
| self.checksum = try container.decode(String.self, forKey: .checksum) | ||
| self.pattern = try container.decodeIfPresent(String.self, forKey: .pattern) | ||
| self.contents = try container.decodeIfPresent(String.self, forKey: .contents) | ||
| self.outputDirectory = try container.decodeIfPresent(String.self, forKey: .outputDirectory) | ||
| } | ||
| } | ||
|
|
||
| /// Optional. This can be used to select specific artifact, if multiple artifacts are added to the the release | ||
| let pattern: String? | ||
| // MARK: Encodable | ||
|
|
||
| /// Optional. Іf defined, the subdirectory with a given name will be created inside download directory. | ||
| /// Use when you want to download multiple artifacts from the same repository. | ||
| let output: String? | ||
| extension Dependency.Asset: Encodable { | ||
| func encode(to encoder: any Encoder) throws { | ||
| var container = encoder.container(keyedBy: CodingKeys.self) | ||
| try container.encode(checksum, forKey: .checksum) | ||
| try container.encodeIfPresent(pattern, forKey: .pattern) | ||
| try container.encodeIfPresent(contents, forKey: .contents) | ||
| try container.encodeIfPresent(outputDirectory, forKey: .outputDirectory) | ||
| } | ||
| } | ||
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.
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.
this should probably go with the tests
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.
Already done it in #9/files/BinaryDependenciesConfigurationTests