-
Notifications
You must be signed in to change notification settings - Fork 22
/
Package.swift
77 lines (70 loc) · 2.51 KB
/
Package.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// swift-tools-version:5.10
import Foundation
import PackageDescription
let package = Package(
name: "WordPressShared",
platforms: [.iOS(.v13), .macOS(.v12)],
products: [
.library(name: "WordPressShared", targets: ["WordPressShared"])
],
dependencies: [
.package(url: "https://github.com/buildkite/test-collector-swift", from: "0.3.0"),
.package(url: "https://github.com/realm/SwiftLint", exact: loadSwiftLintVersion())
],
targets: [
.target(
name: "WordPressSharedObjC",
resources: [.process("Resources")]
),
.target(
name: "WordPressShared",
dependencies: [
.target(name: "WordPressSharedObjC"),
],
resources: [.process("Resources")],
plugins: [
.plugin(name: "SwiftLintPlugin", package: "SwiftLint")
]
),
.testTarget(
name: "WordPressSharedTests",
dependencies: [
.target(name: "WordPressShared"),
.product(name: "BuildkiteTestCollector", package: "test-collector-swift")
],
plugins: [
.plugin(name: "SwiftLintPlugin", package: "SwiftLint")
]
),
.testTarget(
name: "WordPressSharedObjCTests",
dependencies: [
.target(name: "WordPressShared"),
.product(name: "BuildkiteTestCollector", package: "test-collector-swift")
],
resources: [.process("Resources")],
plugins: [
.plugin(name: "SwiftLintPlugin", package: "SwiftLint")
]
),
]
)
func loadSwiftLintVersion() -> Version {
let swiftLintConfigURL = URL(fileURLWithPath: #file)
.deletingLastPathComponent()
.appendingPathComponent(".swiftlint.yml")
guard let yamlString = try? String(contentsOf: swiftLintConfigURL) else {
fatalError("Failed to read SwiftLint config file at \(swiftLintConfigURL).")
}
guard let versionLine = yamlString.components(separatedBy: .newlines)
.first(where: { $0.contains("swiftlint_version") }) else {
fatalError("SwiftLint version not found in YAML file.")
}
// Assumes the format `swiftlint_version: <version>`
guard let version = Version(versionLine.components(separatedBy: ":")
.last?
.trimmingCharacters(in: .whitespaces) ?? "") else {
fatalError("Failed to extract SwiftLint version.")
}
return version
}