Skip to content

Commit add151f

Browse files
Merge pull request #37 from nikolainobadi/update-shell-kit
Update shell kit
2 parents 4651291 + 496511b commit add151f

File tree

53 files changed

+343
-422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+343
-422
lines changed

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ let package = Package(
2525
dependencies: [
2626
.package(url: "https://github.com/JohnSundell/Files", from: "4.0.0"),
2727
.package(url: "https://github.com/nikolainobadi/NnGitKit.git", from: "0.6.0"),
28-
.package(url: "https://github.com/nikolainobadi/NnShellKit.git", from: "2.0.0"),
29-
.package(url: "https://github.com/nikolainobadi/NnSwiftDataKit", from: "0.5.0"),
28+
.package(url: "https://github.com/nikolainobadi/NnShellKit.git", from: "2.2.0"),
29+
.package(url: "https://github.com/nikolainobadi/NnSwiftDataKit", exact: "0.5.0"),
3030
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"),
31-
.package(url: "https://github.com/nikolainobadi/SwiftPickerKit.git", from: "0.5.0")
31+
.package(url: "https://github.com/nikolainobadi/SwiftPickerKit.git", exact: "0.6.0")
3232
],
3333
targets: [
3434
.executableTarget(
@@ -59,7 +59,8 @@ let package = Package(
5959
.target(
6060
name: "NnexSharedTestHelpers",
6161
dependencies: [
62-
"NnexKit"
62+
"NnexKit",
63+
.product(name: "NnShellTesting", package: "NnShellKit"),
6364
]
6465
),
6566
.testTarget(

Sources/NnexKit/Archive/BinaryArchiver.swift

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
//
77

88
import Foundation
9-
import NnShellKit
109

1110
public struct BinaryArchiver {
12-
private let shell: any Shell
11+
private let shell: any NnexShell
1312

14-
public init(shell: any Shell) {
13+
public init(shell: any NnexShell) {
1514
self.shell = shell
1615
}
1716
}
@@ -37,7 +36,7 @@ public extension BinaryArchiver {
3736

3837
if fileName.hasSuffix(".tar.gz") {
3938
let removeCmd = "rm -f \"\(archived.archivePath)\""
40-
_ = try shell.bash(removeCmd)
39+
try shell.runAndPrint(bash: removeCmd)
4140
}
4241
}
4342
}
@@ -55,15 +54,11 @@ private extension BinaryArchiver {
5554
let archivePath = "\(directory)/\(archiveName)"
5655

5756
let tarCmd = "cd \"\(directory)\" && tar -czf \"\(archiveName)\" \"\(fileName)\""
58-
_ = try shell.bash(tarCmd)
57+
try shell.runAndPrint(bash: tarCmd)
5958

6059
let sha256 = try calculateSHA256(for: archivePath)
6160

62-
return ArchivedBinary(
63-
originalPath: binaryPath,
64-
archivePath: archivePath,
65-
sha256: sha256
66-
)
61+
return .init(originalPath: binaryPath, archivePath: archivePath, sha256: sha256)
6762
}
6863

6964
func determineArchiveName(for binaryPath: String, fileName: String) -> String {
@@ -85,7 +80,10 @@ private extension BinaryArchiver {
8580
let raw = try? shell.bash("shasum -a 256 \"\(filePath)\""),
8681
let sha = raw.components(separatedBy: " ").first,
8782
!sha.isEmpty
88-
else { throw NnexError.missingSha256 }
83+
else {
84+
throw NnexError.missingSha256
85+
}
86+
8987
return sha
9088
}
9189
}

Sources/NnexKit/Building/BinaryCopyUtility.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
//
77

88
import Files
9-
import NnShellKit
109

1110
public struct BinaryCopyUtility {
12-
private let shell: any Shell
11+
private let shell: any NnexShell
1312

14-
public init(shell: any Shell) {
13+
public init(shell: any NnexShell) {
1514
self.shell = shell
1615
}
1716
}
@@ -42,14 +41,14 @@ private extension BinaryCopyUtility {
4241
switch binaryOutput {
4342
case .single(let binaryInfo):
4443
let finalPath = destinationPath + "/" + executableName
45-
_ = try shell.bash("cp \"\(binaryInfo.path)\" \"\(finalPath)\"")
44+
try shell.runAndPrint(bash: "cp \"\(binaryInfo.path)\" \"\(finalPath)\"")
4645
return .single(.init(path: finalPath))
4746

4847
case .multiple(let binaries):
4948
var results: [ReleaseArchitecture: BinaryInfo] = [:]
5049
for (arch, binaryInfo) in binaries {
5150
let finalPath = destinationPath + "/" + executableName + "-\(arch.name)"
52-
_ = try shell.bash("cp \"\(binaryInfo.path)\" \"\(finalPath)\"")
51+
try shell.runAndPrint(bash: "cp \"\(binaryInfo.path)\" \"\(finalPath)\"")
5352
results[arch] = .init(path: finalPath)
5453
}
5554
return .multiple(results)

Sources/NnexKit/Building/BinaryInfo.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55
// Created by Nikolai Nobadi on 3/20/25.
66
//
77

8-
/// Represents information about a binary file.
98
public struct BinaryInfo {
10-
/// The file path to the binary.
119
public let path: String
1210

13-
/// Initializes a new instance of BinaryInfo.
14-
/// - Parameters:
15-
/// - path: The file path to the binary.
1611
public init(path: String) {
1712
self.path = path
1813
}

Sources/NnexKit/Building/BuildConfig.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,11 @@
55
// Created by Nikolai Nobadi on 3/25/25.
66
//
77

8-
/// Represents the configuration for building a project.
98
public struct BuildConfig: Sendable {
10-
/// The name of the project to build.
119
public let projectName: String
12-
/// The file path to the project directory.
1310
public let projectPath: String
14-
/// The type of build to perform (e.g., universal, arm64, x86_64).
1511
public let buildType: BuildType
16-
/// Additional arguments to pass to the build command.
1712
public let extraBuildArgs: [String]
18-
/// Indicates whether the project should be cleaned before building.
1913
public let skipClean: Bool
2014
public let testCommand: TestCommand?
2115

Sources/NnexKit/Building/BuildType.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@
55
// Created by Nikolai Nobadi on 3/22/25.
66
//
77

8-
/// Represents the build type for a project, specifying the target architecture.
98
public enum BuildType: String, CaseIterable, Sendable {
10-
/// Universal build, targeting both ARM and Intel architectures.
119
case universal
12-
13-
/// ARM64 architecture.
1410
case arm64
15-
16-
/// x86_64 architecture.
1711
case x86_64
1812
}

Sources/NnexKit/Building/ProjectBuilder.swift

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import NnShellKit
1+
//
2+
// ProjectBuilder.swift
3+
// nnex
4+
//
5+
// Created by Nikolai Nobadi on 3/21/25.
6+
//
7+
28
import Foundation
9+
import NnShellKit
310

411
public struct ProjectBuilder {
5-
private let shell: any Shell
12+
private let shell: any NnexShell
613
private let config: BuildConfig
714
private let progressDelegate: (any BuildProgressDelegate)?
815

9-
public init(shell: any Shell, config: BuildConfig, progressDelegate: (any BuildProgressDelegate)? = nil) {
16+
public init(shell: any NnexShell, config: BuildConfig, progressDelegate: (any BuildProgressDelegate)? = nil) {
1017
self.shell = shell
1118
self.config = config
1219
self.progressDelegate = progressDelegate
@@ -61,8 +68,7 @@ private extension ProjectBuilder {
6168

6269
func cleanProject() throws {
6370
log("🧹 Cleaning the project...")
64-
let output = try shell.bash("swift package clean --package-path \(config.projectPath)")
65-
if !output.isEmpty { print(output) }
71+
try shell.runAndPrint(bash: "swift package clean --package-path \(config.projectPath)")
6672
log("✅ Project cleaned.")
6773
}
6874

@@ -86,8 +92,7 @@ private extension ProjectBuilder {
8692
log("🧪 Running tests: \(testCommand)")
8793

8894
do {
89-
let output = try shell.bash(testCommand)
90-
if !output.isEmpty { print(output) }
95+
try shell.runAndPrint(bash: testCommand)
9196
log("✅ Tests completed successfully.")
9297
} catch let shellError as ShellError {
9398
// Extract test output from the shell error
@@ -113,9 +118,8 @@ private extension ProjectBuilder {
113118
log("🔨 Building for \(arch.name)...")
114119
let extra = config.extraBuildArgs.joined(separator: " ")
115120
let cmd = "swift build -c release --arch \(arch.name) -Xswiftc -Osize -Xswiftc -wmo -Xswiftc -gnone -Xswiftc -cross-module-optimization -Xlinker -dead_strip_dylibs --package-path \(config.projectPath) \(extra)"
116-
let output = try shell.bash(cmd)
117-
if !output.isEmpty { print(output) }
118121

122+
try shell.runAndPrint(bash: cmd)
119123
try stripBinary(for: arch)
120124
}
121125

@@ -127,13 +131,14 @@ private extension ProjectBuilder {
127131
log("✂️ Stripping binary for \(arch.name)...")
128132
let binaryPath = binaryPath(for: arch)
129133
let stripCmd = "strip -x \"\(binaryPath)\""
130-
let output = try shell.bash(stripCmd)
131-
if !output.isEmpty { print(output) }
134+
135+
try shell.runAndPrint(bash: stripCmd)
132136
log("✅ Binary stripped for \(arch.name).")
133137
}
134-
135138
}
136139

140+
141+
// MARK: - Dependencies
137142
public enum BinaryOutput {
138143
case single(BinaryInfo)
139144
case multiple([ReleaseArchitecture: BinaryInfo])
@@ -156,12 +161,17 @@ public struct TestFailureError: Error, LocalizedError {
156161
}
157162
}
158163

164+
165+
// MARK: - Extension Dependencies
159166
private extension BuildType {
160167
var archs: [ReleaseArchitecture] {
161168
switch self {
162-
case .arm64: return [.arm]
163-
case .x86_64: return [.intel]
164-
case .universal: return [.arm, .intel]
169+
case .arm64:
170+
return [.arm]
171+
case .x86_64:
172+
return [.intel]
173+
case .universal:
174+
return [.arm, .intel]
165175
}
166176
}
167177
}

Sources/NnexKit/Formula/PublishUtilities.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import Files
99
import Foundation
10-
import NnShellKit
1110

1211
public enum PublishUtilities {
1312
/// Builds the binary for the given project and formula.
@@ -18,7 +17,7 @@ public enum PublishUtilities {
1817
/// - shell: The shell instance to use for building.
1918
/// - Returns: The binary output including path(s) and hash(es).
2019
/// - Throws: An error if the build process fails.
21-
public static func buildBinary(formula: SwiftDataFormula, buildType: BuildType, skipTesting: Bool, shell: any Shell) throws -> BinaryOutput {
20+
public static func buildBinary(formula: SwiftDataFormula, buildType: BuildType, skipTesting: Bool, shell: any NnexShell) throws -> BinaryOutput {
2221
let testCommand = skipTesting ? nil : formula.testCommand
2322
let config = BuildConfig(projectName: formula.name, projectPath: formula.localProjectPath, buildType: buildType, extraBuildArgs: formula.extraBuildArgs, skipClean: false, testCommand: testCommand)
2423
let builder = ProjectBuilder(shell: shell, config: config)
@@ -32,7 +31,7 @@ public enum PublishUtilities {
3231
/// - shell: The shell instance to use for archiving.
3332
/// - Returns: An array of archived binaries.
3433
/// - Throws: An error if archive creation fails.
35-
public static func createArchives(from binaryOutput: BinaryOutput, shell: any Shell) throws -> [ArchivedBinary] {
34+
public static func createArchives(from binaryOutput: BinaryOutput, shell: any NnexShell) throws -> [ArchivedBinary] {
3635
let archiver = BinaryArchiver(shell: shell)
3736

3837
switch binaryOutput {

Sources/NnexKit/Git/DefaultGitHandler.swift

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,12 @@
77

88
import Foundation
99
import GitShellKit
10-
import NnShellKit
1110

12-
/// Default implementation of the GitHandler protocol, providing Git-related operations.
1311
public struct DefaultGitHandler {
14-
private let shell: any Shell
15-
private let gitShell: any GitShell
12+
private let shell: any NnexShell
1613

17-
/// Initializes a new instance of DefaultGitHandler with the specified shell.
18-
/// - Parameter shell: The shell used to execute commands.
19-
public init(shell: any Shell) {
14+
public init(shell: any NnexShell) {
2015
self.shell = shell
21-
self.gitShell = GitShellAdapter(shell: shell)
2216
}
2317
}
2418

@@ -30,16 +24,16 @@ extension DefaultGitHandler: GitHandler {
3024
/// - message: The commit message describing the changes.
3125
/// - path: The file path of the repository.
3226
public func commitAndPush(message: String, path: String) throws {
33-
_ = try shell.bash(makeGitCommand(.addAll, path: path))
34-
_ = try shell.bash(makeGitCommand(.commit(message: message), path: path))
35-
_ = try shell.bash(makeGitCommand(.push, path: path))
27+
try shell.runAndPrint(bash: makeGitCommand(.addAll, path: path))
28+
try shell.runAndPrint(bash: makeGitCommand(.commit(message: message), path: path))
29+
try shell.runAndPrint(bash: makeGitCommand(.push, path: path))
3630
}
3731

3832
/// Retrieves the remote URL of the repository located at the given path.
3933
/// - Parameter path: The file path of the repository.
4034
/// - Returns: A string representing the remote URL.
4135
public func getRemoteURL(path: String) throws -> String {
42-
return try gitShell.getGitHubURL(at: path)
36+
return try shell.getGitHubURL(at: path)
4337
}
4438

4539
/// Retrieves the previous release version from the repository at the given path.
@@ -52,7 +46,7 @@ extension DefaultGitHandler: GitHandler {
5246
/// Initializes a new Git repository at the given path.
5347
/// - Parameter path: The file path where the repository should be initialized.
5448
public func gitInit(path: String) throws {
55-
try GitStarter(path: path, shell: gitShell).gitInit()
49+
try GitStarter(path: path, shell: shell).gitInit()
5650
}
5751

5852
/// Initializes a new remote repository on GitHub with specified details and returns the repository URL.
@@ -64,7 +58,7 @@ extension DefaultGitHandler: GitHandler {
6458
/// - Returns: A string representing the repository URL.
6559
public func remoteRepoInit(tapName: String, path: String, projectDetails: String, visibility: RepoVisibility) throws -> String {
6660
let info = RepoInfo(name: tapName, details: projectDetails, visibility: visibility, canUploadFromNonMainBranch: false)
67-
return try GitHubRepoStarter(path: path, shell: gitShell, repoInfo: info).repoInit()
61+
return try GitHubRepoStarter(path: path, shell: shell, repoInfo: info).repoInit()
6862
}
6963

7064
/// Creates a new release with one or more archived binaries and returns all asset URLs.
@@ -102,7 +96,7 @@ private extension DefaultGitHandler {
10296
// Create the release and upload all archives at once
10397
let quotedArchivePaths = archivedBinaries.map { "\"\($0.archivePath)\"" }.joined(separator: " ")
10498
let createCmd = "cd \"\(path)\" && gh release create \(version) \(quotedArchivePaths) --title \"\(version)\" \(notesParam)"
105-
_ = try shell.bash(createCmd)
99+
try shell.runAndPrint(bash: createCmd)
106100

107101
// Clean up archive files after upload
108102
let archiver = BinaryArchiver(shell: shell)

0 commit comments

Comments
 (0)