danger / swift

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

danger-swift local fails #285

Open MinuteCode opened 5 years ago

MinuteCode commented 5 years ago

Hi ! I'm trying to setup danger-swift to run with my project and I'm trying to run it locally. I cannot figure out what is wrong with my setup but the result is that danger-swift local fails when I try to run it. Here are my implementation's details :

Package.swift

// swift-tools-version:4.2
import PackageDescription

let package = Package(
    name: "Eigen",
    dependencies: [
      .package(url: "https://github.com/danger/swift.git", from: "1.0.0")
    ],
    targets: [
        // This is just an arbitrary Swift file in our app, that has
        // no dependencies outside of Foundation, the dependencies section
        // ensures that the library for Danger gets build also.
        .target(name: "eigen", dependencies: ["Danger"], path: "ProApp", sources: ["../DangerDummy.swift"]),
    ]
)

Same as the one in getting started. DangerDummy.swift contains one line of code that imports Foundation

Dangerfile.swift

import Danger 
let danger = Danger()

let editedFiles = danger.git.modifiedFiles + danger.git.createdFiles
message("These files have changed: \(editedFiles.joined())")

Once again, it's the same as in the getting started

danger-swift local logs

// DEBUG=* danger-swift local
Launching Danger Swift local (v1.6.5)
Finding out where the danger executable is
Running: /usr/local/bin/danger local --process .build/debug/danger-swift --passURLForDSL 
  danger:localGetDiff > git diff master...HEAD +0ms
  danger:process_runner Debug mode on for Danger v6.1.13 +0ms
  danger:process_runner Starting sub-process run +0ms
  danger:localGetDiff > git log master...HEAD --pretty=format:{ "sha": "%H", "parents": "%p", "author": {"name": "%an", "email": "%ae", "date": "%ai" }, "committer": {"name": "%cn", "email": "%ce", "date": "%ci" }, "message": "%f"}, +0ms
  danger:process_runner Preparing to run: .build/debug/danger-swift +112ms
  danger:runDangerSubprocess Running sub-process: danger-swift -  +0ms
  danger:runDangerSubprocess Started passing in STDIN via the URL: danger://dsl//var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json +4ms
  danger:runDangerSubprocess Passed DSL in via STDIN +0ms
Ran with: /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/_tmp_dangerfile.swift /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json
Decoding the DSL into Swift types
ERROR: Failed to parse JSON: valueNotFound(Swift.String, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "danger", intValue: nil), CodingKeys(stringValue: "git", intValue: nil), CodingKeys(stringValue: "created_files", intValue: nil), _JSONKey(stringValue: "Index 45", intValue: 45)], debugDescription: "Expected String but found null value instead.", underlyingError: nil))

  danger:runDangerSubprocess Got JSON URL from STDOUT, results are at: 
  danger:runDangerSubprocess danger-results://var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json +385ms
Got URL for JSON: /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json
Created a temporary file for the Dangerfile DSL at: /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json
Running Dangerfile at: Dangerfile.swift
Preparing to compile
Running: /usr/bin/swiftc --driver-mode=swift -L /Users/admin/Desktop/REDACTED/proapp/.build/debug -I /Users/admin/Desktop/REDACTED/proapp/.build/debug -lDanger /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/_tmp_dangerfile.swift /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json
Completed evaluation
ERROR: Dangerfile eval failed at Dangerfile.swift
Saving and storing the results at /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json

  danger:runDangerSubprocess child process exited with code 1 +5ms
  danger:runDangerSubprocess Handling fail from subprocess +0ms
  danger:jsonToDSL Creating pr DSL from JSON +0ms
[before-after-hook]: "Hook()" repurposing warning, use "Hook.Collection()". Read more: https://git.io/upgrade-before-after-hook-to-1.4
  danger:localGetDiff > git diff master...HEAD +1s
  danger:localGetDiff > git log master...HEAD --pretty=format:{ "sha": "%H", "parents": "%p", "author": {"name": "%an", "email": "%ae", "date": "%ai" }, "committer": {"name": "%cn", "email": "%ce", "date": "%ci" }, "message": "%f"}, +1s
  danger:executor Got results back: {
  warnings: [],
  messages: [
    {
      message: 'These files have changed: CHANGELOG.mdSources/DangerFixtures/DangerFixtures.swiftTests/DangerTests/XCTestManifests.swiftSources/Danger/Plugins/SwiftLint/CurrentPathProvider.swiftSources/Danger/Plugins/SwiftLint/ShellExecutor.swiftSources/Danger/Plugins/SwiftLint/SwiftLint.swiftSources/Danger/Plugins/SwiftLint/SwiftLintViolation.swiftTests/DangerTests/SwiftLint/DangerSwiftLintTests.swiftTests/DangerTests/SwiftLint/FakeCurrentPathProvider.swiftTests/DangerTests/SwiftLint/FakeShellExecutor.swiftTests/DangerTests/SwiftLint/URL+Utils.swiftTests/DangerTests/SwiftLint/ViolationTests.swift'
    }
  ],
  fails: [ { message: 'danger-swift` failed.' } ],
  markdowns: [
    {
      message: '### Log\n' +
        '\n' +
        '\n' +
        '```sh\n' +
        'Ran with: /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/_tmp_dangerfile.swift /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json\n' +
        '\u001b[0;0mDecoding the DSL into Swift types\n' +
        '\u001b[0;0m\u001b[31mERROR: Failed to parse JSON: valueNotFound(Swift.String, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "danger", intValue: nil), CodingKeys(stringValue: "git", intValue: nil), CodingKeys(stringValue: "created_files", intValue: nil), _JSONKey(stringValue: "Index 45", intValue: 45)], debugDescription: "Expected String but found null value instead.", underlyingError: nil))\n' +
        '\u001b[0;0mdanger-results://var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json\n' +
        '\n' +
        'Got URL for JSON: /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json\n' +
        '\u001b[0;0mCreated a temporary file for the Dangerfile DSL at: /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json\n' +
        '\u001b[0;0mRunning Dangerfile at: Dangerfile.swift\n' +
        '\u001b[0;0mPreparing to compile\n' +
        '\u001b[0;0mRunning: /usr/bin/swiftc --driver-mode=swift -L /Users/admin/Desktop/REDACTED/proapp/.build/debug -I /Users/admin/Desktop/REDACTED/proapp/.build/debug -lDanger /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/_tmp_dangerfile.swift /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json\n' +
        '\u001b[0;0mCompleted evaluation\n' +
        '\u001b[0;0m\u001b[31mERROR: Dangerfile eval failed at Dangerfile.swift\n' +
        '\u001b[0;0mSaving and storing the results at /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json\n' +
        '\u001b[0;0m\n' +
        '```\n'
    }
  ]
} +0ms
  danger:executor Evaluator settings {
  stdoutOnly: true,
  verbose: undefined,
  jsonOnly: false,
  dangerID: 'default',
  passURLForDSL: true
} +3ms
  danger:executor Writing to STDOUT: {
  warnings: [],
  messages: [
    {
      message: 'These files have changed: CHANGELOG.mdSources/DangerFixtures/DangerFixtures.swiftTests/DangerTests/XCTestManifests.swiftSources/Danger/Plugins/SwiftLint/CurrentPathProvider.swiftSources/Danger/Plugins/SwiftLint/ShellExecutor.swiftSources/Danger/Plugins/SwiftLint/SwiftLint.swiftSources/Danger/Plugins/SwiftLint/SwiftLintViolation.swiftTests/DangerTests/SwiftLint/DangerSwiftLintTests.swiftTests/DangerTests/SwiftLint/FakeCurrentPathProvider.swiftTests/DangerTests/SwiftLint/FakeShellExecutor.swiftTests/DangerTests/SwiftLint/URL+Utils.swiftTests/DangerTests/SwiftLint/ViolationTests.swift'
    }
  ],
  fails: [ { message: 'danger-swift` failed.' } ],
  markdowns: [
    {
      message: '### Log\n' +
        '\n' +
        '\n' +
        '```sh\n' +
        'Ran with: /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/_tmp_dangerfile.swift /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json\n' +
        '\u001b[0;0mDecoding the DSL into Swift types\n' +
        '\u001b[0;0m\u001b[31mERROR: Failed to parse JSON: valueNotFound(Swift.String, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "danger", intValue: nil), CodingKeys(stringValue: "git", intValue: nil), CodingKeys(stringValue: "created_files", intValue: nil), _JSONKey(stringValue: "Index 45", intValue: 45)], debugDescription: "Expected String but found null value instead.", underlyingError: nil))\n' +
        '\u001b[0;0mdanger-results://var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json\n' +
        '\n' +
        'Got URL for JSON: /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json\n' +
        '\u001b[0;0mCreated a temporary file for the Dangerfile DSL at: /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json\n' +
        '\u001b[0;0mRunning Dangerfile at: Dangerfile.swift\n' +
        '\u001b[0;0mPreparing to compile\n' +
        '\u001b[0;0mRunning: /usr/bin/swiftc --driver-mode=swift -L /Users/admin/Desktop/REDACTED/proapp/.build/debug -I /Users/admin/Desktop/REDACTED/proapp/.build/debug -lDanger /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/_tmp_dangerfile.swift /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json\n' +
        '\u001b[0;0mCompleted evaluation\n' +
        '\u001b[0;0m\u001b[31mERROR: Dangerfile eval failed at Dangerfile.swift\n' +
        '\u001b[0;0mSaving and storing the results at /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json\n' +
        '\u001b[0;0m\n' +
        '```\n'
    }
  ]
} +0ms
Danger: ⅹ Failing the build, there is 1 fail.
## Failures
danger-swift` failed.
## Messages
These files have changed: CHANGELOG.mdSources/DangerFixtures/DangerFixtures.swiftTests/DangerTests/XCTestManifests.swiftSources/Danger/Plugins/SwiftLint/CurrentPathProvider.swiftSources/Danger/Plugins/SwiftLint/ShellExecutor.swiftSources/Danger/Plugins/SwiftLint/SwiftLint.swiftSources/Danger/Plugins/SwiftLint/SwiftLintViolation.swiftTests/DangerTests/SwiftLint/DangerSwiftLintTests.swiftTests/DangerTests/SwiftLint/FakeCurrentPathProvider.swiftTests/DangerTests/SwiftLint/FakeShellExecutor.swiftTests/DangerTests/SwiftLint/URL+Utils.swiftTests/DangerTests/SwiftLint/ViolationTests.swift
## Markdowns
### Log

```sh
Ran with: /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/_tmp_dangerfile.swift /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json
Decoding the DSL into Swift types
ERROR: Failed to parse JSON: valueNotFound(Swift.String, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "danger", intValue: nil), CodingKeys(stringValue: "git", intValue: nil), CodingKeys(stringValue: "created_files", intValue: nil), _JSONKey(stringValue: "Index 45", intValue: 45)], debugDescription: "Expected String but found null value instead.", underlyingError: nil))
danger-results://var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json

