-
Notifications
You must be signed in to change notification settings - Fork 7
/
Dangerfile.swift
63 lines (52 loc) · 1.9 KB
/
Dangerfile.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
import Danger
import DangerSwiftCoverage
import Foundation
let danger = Danger()
lint()
coverage()
xcodeEnvironmentVariables()
changedFiles()
func changedFiles() {
message("Edited \(danger.git.modifiedFiles.count) files")
message("Created \(danger.git.createdFiles.count) files")
}
func lint() {
let violations = SwiftLint.lint(.all(directory: "./"), inline: true, configFile: ".swiftlint.yml", strict: true, quiet: false)
if violations.isEmpty {
message("No SwiftLint violations! 🎉")
}
}
func coverage() {
guard let xcresult = ProcessInfo.processInfo.environment["BITRISE_XCRESULT_PATH"]?.escapeString() else {
fail("Could not get the BITRISE_XCRESULT_PATH to generage code coverage")
return
}
Coverage.xcodeBuildCoverage(
.xcresultBundle(xcresult),
minimumCoverage: 50
)
}
func xcodeEnvironmentVariables() {
message("Checking XCode Environment Variables")
let snowplowPostPath = #"""
key = "SNOWPLOW_POST_PATH"
value = "com.snowplowanalytics.snowplow/tp2"
isEnabled = "YES">
"""#
let modifiedXcodeSchemes = danger.git.modifiedFiles.filter { $0.contains(".xcscheme") }
for scheme in modifiedXcodeSchemes where danger.utils.readFile(scheme).contains(snowplowPostPath) {
fail("SNOWPLOW_POST_PATH must be disabled")
}
}
extension String {
// Helper function to escape (iOS) in our file name for xcov.
func escapeString() -> String {
var newString = self.replacingOccurrences(of: "(", with: "\\(")
newString = newString.replacingOccurrences(of: ")", with: "\\)")
newString = newString.replacingOccurrences(of: " ", with: "\\ ")
return newString
}
}