GithubHelp home page GithubHelp logo

f-meloni / danger-swift-coverage Goto Github PK

View Code? Open in Web Editor NEW
84.0 2.0 21.0 741 KB

Show the coverage of the modified/created files on your PRs.

License: MIT License

Swift 99.73% Ruby 0.27%
danger danger-plugin swift danger-swift testing test test-driven-development tools coverage xcodebuild xcodeproj spm swift-package-manager

danger-swift-coverage's Introduction

DangerSwiftCoverage

Danger-Swift plugin to show the coverage of the modified/created files.

DangerSwiftCoverage

Getting Started

Install DangerSwiftCoverage

Swift Package Manager (More performant)

You can use a "full SPM" solution to install both danger-swift and DangerSwiftCoverage.

  • Add to your Package.swift:
let package = Package(
    ...
    products: [
        ...
        .library(name: "DangerDeps", type: .dynamic, targets: ["DangerDependencies"]), // dev
        ...
    ],
    dependencies: [
        ...
        // Danger Plugins
        .package(url: "https://github.com/f-meloni/danger-swift-coverage", from: "0.1.0") // dev
        ...
    ],
    targets: [
        .target(name: "DangerDependencies", dependencies: ["Danger", "DangerSwiftCoverage"]), // dev
        ...
    ]
)
  • Add the correct import to your Dangerfile.swift:
import DangerSwiftCoverage

Coverage.xcodeBuildCoverage(.derivedDataFolder("Build"), 
                            minimumCoverage: 50, 
                            excludedTargets: ["DangerSwiftCoverageTests.xctest"])
  • Create a folder called DangerDependencies on Sources with an empty file inside like Fake.swift
  • To run Danger use swift run danger-swift command
  • (Recommended) If you are using SPM to distribute your framework, use Rocket, or similar to comment out all the dev depencencies from your Package.swift. This prevents the dev dependencies to be downloaded and compiled with your framework.

Marathon

  • Add this to your Dangerfile.swift
import DangerSwiftCoverage // package: https://github.com/f-meloni/danger-swift-coverage.git

Coverage.xcodeBuildCoverage(.derivedDataFolder("Build"), 
                            minimumCoverage: 50, 
                            excludedTargets: ["DangerSwiftCoverageTests.xctest"])
  • (Recommended) Cache the ~/.danger-swift folder

Gather Coverage

  • Enable "Gather the Coverage" on Xcode

GatherCoverage

or, on your CI, execute:

xcodebuild test -scheme DangerSwiftCoverage-Package -derivedDataPath Build/ -enableCodeCoverage YES

Custom XCResultBundle path

If you are using the -resultBundlePath parameter on xcodebuild you will need to use:

Coverage.xcodeBuildCoverage(.xcresultBundle("Build/bundlePath.xcresult"), 
                            minimumCoverage: 50, 
                            excludedTargets: ["DangerSwiftCoverageTests.xctest"])

Swift Package Manager

From Swift 5.0 you can gather the coverage from SPM with the --enable-code-coverage=true flag For SPM coverage add to your Dangerfile:

Coverage.spmCoverage(minimumCoverage: 50)

License

This project is licensed under the terms of the MIT license. See the LICENSE file.

danger-swift-coverage's People

Contributors

avdlee avatar f-meloni avatar nikolaykasyanov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

danger-swift-coverage's Issues

`excludedTargets` parameter default value problem

From 1.2.0 there's a new xcodeBuildCoverage method implemented in #26 that allows using [ExcludedTarget] type for excludedTargets parameter.

But the problem is, in that method the excludedTargets parameter also has a default value [], which causes a big problem that for projects that don't have excluded targets, there's no way for the compiler to check which method to use, the excludedTargets: [String] one or the excludedTargets: [ExcludedTarget] one. And that will cause a build error:

