fastlane-community / danger-xcov

Danger plugin to validate the code coverage of the files changed in a pull request

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to find any .xccoverage file

weemundo opened this issue · comments

Hi All,

I am trying to run Danger xcov on my Gitlab CI using the following:

xcov.report(
scheme: 'Scheme_Name'
)

I am getting the following error:

[00:24:44]: Unable to find any .xccoverage file.
[00:24:44]: Make sure you have enabled 'Gather code coverage' setting on your scheme settings.
[00:24:44]: Alternatively you can provide the full path to your .xccoverage file.
[!] The exception involves the following plugins:

  • danger-xcov
    bundler: failed to load command: danger (/Users/ios_testing/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/bin/danger)
    Danger::DSLError:
    [!] Invalid Dangerfile file: Error processing coverage file - see the log above. Updating the Danger gem might fix the issue. Your Danger version: 6.0.7, latest Danger version: 6.1.0

However when I run the following command on CI:

xcrun xcov --scheme Scheme_Name --verbose

It successfully generates the report.

I am currently using XCode 11 and it generates .xcresult. Code coverage is turned on and I have tried setting the full path to the report as well but the plugin is unable to find it.

As of Xcode 11 you need to preprocess the xcresult first: https://github.com/ChargePoint/xcparse#code-coverage

So finally working solution for this would be something like this (I'm using Github Actions with Danger and build.sh script file called from the yaml file).

build.sh:

  bundle install
  pod install --repo-update
  set -o pipefail && bundle exec fastlane tests
  echo "Running Danger..."
  xcparse codecov ./fastlane/test_output/app.xcresult ./fastlane/test_coverage
  bundle exec fastlane danger_tests
  rm -fr ./fastlane/test_coverage
  rm -rf ./fastlane/build_folder

Fastfile:

  1. tests:
  desc "Runs app tests - UNIT + UI tests"
  lane :tests do\
    # First build the project to the build_folder directory
    run_tests(
      workspace: WORKSPACE_NAME,
      scheme: TARGET_NAME,
      derived_data_path: "./fastlane/build_folder",
      build_for_testing: true,
      device: "iPhone 11 Pro",
      code_coverage: true
    )
    # Then run tests without building the project itself
    run_tests(
      workspace: WORKSPACE_NAME,
      scheme: TARGET_NAME,
      derived_data_path: "./fastlane/build_folder",
      test_without_building: true,
      device: "iPhone 11 Pro",
      result_bundle: true,
      output_types: "html",
      prelaunch_simulator: true,
      code_coverage: true
    )
  end
  1. danger_tests:
desc "Run Danger check for tests coverage"
  lane :danger_tests do |options|
    danger(
        danger_id: "Tests",
        dangerfile: "DangerfileBuild",
        github_api_token: ENV["GITHUB_API_TOKEN"]
    )
  end
  1. DangerfileBuild:
xcov.report(
   scheme: 'TARGET_NAME',
   workspace: 'WORKSPACE_NAME',
   output_directory: 'xcov_output',
   only_project_targets: true
)

As you can see, the problem here is that I have to run xcparse codecov ./fastlane/test_output/app.xcresult ./fastlane/test_coverage ro get the right file from build folder as xcov works on build folder, but danger-xcov is not updated for that.

Would be nice to update this project.
@joshdholtz