danger / swift

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

[Question] Danger-Swift for Swift Package Setup Instructions #422

Closed jonesrajee closed 3 years ago

jonesrajee commented 3 years ago

I am not sure if this is an issue or something I have missed in the documentation but I am having the hardest time getting setup to use danger on a Swift Package

What I don't understand

  1. The documentation says to add danger and a target DangerDependencies to my package. What I don't understand is, is this setup for an Xcode project that otherwise wouldn't have a Package.swift or is this intended to be for all setups?

What is happening is that Danger, along with some of my plugins, are being distributed with my actual package instead of just being a dev dependency.

  1. What is the point of creating a Danger library as well? This is a followup to the first question because it doesn't seem needed as well.

I am also trying the similar plugin you have here, Rocket - but also can't get that to work correctly

Any help would be appreciated!

Resources

Existing package as close as possible to the instructions:

// 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: "Skip-Core-Swift",
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "SkipCore",
            targets: ["SkipCore"]
        ),
//        // Development Library
        .library(name: "DangerDeps", type: .dynamic, targets: ["DangerDependencies"]), // dev
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // Development Dependencies
        .package(name: "danger-swift", url: "https://github.com/danger/swift.git", from: "3.0.0"),
        .package(url: "https://github.com/shibapm/Rocket", .branch("master")), // dev
        .package(name: "Komondor", url: "https://github.com/shibapm/Komondor.git", from: "1.0.0"), // dev
        .package(name: "SwiftFormat", url: "https://github.com/nicklockwood/SwiftFormat", from: "0.47.0"), // dev
        .package(name: "SwiftLint", url: "https://github.com/realm/SwiftLint", from: "0.41.0"), // dev
        .package(name: "SourceDocs", url: "https://github.com/eneko/SourceDocs", from: "1.0.0"), // dev
        // Danger Plugins
        .package(name: "DangerSwiftCoverage", url: "https://github.com/f-meloni/danger-swift-coverage", from: "1.0.0"), // dev
        .package(name: "DangerXCodeSummary", url: "https://github.com/f-meloni/danger-swift-xcodesummary", from: "1.0.0"), // dev
    ],
    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 this package depends on.
        // Development Target
        .target(
            name: "DangerDependencies",
            dependencies: [
                .product(name: "Danger", package: "danger-swift"),
                "DangerSwiftCoverage",
                "DangerXCodeSummary",
            ],
            path: "Sources/DangerDependencies",
            sources: ["Fake.swift"]
        ),
        .target(
            name: "SkipCore",
            dependencies: []
        ),
        .testTarget(
            name: "SkipCoreTests",
            dependencies: ["SkipCore"]
        ),
    ]
)

#if canImport(PackageConfig)
    import PackageConfig

    let config = PackageConfiguration([
        "komondor": [
            "pre-commit": [
                "swift test",
                "swift run swiftformat Sources/",
                "swift run swiftlint autocorrect",
                "swift run sourcedocs generate --spm-module SkipCore -- -scheme Skip-Core-Swift-Package",
                "git add Documentation/*"
            ],
            "pre-push": "swift test",
        ],
        "rocket": [
            "steps": [
                ["script": ["content": "ruby Scripts/update_changelog.rb"]],
                ["git_add": ["paths": ["CHANGELOG.md"]]],
                ["commit": ["message": "Releasing version $VERSION"]],
                "tag",
                "push",
            ],
        ],
    ]).write()
#endif

Package that no longer runs Danger:

// 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: "Skip-Core-Swift",
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "SkipCore",
            targets: ["SkipCore"]
        ),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // Development Dependencies
        .package(name: "danger-swift", url: "https://github.com/danger/swift.git", from: "3.0.0"), // dev
        .package(url: "https://github.com/shibapm/Rocket", .branch("master")), // dev
        .package(name: "Komondor", url: "https://github.com/shibapm/Komondor.git", from: "1.0.0"), // dev
        .package(name: "SwiftFormat", url: "https://github.com/nicklockwood/SwiftFormat", from: "0.47.0"), // dev
        .package(name: "SwiftLint", url: "https://github.com/realm/SwiftLint", from: "0.41.0"), // dev
        .package(name: "SourceDocs", url: "https://github.com/eneko/SourceDocs", from: "1.0.0"), // dev
        // Danger Plugins
        .package(name: "DangerSwiftCoverage", url: "https://github.com/f-meloni/danger-swift-coverage", from: "1.0.0"), // dev
        .package(name: "DangerXCodeSummary", url: "https://github.com/f-meloni/danger-swift-xcodesummary", from: "1.0.0"), // dev
    ],
    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 this package depends on.
        .target(
            name: "SkipCore",
            dependencies: []
        ),
        .testTarget(
            name: "SkipCoreTests",
            dependencies: ["SkipCore"]
        ),
    ]
)

#if canImport(PackageConfig)
    import PackageConfig

    let config = PackageConfiguration([
        "komondor": [
            "pre-commit": [
                "swift test",
                "swift run swiftformat Sources/",
                "swift run swiftlint autocorrect",
                "swift run sourcedocs generate --spm-module SkipCore -- -scheme Skip-Core-Swift-Package",
                "git add Documentation/*"
            ],
            "pre-push": "swift test",
        ],
        "rocket": [
            "after": [
               "push",
            ],
        ],
    ]).write()
#endif

Notice if I pull my local package into a repo - it brings all of the dev dependencies image


If I run swift run rocket {version} or comment out all of the //dev dependencies, then it appears to only bring in my Target - which is what I want; however - my CI pipeline no longer runs Danger!

How I Expect the Package to appear

image

Danger Error

image

f-meloni commented 3 years ago

If I run swift run rocket {version} or comment out all of the //dev dependencies, then it appears to only bring in my Target - which is what I want; however - my CI pipeline no longer runs Danger!

Is that on that commit, or in general? Rockert should make another commit where enables the commented dev dependencies

f-meloni commented 3 years ago

The documentation says to add danger and a target DangerDependencies to my package. What I don't understand is, is this setup for an Xcode project that otherwise wouldn't have a Package.swift or is this intended to be for all setups?

You can have a Package.swift in a separate folder if you want, or you can use Danger via brew, given it has its own dependencies resolver, but is less performing

What is the point of creating a Danger library as well? This is a followup to the first question because it doesn't seem needed as well.

If you don't create a library that can not be linked with the Dangerfile compilation