f-meloni / danger-swift-coverage

Show the coverage of the modified/created files on your PRs.
MIT License
85 stars 20 forks source link

Multiple problems getting started #25

Closed postmechanical closed 4 years ago

postmechanical commented 4 years ago

Package.swift:

// swift-tools-version:5.1
import PackageDescription

let package = Package(
    name: "Foo",
    products: [
        .library(name: "DangerDependencies", type: .dynamic, targets: ["Foo"])
    ],
    dependencies: [
        .package(url: "https://github.com/danger/swift.git", from: "3.0.0"),
        .package(url: "https://github.com/f-meloni/danger-swift-coverage.git", from: "1.0.0")
    ],
    targets: [
        .target(name: "Foo", dependencies: ["Danger", "DangerSwiftCoverage"], path: "./", sources: ["Fake.swift"])
    ]
)

Running swift run danger-swift edit crashes with:

ERROR: commandFailed(command: "cd ~/.danger-swift/Scripts/Cache/-~-Workspace-ios-consumer-danger-Dangerfile && /usr/bin/env xcrun --sdk macosx swift package generate-xcodeproj --xcconfig-overrides /var/folders/7_/n64sf4cn3dggctn6k542r7sw0000gp/T/config.xcconfig", exitCode: 1, stdout: "", stderr: "\'Dangerfile\' ~/.danger-swift/Scripts/Cache/-~-Workspace-ios-consumer-danger-Dangerfile: error: dependency \'DangerSwiftCoverage\' in target \'Dangerfile\' requires explicit declaration; provide the name of the package dependency with \'.package(name: \"DangerSwiftCoverage\", url: \"https://github.com/f-meloni/danger-swift-coverage.git\", from: \"1.0.0\")\'\n\'Dangerfile\' ~/.danger-swift/Scripts/Cache/-~-Workspace-ios-consumer-danger-Dangerfile: error: dependency \'OctoKit\' in target \'Dangerfile\' requires explicit declaration; provide the name of the package dependency with \'.package(name: \"OctoKit\", url: \"https://github.com/nerdishbynature/octokit.swift\", from: \"0.0.0\")\'\n\'Dangerfile\' ~/.danger-swift/Scripts/Cache/-~-Workspace-ios-consumer-danger-Dangerfile: error: dependency \'danger-swift\' in target \'Dangerfile\' requires explicit declaration; provide the name of the package dependency with \'.package(name: \"danger-swift\", url: \"https://github.com/danger/swift.git\", from: \"3.0.0\")\'\n")

Running swift run danger-swift pr https://github.com/some-org/some-repo/pull/1234 crashes with:

Starting Danger PR on some-org/some-repo#1234
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret /var/folders/7_/n64sf4cn3dggctn6k542r7sw0000gp/T/_tmp_dangerfile.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I /Users/alondon/Workspace/some-repo/danger/.build/debug -module-name _tmp_dangerfile -lDanger -- runner /snapshot/danger-js/distribution/commands/danger-pr.js --process .build/debug/danger-swift --passURLForDSL https://github.com/some-org/some-repo/pull/1697 /var/folders/7_/n64sf4cn3dggctn6k542r7sw0000gp/T/danger-dsl.json /var/folders/7_/n64sf4cn3dggctn6k542r7sw0000gp/T/danger-response.json 
1.  Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
2.  While running user code "/var/folders/7_/n64sf4cn3dggctn6k542r7sw0000gp/T/_tmp_dangerfile.swift"

0  swift                    0x00000001057164ea PrintStackTraceSignalHandler(void*) + 42

1  swift                    0x0000000105715cc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff6cf5b42d _sigtramp + 29
3  libsystem_malloc.dylib   0x00007fff6cf1d695 
tiny_free_no_lock + 1081
4  libsystem_malloc.dylib   0x00000001090b1020 tiny_free_no_lock + 2618899908

5  swift                    0x00000001014999ba llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 458

6  swift                    0x00000001014a0a2b llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 2011

7  swift                    0x0000000101475aea performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 14362

8  swift                    0x000000010146a4a5 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 55813

9  swift                    0x00000001013e04d3 main + 1283
10 libdyld.dylib            0x00007fff6cd627fd start + 1

ERROR: Dangerfile eval failed at Dangerfile.swift

