Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xcode 16 support #627

Merged
merged 11 commits into from
Oct 14, 2024
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
strategy:
fail-fast: false
matrix:
xcode: ["15.2", "15.4"]
xcode: ["15.4", "16.0"]
steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -95,7 +95,7 @@ jobs:
strategy:
fail-fast: false
matrix:
xcode: ["15.2", "15.4"]
xcode: ["15.4", "16.0"]
steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -136,7 +136,7 @@ jobs:
strategy:
fail-fast: false
matrix:
swift: ["5.8", "5.9", "5.10"]
swift: ["5.9", "5.10", "6.0"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand Down Expand Up @@ -214,7 +214,7 @@ jobs:
strategy:
fail-fast: false
matrix:
xcode: ["15.2", "15.4"]
xcode: ["15.4", "16.0"]
steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -253,7 +253,7 @@ jobs:
strategy:
fail-fast: false
matrix:
swift: ["5.8", "5.9", "5.10"]
swift: ["5.9", "5.10", "6.0"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
Expand Down
14 changes: 7 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ let isDevelop = true

let swiftLint: Package.Dependency = {
#if compiler(>=5.9)
return .package(url: "https://github.com/Realm/SwiftLint", from: "0.56.0")
return .package(url: "https://github.com/Realm/SwiftLint", from: "0.56.0")
#else
return .package(url: "https://github.com/Realm/SwiftLint", exact: "0.53.0")
return .package(url: "https://github.com/Realm/SwiftLint", exact: "0.53.0")
#endif
}()

Expand All @@ -33,17 +33,17 @@ let devTargets: [Target] = isDevelop
dependencies: [
"Danger",
"DangerFixtures",
.product(name: "SnapshotTesting", package: "swift-snapshot-testing")
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
]),
.testTarget(name: "RunnerLibTests",
dependencies: [
"RunnerLib",
.product(name: "SnapshotTesting", package: "swift-snapshot-testing")
], exclude: ["__Snapshots__"]),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
], exclude: ["__Snapshots__"]),
.testTarget(name: "DangerDependenciesResolverTests",
dependencies: [
"DangerDependenciesResolver",
.product(name: "SnapshotTesting", package: "swift-snapshot-testing")
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
],
exclude: ["__Snapshots__"]),
]
Expand All @@ -70,7 +70,7 @@ let package = Package(
dependencies: [
.product(name: "OctoKit", package: "octokit.swift"),
"Logger",
"DangerShellExecutor"
"DangerShellExecutor",
]
),
.target(name: "RunnerLib", dependencies: ["Logger", "DangerShellExecutor", "Version"]),
Expand Down
8 changes: 8 additions & 0 deletions Scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ else
swift build --disable-sandbox
fi

MAJOR_VERSION=$(swift --version | awk '{print $4}' | cut -d '.' -f 1)

ARRAY=()
for ARG in "${SWIFT_LIB_FILES[@]}"; do
ARRAY+=("$BUILD_FOLDER/$ARG")
Expand All @@ -29,6 +31,12 @@ done
mkdir -p "$PREFIX/bin"
mkdir -p "$LIB_INSTALL_PATH"
cp -f "$BUILD_FOLDER/$TOOL_NAME" "$INSTALL_PATH"

if [[ $MAJOR_VERSION -ge 6 ]]; then
BUILD_FOLDER+="/Modules"
SWIFT_LIB_FILES=($(ls "$BUILD_FOLDER"))
fi

cp -fr "${ARRAY[@]}" "$LIB_INSTALL_PATH" 2>/dev/null || :