/var/folders/6q/wgy6jtp12w5gzgm9lzcglpqw0000gn/T/_tmp_dangerfile.swift:577:1: error: ambiguous use of 'xcodeBuildCoverage(_:minimumCoverage:excludedTargets:hideProjectCoverage:)'
Coverage.xcodeBuildCoverage(.xcresultBundle(ProcessInfo.xcTestResultPath), minimumCoverage: 60)
^
/Users/vagrant/.danger-swift/Scripts/Cache/-Users-vagrant-git-_dangerfile_imports/.build/checkouts/danger-swift-coverage/Sources/DangerSwiftCoverage/DangerSwiftCoverage.swift:19:24: note: found this candidate
    public static func xcodeBuildCoverage(_ coveragePathType: CoveragePathType, minimumCoverage: Float, excludedTargets: [String] = [], hideProjectCoverage: Bool = false) {
                       ^
/Users/vagrant/.danger-swift/Scripts/Cache/-Users-vagrant-git-_dangerfile_imports/.build/checkouts/danger-swift-coverage/Sources/DangerSwiftCoverage/DangerSwiftCoverage.swift:24:24: note: found this candidate
    public static func xcodeBuildCoverage(_ coveragePathType: CoveragePathType, minimumCoverage: Float, excludedTargets: [ExcludedTarget] = [], hideProjectCoverage: Bool = false) {

I think the best way to solve this problem is to remove the default value for [ExcludedTarget] method so for the projects that don't have an excludedTargets parameter, the build can still be passed

[Help Needed] Fails to build on Bitrise

It's very weird that from last week all my danger-swift workflows on Bitrise fails to build. I didn't change anything on Dangerfile.swift, and this plugin doesn't seem to have anything being changed either. But if I comment out the use of Coverage on my Dangerfile.swift, everything's OK.

Output of Danger-Swift step on Bitrise:

+ export DANGER_GITHUB_API_TOKEN=[REDACTED]
+ DANGER_GITHUB_API_TOKEN=[REDACTED]
+ danger-swift ci
objc[16933]: Class _TtC7OctoKit4File is implemented in both /usr/local/Cellar/danger-swift/3.7.2/lib/danger/libDanger.dylib (0x10d35f3e0) and /Users/vagrant/.danger-swift/Scripts/Cache/-Users-vagrant-git-_dangerfile_imports/.build/x86_64-apple-macosx/debug/libDangerDependencies.dylib (0x10d0d3ed8). One of the two will be used. Which one is .

objc[16933]: Class _TtC7OctoKit4Gist is implemented in both /usr/local/Cellar/danger-swift/3.7.2/lib/danger/libDanger.dylib (0x10d35f6b0) and /Users/vagrant/.danger-swift/Scripts/Cache/-Users-vagrant-git-_dangerfile_imports/.build/x86_64-apple-macosx/debug/libDangerDependencies.dylib (0x10d0d4198). One of the two will be used. Which one is .
objc[16933]: Class _TtC7OctoKit5Issue is implemented in both /usr/local/Cellar/danger-swift/3.7.2/lib/danger/libDanger.dylib (0x10d35fae0) and /Users/vagrant/.danger-swift/Scripts/Cache/-Users-vagrant-git-_dangerfile_imports/.build/x86_64-apple-macosx/debug/libDangerDependencies.dylib (0x10d0d4610). One of the two will be used. Which one is .
objc[16933]: Class _TtC7OctoKit5Label is implemented in both /usr/local/Cellar/danger-swift/3.7.2/lib/danger/libDanger.dylib (0x10d35ff50) and /Users/vagrant/.danger-swift/Scripts/Cache/-Users-vagrant-git-_dangerfile_imports/.build/x86_64-apple-macosx/debug/libDangerDependencies.dylib (0x10d0d4a28). One of the two will be used. Which one is undefined.
objc[16933]: Class _TtC7OctoKit9Milestone is implemented in both /usr/local/Cellar/danger-swift/3.7.2/lib/danger/libDanger.dylib (0x10d360108) and /Users/vagrant/.danger-swift/Scripts/Cache/-Users-vagrant-git-_dangerfile_imports/.build/x86_64-apple-macosx/debug/libDangerDependencies.dylib (0x10d0d4bd0). One of the two will be used. Which one is undefined.
objc[16933]: Class _TtC7OctoKit11PullRequest is implemented in both /usr/local/Cellar/danger-swift/3.7.2/lib/danger/libDanger.dylib (0x10d3604c8) and /Users/vagrant/.danger-swift/Scripts/Cache/-Users-vagrant-git-_dangerfile_imports/.build/x86_64-apple-macosx/debug/libDangerDependencies.dylib (0x10d0d5140). One of the two will be used. Which one is undefined.
objc[16933]: Class _TtC7OctoKit10Repository is implemented in both /usr/local/Cellar/danger-swift/3.7.2/lib/danger/libDanger.dylib (0x10d3609f0) and /Users/vagrant/.danger-swift/Scripts/Cache/-Users-vagrant-git-_dangerfile_imports/.build/x86_64-apple-macosx/debug/libDangerDependencies.dylib (0x10d0d5820). One of the two will be used. Which one is undefined.
objc[16933]: Class _TtC7OctoKit4User is implemented in both /usr/local/Cellar/danger-swift/3.7.2/lib/danger/libDanger.dylib (0x10d360da0) and /Users/vagrant/.danger-swift/Scripts/Cache/-Users-vagrant-git-_dangerfile_imports/.build/x86_64-apple-macosx/debug/libDangerDependencies.dylib (0x10d0d5ee0). One of the two will be used. Which one is undefined.

'statement_level' has been renamed to 'function_level' and will be completely removed in a future release.

2021-02-16 07:06:45.487 xccov[16941:66880] Requested but did not find extension point with identifier Xcode.IDEFoundation.IDEResultKitSerializationConverter

Stack dump:
0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret /var/folders/6q/wgy6jtp12w5gzgm9lzcglpqw0000gn/T/_tmp_dangerfile.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -I /usr/local/lib/danger -I /Users/vagrant/.danger-swift/Scripts/Cache/-Users-vagrant-git-_dangerfile_imports/.build/debug -target-sdk-version 11.1 -module-name _tmp_dangerfile -lDangerDependencies -lDanger -- runner /snapshot/danger-js/distribution/commands/danger-ci.js --process danger-swift --passURLForDSL /var/folders/6q/wgy6jtp12w5gzgm9lzcglpqw0000gn/T/danger-dsl.json /var/folders/6q/wgy6jtp12w5gzgm9lzcglpqw0000gn/T/danger-response.json 
1.	Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
2.	While running user code "/var/folders/6q/wgy6jtp12w5gzgm9lzcglpqw0000gn/T/_tmp_dangerfile.swift"

0  swift                       0x0000000107bd9615 
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37

1  swift                       0x0000000107bd8615 llvm::sys::RunSignalHandlers() + 85

2  swift                       0x0000000107bd9bcf SignalHandler(int) + 111
3  libsystem_platform.dylib   
 0x00007fff6783c5fd _sigtramp + 29
4  libsystem_platform.dylib    0x0000000000000002 _sigtramp + 18446603338779474466
5  libDangerDependencies.dylib 0x000000010cfe4480 $s6Danger0A3DSLVWOh + 3184
6  libDangerDependencies.dylib 0x000000010cfe2f0c $s19DangerSwiftCoverage0C0O010xcodeBuildC0_07minimumC015excludedTargets011hideProjectC0yAC0C8PathTypeO_SfSaySSGSbtFZ + 652
7  libDangerDependencies.dylib 0x000000010d5904f0 $s19DangerSwiftCoverage0C0O010xcodeBuildC0_07minimumC015excludedTargets011hideProjectC0yAC0C8PathTypeO_SfSaySSGSbtFZ + 5953648

8  swift                       0x0000000103794a6f 
llvm::orc::runAsMain(int (*)(int, char**), llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::Optional<llvm::StringRef>) + 2495

9  swift                       0x0000000103771e5b swift::RunImmediately(swift::CompilerInstance&, 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&, swift::IRGenOptions const&, swift::SILOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >&&) + 6747

10 swift                       0x000000010374cf7a performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 2426

11 swift                       0x000000010373cf4e swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*)
 + 21134

12 swift                       0x00000001036bdc27 main + 1255
13 libdyld.dylib               0x00007fff6763fcc9 start + 1


Cloning and building inline dependencies: import DangerXCodeSummary // package: https://github.com/f-meloni/danger-swift-xcodesummary.git, import DangerSwiftCoverage // package: https://github.com/f-meloni/danger-swift-coverage.git, import DangerSwiftHammer // package: https://github.com/el-hoshino/DangerSwiftHammer.git, this might take some time.
Updating packages...
Using https://github.com/f-meloni/danger-swift-xcodesummary.git latest major:1
Updating packages...
Using https://github.com/f-meloni/danger-swift-coverage.git latest major:1
Updating packages...
Using https://github.com/el-hoshino/DangerSwiftHammer.git latest major:0
Updating packages...
ERROR: Dangerfile eval failed at Dangerfile.swift

Command that seems to cause the failure:

Coverage.xcodeBuildCoverage(.xcresultBundle(processInfo.environment["BITRISE_XCRESULT_PATH"]), minimumCoverage: 60)

processInfo.environment["BITRISE_XCRESULT_PATH"] seems working fine when I tried to check the value:

/var/folders/......./Test.xcresult

Also if I try danger-swift pr locally it also works fine.

Multiple problems getting started

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.

Xcode 11.1, failed to get coverage

After updating to Xcode 11.1, I get this error

Failed to get the coverage - Error: Could not find the xccovreport file

I am using the latest version of danger and this plugin

    dependencies: [
        .package(url: "https://github.com/danger/swift.git", from: "2.0.4"),
        .package(url: "https://github.com/f-meloni/danger-swift-coverage", from: "1.0.0")
    ],

Anyone knows how to fix this for Xcode 11.1?

Undefined symbols for architecture x86_64:

I got this very strange build error :

Ld /Users/sudeepkini/Library/Developer/Xcode/DerivedData/Dangerfile-bgoyfmznyrlvgxaiskabqrhusora/Build/Products/Debug/Dangerfile normal (in target 'Dangerfile' from project 'Dangerfile')
    cd /Users/sudeepkini/.danger-swift/Scripts/Cache/-Users-sudeepkini-iOS-dunzoit-latte-Dangerfile
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target x86_64-apple-macos10.10 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -L/Users/sudeepkini/Library/Developer/Xcode/DerivedData/Dangerfile-bgoyfmznyrlvgxaiskabqrhusora/Build/Products/Debug -L/Users/sudeepkini/iOS/dunzoit/latte/.build/x86_64-apple-macosx/debug -F/Users/sudeepkini/Library/Developer/Xcode/DerivedData/Dangerfile-bgoyfmznyrlvgxaiskabqrhusora/Build/Products/Debug -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -filelist /Users/sudeepkini/Library/Developer/Xcode/DerivedData/Dangerfile-bgoyfmznyrlvgxaiskabqrhusora/Build/Intermediates.noindex/Dangerfile.build/Debug/Dangerfile.build/Objects-normal/x86_64/Dangerfile.LinkFileList -Xlinker -rpath -Xlinker /usr/lib/swift -Xlinker -rpath -Xlinker /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -Xlinker -rpath -Xlinker @executable_path -Xlinker -object_path_lto -Xlinker /Users/sudeepkini/Library/Developer/Xcode/DerivedData/Dangerfile-bgoyfmznyrlvgxaiskabqrhusora/Build/Intermediates.noindex/Dangerfile.build/Debug/Dangerfile.build/Objects-normal/x86_64/Dangerfile_lto.o -Xlinker -no_deduplicate -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/sudeepkini/Library/Developer/Xcode/DerivedData/Dangerfile-bgoyfmznyrlvgxaiskabqrhusora/Build/Intermediates.noindex/Dangerfile.build/Debug/Dangerfile.build/Objects-normal/x86_64/Dangerfile.swiftmodule -l Danger -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/sudeepkini/Library/Developer/Xcode/DerivedData/Dangerfile-bgoyfmznyrlvgxaiskabqrhusora/Build/Intermediates.noindex/Dangerfile.build/Debug/Dangerfile.build/Objects-normal/x86_64/Dangerfile_dependency_info.dat -o /Users/sudeepkini/Library/Developer/Xcode/DerivedData/Dangerfile-bgoyfmznyrlvgxaiskabqrhusora/Build/Products/Debug/Dangerfile

Undefined symbols for architecture x86_64:
  "static DangerSwiftCoverage.Coverage.xcodeBuildCoverage(_: DangerSwiftCoverage.Coverage.CoveragePathType, minimumCoverage: Swift.Float, excludedTargets: [Swift.String], hideProjectCoverage: Swift.Bool) -> ()", referenced from:
      _main in main.o
     (maybe you meant: default argument 3 of static DangerSwiftCoverage.Coverage.xcodeBuildCoverage(_: DangerSwiftCoverage.Coverage.CoveragePathType, minimumCoverage: Swift.Float, excludedTargets: [Swift.String], hideProjectCoverage: Swift.Bool) -> (), default argument 2 of static DangerSwiftCoverage.Coverage.xcodeBuildCoverage(_: DangerSwiftCoverage.Coverage.CoveragePathType, minimumCoverage: Swift.Float, excludedTargets: [Swift.String], hideProjectCoverage: Swift.Bool) -> () )
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is my set up

Package.swift

// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "DangerComponents",
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "DangerDeps",
            type: .dynamic,
            targets: ["DangerDependencies"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        .package(name: "danger-swift", url: "https://github.com/danger/swift.git", from: "3.10.1"),
        .package(name: "DangerXCodeSummary", url: "https://github.com/f-meloni/danger-swift-xcodesummary", from: "1.2.1"),
        .package(name: "DangerSwiftCoverage", url: "https://github.com/f-meloni/danger-swift-coverage", from: "1.2.1")
    ],
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "DangerDependencies",
            dependencies: [
              .product(name: "Danger", package: "danger-swift"), 
              "DangerXCodeSummary", 
              "DangerSwiftCoverage"
            ],
            path: "latte/Tools/Tools", 
            sources: ["main.swift"]),
    ]
)

