Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'No such file or directory' when the Gemfile and Dangerfile is in a different location than the root #175

Open
ghost opened this issue Nov 29, 2021 · 1 comment

Comments

@ghost
Copy link

ghost commented Nov 29, 2021

I am using Bitrise as a CI/CD tool and I have an issue when I am running Danger-swiftlint for my project:

error opening input file '/Users/vagrant/git/ios/ios/Main/fileFolder/fileWithLintError.swift' (No such file or directory)
Most rules will be skipped because sourcekitd has failed.
SourceKittenFramework/File.swift:20: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=260 "The file “fileWithLintError.swift” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/vagrant/git/ios/ios//Main/fileFolder/fileWithLintError.swift, NSUnderlyingError=0x7fac62b05480 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

The cause of this issue probably is a double ios value in the path because when I moved Danger and Gemfile file into the root folder it works. We are using Kotlin Multiplatform and our root folder for iOS is project_catalouge/ios/ and there is no possibility to keep these files there.

Is there any workaround for this or a way to pass a different execution path?

My Danger file setup:

swiftlint.config_file = '.swiftlint.yml'
swiftlint.binary_path = 'ios/Pods/SwiftLint/swiftlint'
swiftlint.lint_files fail_on_error: true, inline_mode: true

Bitrise job for running Danger:

    - script:
        run_if: ".IsPR"
        inputs:
        - content: |-
            #!/bin/bash
            set -ex
            bundle exec danger --fail-on-errors=true
        - working_dir: "$BITRISE_SOURCE_DIR/ios"
@Skoti
Copy link

Skoti commented Feb 4, 2022

This is actually an issue in Danger itself.
This plugin uses Git module from Danger.
So here the git.renamed_files, git.modified_files and git.added_files already return incorrect paths (basically with the subdir path added again unnecessarily). So in your case ios is added twice as this is probably the directory where your Dangerfile is located.

def find_swift_files(dir_selected, files = nil, excluded_paths = [], included_paths = [])
# Assign files to lint
if files.nil?
renamed_files_hash = git.renamed_files.map { |rename| [rename[:before], rename[:after]] }.to_h
post_rename_modified_files = git.modified_files.map { |modified_file| renamed_files_hash[modified_file] || modified_file }
files = (post_rename_modified_files - git.deleted_files) + git.added_files

So you can either provide the paths to files yourself or temporary workaround by linting all files instead of only modified in the PR.
Set swiftlint.lint_all_files = true and it will omit the part of code that uses flawed Danger methods.:

if lint_all_files
issues = run_swiftlint(options, additional_swiftlint_args)
else
# Extract swift files (ignoring excluded ones)
files = find_swift_files(dir_selected, files, excluded_paths, included_paths)
log "Swiftlint will lint the following files: #{files.join(', ')}"
# Lint each file and collect the results
issues = run_swiftlint_for_each(files, options, additional_swiftlint_args)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant