danger / swift

⚠️ Stop saying "you forgot to …" in code review
https://danger.systems/swift/
MIT License
1.06k stars 141 forks source link

Plugins fail using Marathon on Bitrise #451

Open mohamedTarek95 opened 3 years ago

mohamedTarek95 commented 3 years ago

When I try to install plugins using Marathon inline dependencies I get this error on Bitrise

ERROR: failedToUpdatePackages("/var/root/.danger-swift/Packages/")

I tried using sudo to run the danger command and tried without sudo and it fails in both cases.

f-meloni commented 3 years ago

do you get that also if you remove completely the folder ~/.danger-swift?

mohamedTarek95 commented 3 years ago

do you get that also if you remove completely the folder ~/.danger-swift?

Yes

albertodebortoli commented 3 years ago

Same issue here.

f-meloni commented 3 years ago

Can I ask you if you can share which version of swift/xcode you are using and your Dangerfile.swift please?

ashfurrow commented 3 years ago

I'm seeing the same error on Circle CI (example failure). I did some digging and thought I'd share – I have a local workaround but I'm not sure about how to turn this into a fix.

I've reproduced the error locally using danger-swift 3.12.1 and Xcode 13, though CI is using Xcode 12.5.1. The Dangerfile is here. These two lines are causing the issue:

import DangerSwiftProse // package: https://github.com/f-meloni/danger-swift-prose.git
import DangerXCodeSummary // package: https://github.com/f-meloni/danger-swift-xcodesummary.git

Looks like the error is generated here:

https://github.com/danger/swift/blob/d951a755f7e9335321160272698a2ede9dc572a3/Sources/DangerDependenciesResolver/PackageManager.swift#L158-L165

I ran swift package update in ~/.danger-swift/Packages/Generated to reproduce the underlying error and got the following:

'PACKAGES' /Users/ash/.danger-swift/Packages/Generated: error: Source files for target PACKAGES should be located under 'Sources/PACKAGES', or a custom sources path can be set with the 'path' property in Package.swift
The generated `Package.swift` file has the following contents ```swift // swift-tools-version:5.5 // danger-dependency-generator-version:1 import PackageDescription let package = Package( name: "PACKAGES", products: [.library(name: "DangerDependencies", type: .dynamic, targets: ["PACKAGES"])], dependencies: [ .package(name: "DangerSwiftProse", url: "https://github.com/f-meloni/danger-swift-prose.git", from: "1.0.0"), .package(name: "DangerXCodeSummary", url: "https://github.com/f-meloni/danger-swift-xcodesummary.git", from: "1.0.0") ], targets: [.target(name: "PACKAGES", dependencies: ["DangerSwiftProse", "DangerXCodeSummary"])], swiftLanguageVersions: [.version("5")] ) ```

Based on the error output, I created a directory with an empty Swift source file in it:

mkdir -p ~/.danger-swift/Packages/Generated/Sources/PACKAGES
touch /Users/ash/.danger-swift/Packages/Generated/Sources/PACKAGES/Empty.swift

Then swift package update worked in the generated folder. I was able to run danger-swift local back in my directory without an issue.

I'm not sure the best approach to take here. We could either modifying the generated Package.swift to allow empty targets (if that's supported by SPM) or we could generate an empty .swift source file like I did above. If you point me in the right direction, I'm happy to try sending a pull request.

Thanks again!