@@ -26,18 +26,24 @@ struct Release: AsyncParsableCommand {
26
26
mutating func run( ) async throws {
27
27
info ( " Build directory: \( buildDirectory. path ( ) ) " )
28
28
29
- let libraryDirectory = try buildLibrary ( )
30
- let ( zipFileURL, checksum) = try zipBinary ( at: libraryDirectory )
29
+ let library = try buildLibrary ( )
30
+ let ( zipFileURL, checksum) = try zipBinary ( at: library . directory )
31
31
32
- try await updatePackage ( from : libraryDirectory , checksum: checksum)
33
- let commitHash = try commitAndPush ( )
34
- try await makeRelease ( at : commitHash , uploading: zipFileURL)
32
+ try await updatePackage ( with : library , checksum: checksum)
33
+ try commitAndPush ( with : library )
34
+ try await makeRelease ( with : library , uploading: zipFileURL)
35
35
}
36
36
37
- mutating func buildLibrary( ) throws -> URL {
37
+ mutating func buildLibrary( ) throws -> LibraryInfo {
38
+ let commitHash = try run ( command: " git rev-parse HEAD " , directory: buildDirectory) !. trimmingCharacters ( in: . whitespacesAndNewlines)
39
+ let branch = try run ( command: " git rev-parse --abbrev-ref HEAD " , directory: buildDirectory) !. trimmingCharacters ( in: . whitespacesAndNewlines)
40
+
41
+ info ( " Building \( branch) at \( commitHash) " )
42
+
38
43
// unset fixes an issue where swift compilation prevents building for targets other than macOS X
39
44
try run ( command: " unset SDKROOT && cargo xtask swift build-framework --release " , directory: buildDirectory)
40
- return buildDirectory. appending ( component: " bindings/apple/generated/ " )
45
+
46
+ return LibraryInfo ( commitHash: commitHash, branch: branch, directory: buildDirectory. appending ( component: " bindings/apple/generated/ " ) )
41
47
}
42
48
43
49
mutating func zipBinary( at libraryDirectory: URL ) throws -> ( URL , String ) {
@@ -55,9 +61,9 @@ struct Release: AsyncParsableCommand {
55
61
return ( zipFileURL, checksum)
56
62
}
57
63
58
- func updatePackage( from libraryDirectory : URL , checksum: String ) async throws {
64
+ func updatePackage( with library : LibraryInfo , checksum: String ) async throws {
59
65
info ( " Copying sources " )
60
- let source = libraryDirectory . appending ( component: " swift " , directoryHint: . isDirectory)
66
+ let source = library . directory . appending ( component: " swift " , directoryHint: . isDirectory)
61
67
let destination = packageDirectory. appending ( component: " Sources/MatrixRustSDK " , directoryHint: . isDirectory)
62
68
try run ( command: " rsync -a --delete ' \( source. path ( ) ) ' ' \( destination. path ( ) ) ' " )
63
69
@@ -80,20 +86,15 @@ struct Release: AsyncParsableCommand {
80
86
try updatedManifest. write ( to: manifestURL, atomically: true , encoding: . utf8)
81
87
}
82
88
83
- mutating func commitAndPush( ) throws -> String {
84
- let commitHash = try run ( command: " git rev-parse HEAD " , directory: buildDirectory) !. trimmingCharacters ( in: . whitespacesAndNewlines)
85
- let branch = try run ( command: " git rev-parse --abbrev-ref HEAD " , directory: buildDirectory) !. trimmingCharacters ( in: . whitespacesAndNewlines)
86
-
89
+ mutating func commitAndPush( with library: LibraryInfo ) throws {
87
90
info ( " Pushing changes " )
88
91
try run ( command: " git add Package.swift " )
89
92
try run ( command: " git add Sources " )
90
- try run ( command: " git commit -m 'Bump to version \( version) (matrix-rust-sdk/ \( branch) \( commitHash) )' " )
93
+ try run ( command: " git commit -m 'Bump to version \( version) (matrix-rust-sdk/ \( library . branch) \( library . commitHash) )' " )
91
94
try run ( command: " git push " )
92
-
93
- return commitHash
94
95
}
95
96
96
- func makeRelease( at commitHash : String , uploading zipFileURL: URL ) async throws {
97
+ func makeRelease( with library : LibraryInfo , uploading zipFileURL: URL ) async throws {
97
98
info ( " Making release " )
98
99
let url = URL ( string: " https://api.github.com/repos " ) !
99
100
. appending ( path: packageRepo)
@@ -108,7 +109,7 @@ struct Release: AsyncParsableCommand {
108
109
let body = GitHubReleaseRequest ( tagName: version,
109
110
targetCommitish: " main " ,
110
111
name: version,
111
- body: " https://github.com/matrix-org/matrix-rust-sdk/tree/ \( commitHash) " ,
112
+ body: " https://github.com/matrix-org/matrix-rust-sdk/tree/ \( library . commitHash) " ,
112
113
draft: false ,
113
114
prerelease: false ,
114
115
generateReleaseNotes: false ,
@@ -192,6 +193,12 @@ struct Release: AsyncParsableCommand {
192
193
}
193
194
}
194
195
196
+ struct LibraryInfo {
197
+ let commitHash : String
198
+ let branch : String
199
+ let directory : URL
200
+ }
201
+
195
202
enum ReleaseError : Error {
196
203
case commandFailure( command: String , directory: URL )
197
204
case httpResponse( Int )
0 commit comments