DangerFile.swift

import Danger
import DangerXCodeSummary
import DangerSwiftCoverage

let danger = Danger()
let allFileChanges = danger.git.createdFiles + danger.git.modifiedFiles



// Linting Swift files

var swiftFiles  = allFileChanges.filter { $0.fileType == .swift}
swiftFiles = swiftFiles.filter {
    !$0.contains("DangerFile")
}

var swiftlintDisabledFiles = swiftFiles.filter {
    let fileContents  = danger.utils.readFile($0)
    return fileContents.contains("swiftlint:disable all")
}
swiftlintDisabledFiles.forEach { danger.warn(message: "SwiftLint Violation: Please remove 'swiftlint:disable all' for this file", file: $0, line: 1)
}
SwiftLint.lint(.files(swiftFiles), inline: true, configFile: "latte/.swiftlint.yml", swiftlintPath: .bin("Pods/SwiftLint/swiftlint"))

Coverage.xcodeBuildCoverage(.derivedDataFolder("Build"), minimumCoverage: 3 )
// let reportTestJSON = "build/reports/errors.json"
// let summary = XCodeSummary(filePath: reportTestJSON ) { result in
//     return result.category != .warning
// }
// summary.report()

I am using a Subproject called Tools - for writing command lines tools though it's more just an empty shell right now hence the target and path

Xcode Version : 12.4

The report not showed

please help me, when i run this command. i only get this

run in terminal : swift run danger-swift pr https://github.com/x/projectname/pull/1863

xcrun xccov view --report --json /Users/devicename/Documents/work/username/ios/projectname/automation/scan/output_directory/dev.xcresult > /var/folders/6c/g8z2ltwd51g0914p485vq_2r0000gp/T/file



Danger: โœ“ found only warnings, not failing the build
## Warnings
No asignee found. ๐Ÿง‘โ€๐Ÿ’ป You should asign someone to the PR.
-
warn succed
## Messages
These files have changed: Dangerfile.swift
my Dangerfile.swift

import Danger
import DangerSwiftCoverage
import Foundation
Coverage.xcodeBuildCoverage(.xcresultBundle("/Users/devicename/Documents/work/username/ios/foldername/automation/scan/output_directory/dev.xcresult"), 
                            minimumCoverage: 50,
                            excludedTargets: ["DangerSwiftCoverageTests.xctest"])
// swift-tools-version: 5.9
import PackageDescription

let package = Package(
    name: "PackageName",
    defaultLocalization: "en",
    platforms: [
        .iOS(.v13),
        .macOS(.v13),
    ],
    products: [
        .library(name: "DangerDeps", type: .dynamic, targets: ["projectname"]),
    ],
    dependencies: [
        .package(url: "https://github.com/danger/swift.git", from: "3.0.0"),
        .package(url: "https://github.com/f-meloni/danger-swift-coverage", from: "1.2.1"),
    ],
    targets: [
        .target(
            name: "targetName",
            dependencies: [
                .product(name: "Danger", package: "swift"),
                .product(name: "DangerSwiftCoverage", package: "danger-swift-coverage"),
            ],
            path: "folderRootName"
        ),
        .testTarget(
            name: "targetTestsName",
            dependencies: [
                .product(name: "Danger", package: "swift"),
                .product(name: "DangerSwiftCoverage", package: "danger-swift-coverage"),
            ],
            path: "folderRootNameTests"
        ),
    ]
)

how to get and show this report
image

Last coverage doesn't work markdown

I have different pods dev in my xcresult, so for the last modified I receive in one line the message, not in markdown as the other coverage.
Something like this.

PodA.framework: Coverage: 50.9 | File | Coverage || | --- | --- | --- | File.swift | 48.08% | โš ๏ธ

`danger-swift local` works fine but not `danger-swift ci` (GH Actions)

using danger-swift local able to generate code coverage from stdout.

## Messages
Project coverage: 15.88%
-
Project coverage: 15.88%
## Markdowns
## AppTests.xctest: Coverage: 100.0
| File | Coverage ||
| --- | --- | --- |
AppTests.swift | 100.0% | โœ…

-
## TodosTests.xctest: Coverage: 100.0
| File | Coverage ||
| --- | --- | --- |
TodosTests.swift | 100.0% | โœ…

-
## Core.framework: Coverage: 0.0
| File | Coverage ||
| --- | --- | --- |
Core.swift | 0.0% | โš ๏ธ

-
## App.app: Coverage: 70.97
| File | Coverage ||
| --- | --- | --- |
AppDelegate.swift | 94.74% | โœ…
ViewController.swift | 33.33% | โš ๏ธ

-
## Todos.framework: Coverage: 75.17
| File | Coverage ||
| --- | --- | --- |
Todo.swift | 18.97% | โš ๏ธ
Todos.swift | 89.47% | โœ…

