ashfurrow / danger-ruby-swiftlint

A Danger plugin for SwiftLint.
https://rubygems.org/gems/danger-swiftlint
MIT License
203 stars 80 forks source link

Error after upgrading danger-swiftlint to 0.36.0 #201

Closed michaeleustace closed 3 months ago

michaeleustace commented 3 months ago
Using danger 9.4.3
Using danger-gitlab 8.0.0
Using danger-plugin-api 1.0.0
Using danger-swiftlint 0.36.0
Using gitlab-dangerfiles 4.7.0
Using danger-jira 0.9.1
Bundle complete! 7 Gemfile dependencies, 40 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
$ danger
---------------------------------------------
Checking SwiftLint...
/Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-swiftlint-0.36.0/lib/danger_plugin.rb:[68](https://gitlab.mkodo.net/blah/blah/-/jobs/162133#L68):in `lint_files': \e[31m (Danger::DSLError)
[!] Invalid `Dangerfile` file: swiftlint is not installed\e[0m
 #  from Dangerfile:11
 #  -------------------------------------------
 #      
 >      CodeAnalysis.check_swiftlint(swiftlint, git)
 #      CodeAnalysis.find_unused_swift_items(git, self)
 #  -------------------------------------------
    from /Users/jenkins/builds/SDbktd4d/0/blah/blah/danger/code_analysis.rb:12:in `check_swiftlint'
    from Dangerfile:11:in `eval_file'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:311:in `eval'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:311:in `eval_file'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:204:in `block in parse'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:201:in `instance_eval'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:201:in `parse'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:287:in `run'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/danger_core/executor.rb:28:in `run'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/commands/runner.rb:[73](https://gitlab.mkodo.net/blah/blah/-/jobs/162133#L73):in `run'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/claide-1.1.0/lib/claide/command.rb:334:in `run'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/bin/danger:5:in `<top (required)>'
    from /Users/jenkins/.rbenv/versions/3.0.6/bin/danger:25:in `load'
    from /Users/jenkins/.rbenv/versions/3.0.6/bin/danger:25:in `<main>'
/Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-swiftlint-0.36.0/lib/danger_plugin.rb:68:in `lint_files': swiftlint is not installed (RuntimeError)
    from /Users/jenkins/builds/SDbktd4d/0/blah/blah/danger/code_analysis.rb:12:in `check_swiftlint'
    from Dangerfile:11:in `eval_file'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:311:in `eval'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:311:in `eval_file'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:204:in `block in parse'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:201:in `instance_eval'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:201:in `parse'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:287:in `run'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/danger_core/executor.rb:28:in `run'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/lib/danger/commands/runner.rb:73:in `run'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/claide-1.1.0/lib/claide/command.rb:334:in `run'
    from /Users/jenkins/.rbenv/versions/3.0.6/lib/ruby/gems/3.0.0/gems/danger-9.4.3/bin/danger:5:in `<top (required)>'
    from /Users/jenkins/.rbenv/versions/3.0.6/bin/danger:25:in `load'
    from /Users/jenkins/.rbenv/versions/3.0.6/bin/danger:25:in `<main>'
[!] The exception involves the following plugins:
 -  danger-swiftlint
BenoitDeguine commented 3 months ago

I got the same issue since today. Forcing 0.35.0 version working fine

ashfurrow commented 3 months ago

Gotcha, sorry you're running into that issue. The only meaningful change in 0.36.0 was an update to Swiftlint itself in #200. @aiKrice does this issue look related?

aiKrice commented 3 months ago

(nudging works well !)

Can you put a piece of your dangerfile ?

I will try later in the day, (I use the binary_path with a localversion of swiftlint)

aiKrice commented 3 months ago

Hello @ashfurrow , I don't understand what's wrong but indeed locally it's break if I don't use the binary_path (so the local version of swiftlint downloaded by the tools). I double check the ash and the version and it looks good. Do you have an idea why it could fail (any hint?)

michaeleustace commented 3 months ago

@aiKrice We are running Danger in GitLab runners.

Gemfile:

source "https://rubygems.org"

gem "bundler"
gem "danger"
gem "danger-gitlab"
gem "danger-swiftlint"
gem "gitlab-dangerfiles"
gem "danger-jira"
gem "git_diff_parser"

Dangerfile (only showing relevant part):

require "./danger/code_analysis.rb"

# Perform only when merging into develop
if gitlab.branch_for_merge.include? "develop"
    CodeAnalysis.check_swiftlint(swiftlint, git)
end

and the CodeAnalysis file:

class CodeAnalysis
    def self.check_swiftlint(swiftlint, git)
        puts "Checking SwiftLint..."
        swiftlint.config_file = '.swiftlint.yml'
        swiftlint.lint_files(inline_mode: true) { |violation|
            ... does some stuff here
        }
    end
end

.gitlab-ci.ym stagel:

build_danger:
  stage: build
  before_script:
    - bundle install --gemfile="danger/Gemfile"
  script:
    - danger
  only:
    - merge_requests
  tags:
    - macOS
aiKrice commented 3 months ago

The issue was solved. Can you double check please

michaeleustace commented 3 months ago

@aiKrice Does it need a new version bump? - latest gem is still pointing to 0.36.0

psicot commented 3 months ago

Hello, we have the same error on Bitrise:

Running danger
$ bundle "exec" "danger" "--fail-on-errors=true"
bundler: failed to load command: danger (/Users/vagrant/.asdf/installs/ruby/3.2.4/bin/danger)
/Users/vagrant/.asdf/installs/ruby/3.2.4/lib/ruby/gems/3.2.0/gems/danger-swiftlint-0.36.0/lib/danger_plugin.rb:68:in `lint_files':  (Danger::DSLError)
[!] Invalid `Dangerfile` file: swiftlint is not installed
aiKrice commented 3 months ago

@ashfurrow . I think I can't push the new version of the gem. I already prepare a tag (i am not very familiar to rubygems deployment. I tried gem push command but unsuccessfully. I think my last commit is fine. Can you finish or tell me what to do ?

antonio-zdelican-tg commented 3 months ago

Last gem still pointing to 0.36.0. Please update rubygems: https://rubygems.org/gems/danger-swiftlint/versions and have it to 0.36.1

aiKrice commented 3 months ago

I can't :( Nudge @ashfurrow

ashfurrow commented 3 months ago

Hey, sorry for the delayed response from me here.

First and foremost, thank you to @thomasjoulin for opening the PR that fixed this and to @aiKrice for reviewing the PR and tagging a new release.

I'm still the only owner on rubygems.org which is why the tag alone didn't work. I have pushed up the 0.36.1 version so this should work now.

If anyone runs into this kind of problem again, you can specify a last-known good version in your Gemfile:

gem 'danger-swiftlint', '0.35.0'

This locks bundler to using the old version, but of course you'd also have the old version of SwiftLint, too. Not my intention to assign blame here – I should have responded sooner – I only want to share a potential workaround.

Let's keep this issue open until someone can confirm it's fixed for them.

michaeleustace commented 3 months ago

@ashfurrow I am using 0.36.1 now and it works successfully, thanks.

ashfurrow commented 3 months ago

@michaeleustace wonderful, I’m glad to hear it’s working! Sorry again for the delay on my side.