danger / swift

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

`swift run danger-swift edit` doesn't include plugins; `swift run danger-swift (ci|local)` works #590

Open niorko opened 10 months ago

niorko commented 10 months ago

I have a danger subdirectory in my project.

This is it's structure:

.
├── DangerDependencies
│   └── Fake.swift
├── Dangerfile.swift
├── Package.resolved
└── Package.swift

This is Dangerfile.swift:

import Foundation
import Danger
import DangerSwiftKantoku

let danger = Danger()
let kantokuConfig = XCResultParsingConfiguration(
    codeCoverageRequirement: .none,
    reportingFileType: .modifiedAndCreatedFiles
)
danger.kantoku.parseXCResultFile(at: "somePath", configuration: kantokuConfig)

and this is Package.swift:

// swift-tools-version:5.8
import PackageDescription

let package = Package(
    name: "DangerDepsProject",
    platforms: [.macOS(.v12)],
    products: [
        .library(name: "DangerDeps", type: .dynamic, targets: ["DangerDependencies"])
    ],
    dependencies: [
        .package(url: "https://github.com/danger/swift.git", from: "3.17.1"),
        .package(url: "https://www.github.com/yumemi-inc/danger-swift-kantoku.git", from: "0.1.1")
    ],
    targets: [
        .target(
            name: "DangerDependencies", 
            dependencies: [
                .product(name: "Danger", package: "swift"),
                .product(name: "DangerSwiftKantoku", package: "danger-swift-kantoku")
            ],
            path: "DangerDependencies"
        )
    ]
)

This works and it successfully uses plugins:

cd danger
swift build
swift run danger-swift local --failOnErrors --cwd ../ --base origin/develop

But I want to be able to edit the project, so I call this:

cd danger
swift build
swift run danger-swift edit

And this does not work, it generates the project where Package.swift does not contain plugins, so it won't build:

Generated Package.swift:

// swift-tools-version:5.8
// danger-dependency-generator-version:3

import PackageDescription

let package = Package(
    name: "Dangerfile",
    platforms: [.macOS(.v13)],
    products: [.executable(name: "DangerDependencies", targets: ["Dangerfile"])],
    dependencies: [
        .package(url: "https://github.com/danger/swift.git", exact: "3.17.1")
    ],
    targets: [.executableTarget(name: "Dangerfile", dependencies: [
        .product(name: "Danger", package: "swift")
    ])],
    swiftLanguageVersions: [.version("5")]
)

Swift Danger Version: 3.17.1

Example project: danger.zip

f-meloni commented 10 months ago

Thank you for the really detailed issue, let me give it a look and see if I can help :)