Skip to content

Commit 89a608a

Browse files
committed
Refactor release script.
1 parent f110cb6 commit 89a608a

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

Tools/Release/Sources/Release.swift

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,24 @@ struct Release: AsyncParsableCommand {
2626
mutating func run() async throws {
2727
info("Build directory: \(buildDirectory.path())")
2828

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)
3131

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)
3535
}
3636

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+
3843
// unset fixes an issue where swift compilation prevents building for targets other than macOS X
3944
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/"))
4147
}
4248

4349
mutating func zipBinary(at libraryDirectory: URL) throws -> (URL, String) {
@@ -55,9 +61,9 @@ struct Release: AsyncParsableCommand {
5561
return (zipFileURL, checksum)
5662
}
5763

58-
func updatePackage(from libraryDirectory: URL, checksum: String) async throws {
64+
func updatePackage(with library: LibraryInfo, checksum: String) async throws {
5965
info("Copying sources")
60-
let source = libraryDirectory.appending(component: "swift", directoryHint: .isDirectory)
66+
let source = library.directory.appending(component: "swift", directoryHint: .isDirectory)
6167
let destination = packageDirectory.appending(component: "Sources/MatrixRustSDK", directoryHint: .isDirectory)
6268
try run(command: "rsync -a --delete '\(source.path())' '\(destination.path())'")
6369

@@ -80,20 +86,15 @@ struct Release: AsyncParsableCommand {
8086
try updatedManifest.write(to: manifestURL, atomically: true, encoding: .utf8)
8187
}
8288

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 {
8790
info("Pushing changes")
8891
try run(command: "git add Package.swift")
8992
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))'")
9194
try run(command: "git push")
92-
93-
return commitHash
9495
}
9596

96-
func makeRelease(at commitHash: String, uploading zipFileURL: URL) async throws {
97+
func makeRelease(with library: LibraryInfo, uploading zipFileURL: URL) async throws {
9798
info("Making release")
9899
let url = URL(string: "https://api.github.com/repos")!
99100
.appending(path: packageRepo)
@@ -108,7 +109,7 @@ struct Release: AsyncParsableCommand {
108109
let body = GitHubReleaseRequest(tagName: version,
109110
targetCommitish: "main",
110111
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)",
112113
draft: false,
113114
prerelease: false,
114115
generateReleaseNotes: false,
@@ -192,6 +193,12 @@ struct Release: AsyncParsableCommand {
192193
}
193194
}
194195

196+
struct LibraryInfo {
197+
let commitHash: String
198+
let branch: String
199+
let directory: URL
200+
}
201+
195202
enum ReleaseError: Error {
196203
case commandFailure(command: String, directory: URL)
197204
case httpResponse(Int)

0 commit comments

Comments
 (0)