diff --git a/Sources/SwiftPolyglot/main.swift b/Sources/SwiftPolyglot/main.swift index 4aacad6..34110a1 100755 --- a/Sources/SwiftPolyglot/main.swift +++ b/Sources/SwiftPolyglot/main.swift @@ -5,6 +5,7 @@ guard CommandLine.arguments.count > 1 else { exit(1) } +let isRunningFromGitHubActions = ProcessInfo.processInfo.environment["GITHUB_ACTIONS"] == "true" let languages = CommandLine.arguments[1].split(separator: ",").map(String.init) let errorOnMissing = CommandLine.arguments.contains("--errorOnMissing") @@ -19,13 +20,17 @@ func checkTranslations(in fileURL: URL, for languages: [String]) { let jsonDict = jsonObject as? [String: Any], let strings = jsonDict["strings"] as? [String: [String: Any]] else { - print("Could not process file: \(fileURL.path)") + if isRunningFromGitHubActions { + print("::warning file=\(fileURL.path)::Could not process file at path: \(fileURL.path)") + } else { + print("Could not process file at path: \(fileURL.path)") + } return } for (originalString, translations) in strings { guard let localizations = translations["localizations"] as? [String: [String: Any]] else { - print("Warning: '\(originalString)' is not translated in any language in file: \(fileURL.absoluteString)") + logWarning(file: fileURL.path, message: "'\(originalString)' is not translated in any language in file: \(fileURL.path)") missingTranslations = true continue } @@ -36,7 +41,7 @@ func checkTranslations(in fileURL: URL, for languages: [String]) { let state = stringUnit["state"] as? String, state == "translated" { } else { - print("Warning: '\(originalString)' is missing or not translated in \(lang) in file: \(fileURL.absoluteString)") + logWarning(file: fileURL.path, message: "'\(originalString)' is missing or not translated in \(lang) in file: \(fileURL.path)") missingTranslations = true } } @@ -54,6 +59,18 @@ func searchDirectory(_ dirPath: String) { } } +func logWarning(file: String, message: String) { + if isRunningFromGitHubActions { + if errorOnMissing { + print("::error file=\(file)::\(message)") + } else { + print("::warning file=\(file)::\(message)") + } + } else { + print(message) + } +} + searchDirectory(currentDirectoryPath) if missingTranslations, errorOnMissing {