SwiftTailwind/Sources/TailwindCSSCLIArtifactBundler/ArtifactBundleBuilder+File Operations.swift
laosb f9024a8cd7 fix: Add checksum to release tag and fix zip invocation
Fix zip creation so the bundle is archived with the bundle root rather
than its full path. Use a standardized zip path, set
Process.currentDirectoryURL
to the bundle's parent, and pass the bundle basename to /usr/bin/zip.
2026-01-20 23:15:34 +08:00

42 lines
1.3 KiB
Swift

import Foundation
extension ArtifactBundleBuilder {
func downloadFile(from urlString: String, to destination: String) throws {
guard let url = URL(string: urlString) else {
throw ArtifactBundleError.invalidURL(urlString)
}
let data = try Data(contentsOf: url)
try data.write(to: URL(fileURLWithPath: destination))
}
func makeExecutable(path: String) throws {
let attributes = [FileAttributeKey.posixPermissions: 0o755]
try fileManager.setAttributes(attributes, ofItemAtPath: path)
}
func createZipFile(bundleDir: String, zipPath: String) throws {
// Remove existing ZIP file if it exists
if fileManager.fileExists(atPath: zipPath) {
try fileManager.removeItem(atPath: zipPath)
}
let bundleDirURL = URL(fileURLWithPath: bundleDir)
let workDirURL = bundleDirURL.deletingLastPathComponent()
let bundleName = bundleDirURL.lastPathComponent
let process = Process()
process.executableURL = URL(fileURLWithPath: "/usr/bin/zip")
let zipPathURL = URL(fileURLWithPath: zipPath).standardizedFileURL
process.arguments = ["-r", zipPathURL.path, bundleName]
process.currentDirectoryURL = workDirURL
try process.run()
process.waitUntilExit()
guard process.terminationStatus == 0 else {
throw ArtifactBundleError.zipCreationFailed
}
}
}