Danger: ⅹ Failing the build, there are 2 fails.
## Failures
Error deserializing SwiftLint JSON response (): dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "No value." UserInfo={NSDebugDescription=No value.})))
-
danger-swift` failed.
## Messages
Updated CHANGELOG 📃✨
-
Included JIRA 🎫🔗
## Markdowns
### Log

```sh
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret /var/folders/7_/n64sf4cn3dggctn6k542r7sw0000gp/T/_tmp_dangerfile.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I ~/Workspace/some-repo/danger/.build/debug -module-name _tmp_dangerfile -lDanger -- runner /snapshot/danger-js/distribution/commands/danger-pr.js --process .build/debug/danger-swift --passURLForDSL https://github.com/some-org/some-repo/pull/1697 /var/folders/7_/n64sf4cn3dggctn6k542r7sw0000gp/T/danger-dsl.json /var/folders/7_/n64sf4cn3dggctn6k542r7sw0000gp/T/danger-response.json 
1.  Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
2.  While running user code "/var/folders/7_/n64sf4cn3dggctn6k542r7sw0000gp/T/_tmp_dangerfile.swift"
0  swift                    0x00000001057164ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000105715cc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff6cf5b42d _sigtramp + 29
3  libsystem_malloc.dylib   0x00007fff6cf1d695 tiny_free_no_lock + 1081
4  libsystem_malloc.dylib   0x00000001090b1020 tiny_free_no_lock + 2618899908
5  swift                    0x00000001014999ba llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 458
6  swift                    0x00000001014a0a2b llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 2011
7  swift                    0x0000000101475aea performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 14362
8  swift                    0x000000010146a4a5 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 55813
9  swift                    0x00000001013e04d3 main + 1283
10 libdyld.dylib            0x00007fff6cd627fd start + 1
danger-results://var/folders/7_/n64sf4cn3dggctn6k542r7sw0000gp/T/danger-response.json

ERROR: Dangerfile eval failed at Dangerfile.swift

The Dangerfile.swift runs fine with danger-swift installed via brew and the import DangerSwiftCoverage omitted.

f-meloni commented 4 years ago

First two things I notice are that:

f-meloni commented 4 years ago

Also: which version of Danger-swift are you currently using in your package.resolved?

postmechanical commented 4 years ago

@f-meloni Thanks for the response.

  1. When using import DangerSwiftCoverage in my Dangerfile.swift and then running swift run danger-swift edit it does not compile. See first error posted.
  2. I am trying to migrate from brew installed danger-swift to SPM setup in order to use DangerSwiftCoverage, but it's not working and the errors don't seem to guide one to any solution in a reasonable amount of time.
  3. The danger-swift version in Package.resolved that I tried were 3.0.0 and 3.3.0.
f-meloni commented 4 years ago

I'm sure you will need an import DangerSwiftCoverage. I'm currently not sure of why that is not working though. I have a repo with a really similar configuration to the one you would like to have, that is currently working, maybe you can have a look and see if you spot any difference

https://github.com/f-meloni/danger-swift-xcodesummary/pull/17/files

postmechanical commented 4 years ago

@f-meloni Finally got it working with the Package.swift to which you linked. Thanks.

postmechanical commented 4 years ago

@f-meloni Actually scratch that previous comment. I was able to get swift run danger-swift edit to build and run. In my Dangerfile.swift I could import DangerSwiftCoverage, but I could not import any other plugins so your linked example really is for a Package.swift for a plugin. What I need is a Package.swift for just running danger-swift and arbitrary plugins via SPM.

The plugin example on the main site just doesn't appear to work at all. I have a pretty vanilla Package.swift, which builds fine but none of the plugins can be imported. Pretty much going to bail and go back to Ruby danger.

// swift-tools-version:5.1
import PackageDescription

let package = Package(
    name: "Whatever",
    products: [
        .library(name: "DangerDependencies-Library", type: .dynamic, targets: ["DangerDependencies-Target"]) // dev
    ],
    dependencies: [
    .package(url: "https://github.com/danger/swift.git", from: "3.3.0"), // dev
        .package(url: "https://github.com/f-meloni/danger-swift-coverage", from: "1.1.0"), // dev
        .package(url: "https://github.com/f-meloni/danger-swift-xcodesummary", from: "1.2.1"), // dev
    ],
    targets: [
        .target(name: "DangerDependencies-Target", dependencies: ["Danger", "DangerSwiftCoverage", "DangerXCodeSummary"], path: ".", sources: ["Fake.swift"]) // dev
    ]
)
f-meloni commented 4 years ago

I think you’ll need to replace the library name library(name: "DangerDeps[Product name (optional)]" (it needs to start with DangerDeps, danger needs to identify it)

postmechanical commented 4 years ago

Thanks, that works. I opened a PR to improve the main readme for that: https://github.com/danger/swift/pull/348. Hopefully it saves other a significant hassle in the future.