hbmartin / danger-spm_version_updates

A Danger plugin to detect if there are any updates to your Swift Package Manager dependencies.
https://hbmartin.github.io/danger-spm_version_updates/Danger/DangerSpmVersionUpdates.html
MIT License
5 stars 1 forks source link

[BUG] undefined method `match' for nil:NilClass #1

Closed BartoszCichecki closed 3 months ago

BartoszCichecki commented 3 months ago

There is an issue while running this plugin:

[!] The exception involves the following plugins:
 -  danger-spm_version_updates

/Users/bartosz/.gem/ruby/3.2.3/gems/semantic-1.6.1/lib/semantic/version.rb:13:in `initialize':  (Danger::DSLError)
[!] Invalid `Dangerfile` file: undefined method `match' for nil:NilClass
 #  from Dangerfile:46
 #  -------------------------------------------
 #  spm_version_updates.report_above_maximum = true
 >  spm_version_updates.check_for_updates("Project.xcodeproj")
 #  -------------------------------------------

    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-spm_version_updates-0.1.1/lib/spm_version_updates/plugin.rb:157:in `new'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-spm_version_updates-0.1.1/lib/spm_version_updates/plugin.rb:157:in `warn_for_new_versions'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-spm_version_updates-0.1.1/lib/spm_version_updates/plugin.rb:63:in `block in check_for_updates'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-spm_version_updates-0.1.1/lib/spm_version_updates/plugin.rb:41:in `each'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-spm_version_updates-0.1.1/lib/spm_version_updates/plugin.rb:41:in `check_for_updates'
    from Dangerfile:46:in `eval_file'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:311:in `eval'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:311:in `eval_file'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:204:in `block in parse'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:201:in `instance_eval'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:201:in `parse'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:287:in `run'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/lib/danger/commands/dry_run.rb:44:in `run'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/claide-1.1.0/lib/claide/command.rb:334:in `run'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/bin/danger:5:in `<top (required)>'
    from /Users/bartosz/.gem/ruby/3.2.3/bin/danger:25:in `load'
    from /Users/bartosz/.gem/ruby/3.2.3/bin/danger:25:in `<main>'
/Users/bartosz/.gem/ruby/3.2.3/gems/semantic-1.6.1/lib/semantic/version.rb:13:in `initialize': undefined method `match' for nil:NilClass (NoMethodError)

      v = version_str.match(SemVerRegexp)
                     ^^^^^^
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-spm_version_updates-0.1.1/lib/spm_version_updates/plugin.rb:157:in `new'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-spm_version_updates-0.1.1/lib/spm_version_updates/plugin.rb:157:in `warn_for_new_versions'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-spm_version_updates-0.1.1/lib/spm_version_updates/plugin.rb:63:in `block in check_for_updates'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-spm_version_updates-0.1.1/lib/spm_version_updates/plugin.rb:41:in `each'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-spm_version_updates-0.1.1/lib/spm_version_updates/plugin.rb:41:in `check_for_updates'
    from Dangerfile:46:in `eval_file'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:311:in `eval'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:311:in `eval_file'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:204:in `block in parse'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:201:in `instance_eval'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:201:in `parse'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/lib/danger/danger_core/dangerfile.rb:287:in `run'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/lib/danger/commands/dry_run.rb:44:in `run'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/claide-1.1.0/lib/claide/command.rb:334:in `run'
    from /Users/bartosz/.gem/ruby/3.2.3/gems/danger-9.4.3/bin/danger:5:in `<top (required)>'
    from /Users/bartosz/.gem/ruby/3.2.3/bin/danger:25:in `load'
    from /Users/bartosz/.gem/ruby/3.2.3/bin/danger:25:in `<main>'

Any workarounds?

hbmartin commented 3 months ago

@BartoszCichecki Thanks for the report. This is happening because there is a package listed in your Project.xcodeproj that is missing from your Package.resolved so the plugin has nothing to check against. Do you know why this might be the case for your project? If you are able to put up an example repo I can take a look as well. In the meantime, this crash has been fixed in 0.1.2 and a warning will print to your console or CI logs identifying the missing package.

BartoszCichecki commented 3 months ago

Thanks for quick response. I updated to 0.1.2 and it doesn't crash, but it prints quite a bit of warnings now for what looks to be all packages. For example:

Unable to locate the current version for adjust/ios_sdk (https://github.com/adjust/ios_sdk) in Project.xcworkspace/xcshareddata/swiftpm/Package.resolved and when I check the Package.resolved file, I can find the version:

    {
      "package": "Adjust",
      "repositoryURL": "https://github.com/adjust/ios_sdk",
      "state": {
        "branch": null,
        "revision": "a7b50f187855dfc0fb84114c22661216393387ae",
        "version": "4.32.1"
      }
    },

Danger is configured like this:

# SPM Version Updates
spm_version_updates.check_when_exact = true
spm_version_updates.report_above_maximum = true
spm_version_updates.check_for_updates("Project.xcodeproj")

Both dangerfile, Project.xcodeproj and Project.xcworkspace are in the root dir of the repo. Path to Package.resolved is also correct.

Maybe the parsing of Package.resolved is failiing? Let me know what info you need.

hbmartin commented 3 months ago

Hmm, I'm guessing this is due to how Xcode mangles repo URLs. Can you look at the Adjust URL in Project.xcodeproj/project.xcodeproj?

BartoszCichecki commented 3 months ago
4153F63E28FD5048003BEEA3 /* XCRemoteSwiftPackageReference "ios_sdk" */ = {
            isa = XCRemoteSwiftPackageReference;
            repositoryURL = "https://github.com/adjust/ios_sdk";
            requirement = {
                kind = upToNextMajorVersion;
                minimumVersion = 4.29.0;
            };
        };
hbmartin commented 3 months ago

In addition to having a Project.xcworkspace/xcshareddata/swiftpm/Package.resolved do you also have a Project.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved file? (note in the second path project.xcworkspace is always that name regardless of your actual project name).

Digging around I came across this link https://stackoverflow.com/a/71721448 which suggests there may be multiple .resolved files in projects that use both SPM and CocoaPods. (According to Apple the .xcodeproj form is canonically correct https://developer.apple.com/documentation/xcode/building-swift-packages-or-apps-that-use-them-in-continuous-integration-workflows#Use-the-expected-version-of-a-package-dependency )

I'll release a new version soon to handle this issue and the URL mangling cases, and also add more debug logging. In the meantime you can email me your Package.resolved if you're comfortable with that Harold . Martin @ gmail

hbmartin commented 3 months ago

Working on addressing the multiple resolved files in https://github.com/hbmartin/danger-spm_version_updates/pull/2 Will follow-up on the URL issue in another PR

hbmartin commented 3 months ago

Addressing URL issue in https://github.com/hbmartin/danger-spm_version_updates/pull/3

BartoszCichecki commented 3 months ago

In addition to having a Project.xcworkspace/xcshareddata/swiftpm/Package.resolved do you also have a Project.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved file? (note in the second path project.xcworkspace is always that name regardless of your actual project name).

There is only 1 packaged resolved file: Project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Also tested 1.3 with exactly the same result.

hbmartin commented 3 months ago

I think we're finally on the verge of solving this... does your Package.resolved have "version": 1? If so it's not currently supported... but working on it now should be done tomorrow

BartoszCichecki commented 3 months ago

Yes! Thanks! 👏