but pushing the same code to the origin (with GitHub actions) running danger-swift ci doesn't produce any output.
I even also tried to push the same .xcresult to verify the ci, but still the same. Any recommendation? thank you

GitHub API v3 breaking change

I've followed the getting started guide and have successfully integrated DangerSwiftCoverage on TeamCity CI:

Dangerfile.swift

import Danger
import DangerSwiftCoverage
import Foundation

print("Generating code coverage...")
Coverage.xcodeBuildCoverage(.xcresultBundle("Build/BenchSocialNetwork-DEV.xcresult"),
                            minimumCoverage: 50,
                            excludedTargets: ["BenchSocialNetworkTests.xctest", "BenchSocialNetworkUITests.xctest"])

Command: swift run danger-swift ci

Generating code coverage...
  xcrun xccov view --report --json Build/BenchSocialNetwork-DEV.xcresult > /var/folders/jd/pzvvs8196p5cj_0j56bscv280000gp/T/file

Failing the build, there is 1 fail.
  Request failed [422]: https://api.github.com/repos/<org>/<repo>/pulls/3/reviews
  Response: {
    "message": "Unprocessable Entity",
    "errors": [
      "Pull request review thread position is invalid and Pull request review thread diff hunk can't be blank"
    ],
    "documentation_url": "https://docs.github.com/rest/reference/pulls#create-a-review-for-a-pull-request
  }

I believe this is a breaking change with the way the plugin sends requests to GitHub, since the coverage generation gave an exit code of 0.

Hope you can advise / fix asap, thanks!

Error when using Xcode 13.4 / Swift 5.6

I'm getting the following error after updating my GitHub Actions workflow to use Xcode 13.4:

Cloning and building inline dependencies: import DangerSwiftCoverage // package: https://github.com/f-meloni/danger-swift-coverage.git, this might take some time.
Updating packages...
Using https://github.com/f-meloni/danger-swift-coverage.git latest major:1
Updating packages...
ERROR: keyNotFound(CodingKeys(stringValue: "object", intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: "No value associated with key CodingKeys(stringValue: \"object\", intValue: nil) (\"object\").", underlyingError: nil))

To reproduce, include this in your workflow:

jobs:
  MyDangerJob:
    runs-on: macos-12
    env:
      DEVELOPER_DIR: "/Applications/Xcode_13.4.app/Contents/Developer"
    ...

Any ideas how to resolve this?

Error- no such module 'DangerSwiftCoverage'

So i have an SPM project, in Swift 5.1. My Dangerfile.swift file has:

import Danger
import DangerSwiftCoverage

let danger = Danger()
Coverage.spmCoverage(minimumCoverage: 50)

I imported in my Package.swift as per instructions.

When I run the following, I get an error:

$ swift run danger-swift local
/var/folders/68/946ywfgx3jq3bwhy02std9tc0000gn/T/_tmp_dangerfile.swift:9:8: error: no such module 'DangerSwiftCoverage'
import DangerSwiftCoverage
       ^

ERROR: Dangerfile eval failed at Dangerfile.swift
ERROR: Could not get the results JSON file at /var/folders/68/946ywfgx3jq3bwhy02std9tc0000gn/T/danger-response.json

Danger: โ…น Failing the build, there is 1 fail.
## Failures
danger-swift` failed.
## Markdowns
### Log


```sh
/var/folders/68/946ywfgx3jq3bwhy02std9tc0000gn/T/_tmp_dangerfile.swift:9:8: error: no such module 'DangerSwiftCoverage'
import DangerSwiftCoverage
       ^
ERROR: Dangerfile eval failed at Dangerfile.swift
ERROR: Could not get the results JSON file at /var/folders/68/946ywfgx3jq3bwhy02std9tc0000gn/T/danger-response.json

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.