Got URL for JSON: /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json
Created a temporary file for the Dangerfile DSL at: /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json
Running Dangerfile at: Dangerfile.swift
Preparing to compile
Running: /usr/bin/swiftc --driver-mode=swift -L /Users/admin/Desktop/REDACTED/proapp/.build/debug -I /Users/admin/Desktop/REDACTED/proapp/.build/debug -lDanger /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/_tmp_dangerfile.swift /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-dsl.json /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json
Completed evaluation
ERROR: Dangerfile eval failed at Dangerfile.swift
Saving and storing the results at /var/folders/6c/_dj0nh5s7g1b0w29rkn6j34r0000gn/T/danger-response.json

The message I get from Danger is consistent with what's in my Dangerfile but it doesn't looks like it runs on the right project.

I tried to wrap my head around the meaning of ERROR: Failed to parse JSON: valueNotFound(Swift.String, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "danger", intValue: nil), CodingKeys(stringValue: "git", intValue: nil), CodingKeys(stringValue: "created_files", intValue: nil), _JSONKey(stringValue: "Index 45", intValue: 45)], debugDescription: "Expected String but found null value instead.", underlyingError: nil)) from other similar issues but in vain too

Looking forward to your answer and thank you for your time !

f-meloni commented 5 years ago

This looks a danger-js issue, in the array of the files the item at index 45 is nill, I don't know why, it probably is related to your diff from master (danger-swift local uses your diff from your branch to master)

MinuteCode commented 5 years ago

Hi, thanks for your answer !

At first I didn't have the master branch locally so I took care of that. I will try and merge where I can to reduce the diff output it's been a long time coming anyway :) Maybe this will work out.

Is there a way that I could set the branch against which danger has to work ?

f-meloni commented 5 years ago

No, but I think it could be a good addition to https://github.com/danger/danger-js/blob/master/source/commands/danger-local.ts

f-meloni commented 5 years ago

You can actually use --base to set the branch, I think

MinuteCode commented 5 years ago

Ok thanks ! Will try that