Skip to content

Instantly share code, notes, and snippets.

@yawillianpsb
Created May 20, 2021 18:34
Show Gist options
  • Save yawillianpsb/fb51e7f1a957e903e27235e2864d2035 to your computer and use it in GitHub Desktop.
Save yawillianpsb/fb51e7f1a957e903e27235e2864d2035 to your computer and use it in GitHub Desktop.
import Foundation
guard let scheme = CommandLine.arguments
.first(where: { $0.starts(with: "scheme_") })?
.dropFirst(7) else {
print("⁉️ empty schemes")
print("exit(1)")
exit(1)
}
let reportUrl = URL(string: "file://"+FileManager.default.currentDirectoryPath+"/tests/\(scheme)_report/coverage_result/report.json")!
let nf = NumberFormatter()
nf.maximumFractionDigits = 13
guard
let data = try? Data(contentsOf: reportUrl),
let jsonDict = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let coverage = jsonDict["coverage"] as? Double,
let stringCov = nf.string(from: NSNumber(value: coverage * 100))?
.replacingOccurrences(of: ",", with: ".")
else {
print("⛔️ failed parsing coverage percantage", reportUrl.path)
print("exit(1)")
exit(1)
}
print("(\(stringCov)%) covered")
let coverageFolder = FileManager.default.currentDirectoryPath+"/coverage/"
let coveragePercertFileUrl = URL(string: "file://\(coverageFolder).current")!
do {
try FileManager.default.createDirectory(atPath: coverageFolder, withIntermediateDirectories: true, attributes: nil)
try stringCov.write(to: coveragePercertFileUrl, atomically: true, encoding: .utf8)
} catch {
print("⛔️ failed writing coverage percent to", coveragePercertFileUrl.path)
print("error: ", error)
print("exit(1)")
exit(1)
}
print("✅ coverage written")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment