Skip to content

Commit 6c9bb14

Browse files
committed
add script to detect Xcode Version in swift
1 parent ab7c383 commit 6c9bb14

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

Xcode/check-xcode-version.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env xcrun --sdk macosx swift
2+
3+
import Foundation
4+
5+
let env = ProcessInfo.processInfo.environment
6+
7+
guard
8+
let path = env["PROJECT_DIR"],
9+
var url = URL(string: "file://" + path),
10+
let xcodeVersion = env["XCODE_VERSION_ACTUAL"] else {
11+
exit(0)
12+
}
13+
14+
url.appendPathComponent("Config.json")
15+
16+
guard
17+
let data = try? Data(contentsOf: url),
18+
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
19+
let project = json["project"] as? [String: Any],
20+
let projectXcodeVersion = project["xcode_version"] as? String else {
21+
fatalError("'xcode_version' not found, please check your Config.json")
22+
}
23+
24+
let xcodeVersionCleaned = xcodeVersion.trimmingCharacters(in: .init(charactersIn: "0"))
25+
let projectXcodeVersionCleaned = projectXcodeVersion.replacingOccurrences(of: ".", with: "")
26+
27+
if (xcodeVersionCleaned != projectXcodeVersionCleaned) {
28+
fatalError("Xcode Version mismatch: please open Project with Xcode \(projectXcodeVersion) or change Xcode Version in Config.json")
29+
}
30+
31+
exit(0)

setup-common-project-files.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,5 @@ if [ $copyPRTemplate = true ]; then
151151
fi
152152

153153
if [ $checkXcodeVersion = true ]; then
154-
./Xcode/check-xcode-version.sh "$projectDir" || exit 1;
154+
./Xcode/check-xcode-version.swift;
155155
fi

0 commit comments

Comments
 (0)