sed -e "s/$DANGER_LIB_DYNAMIC_DECLARATION/$DANGER_LIB_DECLARATION/g" Package.swift > tmpPackage
Expand Down
3 changes: 2 additions & 1 deletion Sources/Danger/Danger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ final class DangerRunner {

if !FileManager.default.createFile(atPath: outputPath,
contents: data,
attributes: nil) {
attributes: nil)
{
logger.logError("Could not create a temporary file " +
"for the Dangerfile DSL at: \(outputPath)")
exit(0)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Danger/DangerDSL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public struct DangerDSL: Decodable {
// Setup the OctoKit once all other
if runningOnGithub {
let config: TokenConfiguration

if let baseURL = settings.github.baseURL {
config = TokenConfiguration(settings.github.accessToken, url: baseURL)
} else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Danger/DangerUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public struct DangerUtils {

let lines = readFile(file).components(separatedBy: .newlines)

lines.enumerated().forEach { index, line in
for (index, line) in lines.enumerated() {
if line.contains(string) {
result.append(index + 1)
}
Expand Down Expand Up @@ -174,7 +174,7 @@ public extension DangerUtils.Environment {
}
}

public extension Optional where Wrapped == DangerUtils.Environment.Value {
public extension DangerUtils.Environment.Value? {
func getString(default defaultString: String) -> String {
if case let .string(value) = self { return value }
return defaultString
Expand Down
2 changes: 1 addition & 1 deletion Sources/Danger/Extensions/DateFormatterExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public extension DateFormatter {
}
}

private final class OptionalFractionalSecondsDateFormatter: DateFormatter {
private final class OptionalFractionalSecondsDateFormatter: DateFormatter, @unchecked Sendable {
static let withMilliseconds: DateFormatter = {
let formatter = DateFormatter()
setUpFormatter(formatter)
Expand Down
5 changes: 3 additions & 2 deletions Sources/Danger/GitDiff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct DiffParser {
.deletingPrefix("b/") ?? ""

let change: FileDiff.ParsedHeader.ChangeType

if lines.contains(where: { $0.hasPrefix("deleted file mode ") }) {
change = .deleted
} else if lines.contains(where: { $0.hasPrefix("new file mode") }) {
Expand Down Expand Up @@ -167,7 +167,8 @@ struct DiffParser {
let oldLineStart = Int(dividedSpan[0][0]),
let oldLineSpan = Int(dividedSpan[0][1]),
let newLineStart = Int(dividedSpan[1][0]),
let newLineSpan = Int(dividedSpan[1][1]) {
let newLineSpan = Int(dividedSpan[1][1])
{
return HunkSpan(oldLineStart: oldLineStart,
oldLineSpan: oldLineSpan,
newLineStart: newLineStart,
Expand Down
4 changes: 2 additions & 2 deletions Sources/Danger/Plugins/SwiftLint/CurrentPathProvider.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Foundation

internal protocol CurrentPathProvider {
protocol CurrentPathProvider {
var currentPath: String { get }
}

internal final class DefaultCurrentPathProvider: CurrentPathProvider {
final class DefaultCurrentPathProvider: CurrentPathProvider {
var currentPath: String {
FileManager.default.currentDirectoryPath
}
Expand Down
36 changes: 21 additions & 15 deletions Sources/Danger/Plugins/SwiftLint/SwiftLint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public enum SwiftLint {
strict: Bool = false,
quiet: Bool = true,
swiftlintPath: String,
markdownAction: (String) -> Void = markdown) -> [SwiftLintViolation] {
markdownAction: (String) -> Void = markdown) -> [SwiftLintViolation]
{
lint(lintStyle,
inline: inline,
configFile: configFile,
Expand All @@ -70,8 +71,8 @@ public enum SwiftLint {
strict: Bool = false,
quiet: Bool = true,
swiftlintPath: SwiftlintPath? = nil,
markdownAction: (String) -> Void = markdown
) -> [SwiftLintViolation] {
markdownAction: (String) -> Void = markdown) -> [SwiftLintViolation]
{
lint(lintStyle: lintStyle,
danger: danger,
shellExecutor: shellExecutor,
Expand All @@ -80,8 +81,7 @@ public enum SwiftLint {
configFile: configFile,
strict: strict,
quiet: quiet,
markdownAction: markdownAction
)
markdownAction: markdownAction)
}
}

Expand Down Expand Up @@ -112,7 +112,7 @@ extension SwiftLint {
arguments.append("--quiet")
}

if let configFile = configFile {
if let configFile {
arguments.append("--config \"\(configFile)\"")
}

Expand All @@ -133,10 +133,11 @@ extension SwiftLint {
outputFilePath: outputFilePath,
failAction: failAction,
readFile: readFile)

case let .modifiedAndCreatedFiles(directory):
// Gathers modified+created files, invokes SwiftLint on each, and posts collected errors+warnings to Danger.
var files = (danger.git.createdFiles + danger.git.modifiedFiles)
if let directory = directory {
if let directory {
files = files.filter { $0.hasPrefix(directory) }
}

Expand Down Expand Up @@ -181,10 +182,11 @@ extension SwiftLint {
swiftlintPath: String,
outputFilePath: String,
failAction: (String) -> Void,
readFile: (String) -> String) -> [SwiftLintViolation] {
readFile: (String) -> String) -> [SwiftLintViolation]
{
var arguments = arguments

if let directory = directory {
if let directory {
arguments.append(directory)
}

Expand All @@ -205,7 +207,8 @@ extension SwiftLint {
swiftlintPath: String,
outputFilePath: String,
failAction: (String) -> Void,
readFile: (String) -> String) -> [SwiftLintViolation] {
readFile: (String) -> String) -> [SwiftLintViolation]
{
let files = files.filter { $0.fileType == .swift }

// Only run Swiftlint, if there are files to lint
Expand Down Expand Up @@ -236,7 +239,8 @@ extension SwiftLint {
let swiftPackageDepPattern = #"\.package\(.*SwiftLint(\.git)?".*"#
if let packageContent = try? String(contentsOfFile: packagePath),
let regex = try? NSRegularExpression(pattern: swiftPackageDepPattern, options: .allowCommentsAndWhitespace),
regex.firstMatchingString(in: packageContent) != nil {
regex.firstMatchingString(in: packageContent) != nil
{
return "swift run swiftlint"
} else {
return "swiftlint"
Expand All @@ -248,9 +252,10 @@ extension SwiftLint {
inline: Bool,
markdownAction: (String) -> Void,
failInlineAction: (String, String, Int) -> Void,
warnInlineAction: (String, String, Int) -> Void) {
warnInlineAction: (String, String, Int) -> Void)
{
if inline {
violations.forEach { violation in
for violation in violations {
switch violation.severity {
case .error:
failInlineAction(violation.messageText, violation.file, violation.line)
Expand All @@ -276,7 +281,8 @@ extension SwiftLint {
outputFilePath: String,
shellExecutor: ShellExecuting,
failAction: (String) -> Void,
readFile: (String) -> String) -> [SwiftLintViolation] {
readFile: (String) -> String) -> [SwiftLintViolation]
{
shellExecutor.execute(swiftlintPath,
arguments: arguments,
environmentVariables: environmentVariables,
Expand Down Expand Up @@ -309,7 +315,7 @@ extension SwiftLint {
}
}

private extension Array where Element == SwiftLintViolation {
private extension [SwiftLintViolation] {
func updatingForCurrentPathProvider(_ currentPathProvider: CurrentPathProvider, strictSeverity: Bool) -> [Element] {
let currentPath = currentPathProvider.currentPath
return map { violation -> SwiftLintViolation in
Expand Down
2 changes: 1 addition & 1 deletion Sources/Danger/Report.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public extension DangerDSL {
/// Adds an inline suggestion to the Danger report (sends a normal message if suggestions are not supported)
func suggestion(code: String, file: String, line: Int) {
let message: String

if dangerRunner.dsl.supportsSuggestions {
message = """
```suggestion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ struct InlineDependenciesFinder {

let url: URL? = {
#if os(macOS) && compiler(>=5.9)
if #available(macOS 14.0, *) {
return URL(string: splittedImportString[0], encodingInvalidCharacters: false)
}
if #available(macOS 14.0, *) {
return URL(string: splittedImportString[0], encodingInvalidCharacters: false)
}
#endif
return URL(string: splittedImportString[0])
}()
guard let url = url else {
guard let url else {
throw Errors.invalidInlineDependencyURL(splittedImportString[0])
}

Expand Down
10 changes: 6 additions & 4 deletions Sources/DangerDependenciesResolver/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ extension Package {
func dependencyString(forToolsVersion version: Version) -> String {
switch version {
case Version(5, 6, 0)...:
if let minorVersion = minorVersion, let patchVersion = patchVersion {
if let minorVersion, let patchVersion {
return #".package(url: "\#(url.absoluteString)", exact: "\#(majorVersion).\#(minorVersion).\#(patchVersion)")"#
} else {
return #".package(url: "\#(url.absoluteString)", from: "\#(majorVersion).0.0")"#
}
case Version(5, 2, 0)...:
if let minorVersion = minorVersion, let patchVersion = patchVersion {
if let minorVersion, let patchVersion {
return #".package(name: "\#(name)", url: "\#(url.absoluteString)", .exact("\#(majorVersion).\#(minorVersion).\#(patchVersion)"))"#
} else {
return #".package(name: "\#(name)", url: "\#(url.absoluteString)", from: "\#(majorVersion).0.0")"#
}
default:
if let minorVersion = minorVersion, let patchVersion = patchVersion {
if let minorVersion, let patchVersion {
return #".package(url: "\#(url.absoluteString)", .exact("\#(majorVersion).\#(minorVersion).\#(patchVersion)"))"#
} else {
return #".package(url: "\#(url.absoluteString)", from: "\#(majorVersion).0.0")"#
Expand Down Expand Up @@ -66,6 +66,7 @@ extension Package.Pinned {
}

// MARK: - swift-tools-version >= 5.6

extension Package {
struct PinnedV2: Decodable, Equatable {
let name: String
Expand Down Expand Up @@ -99,7 +100,8 @@ extension Package.PinnedV2 {
}

// MARK: -
extension Sequence where Element == Package.PinnedV2 {

extension Sequence<Package.PinnedV2> {
func v1Converted() -> [Package.Pinned] {
map(\.v1)
}
Expand Down
Loading
Loading