Skip to content

Commit

Permalink
Fix updating GitHub Actions with mixed versions
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Dec 28, 2022
1 parent 06702c8 commit bac23a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
31 changes: 19 additions & 12 deletions common/lib/dependabot/file_parsers/base/dependency_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,10 @@ def <<(dep)

# Produces a new dependency by merging the attributes of `old_dep` with those of
# `new_dep`. Requirements and subdependency metadata will be combined and deduped.
# The version of the combined dependency is determined by the logic below.
# The version of the combined dependency is determined by the
# `#combined_version` method below.
def combined_dependency(old_dep, new_dep)
version = if old_dep.top_level? # Prefer a direct dependency over a transitive one
old_dep.version || new_dep.version
elsif !version_class.correct?(new_dep.version)
old_dep.version
elsif !version_class.correct?(old_dep.version)
new_dep.version
elsif version_class.new(new_dep.version) > version_class.new(old_dep.version)
old_dep.version
else
new_dep.version
end
version = combined_version(old_dep, new_dep)
requirements = (old_dep.requirements + new_dep.requirements).uniq
subdependency_metadata = (
(old_dep.subdependency_metadata || []) +
Expand All @@ -145,6 +136,22 @@ def combined_dependency(old_dep, new_dep)
)
end

def combined_version(old_dep, new_dep)
if old_dep.version.nil? ^ new_dep.version.nil?
[old_dep, new_dep].find(&:version).version
elsif old_dep.top_level? ^ new_dep.top_level? # Prefer a direct dependency over a transitive one
[old_dep, new_dep].find(&:top_level?).version
elsif !version_class.correct?(new_dep.version)
old_dep.version
elsif !version_class.correct?(old_dep.version)
new_dep.version
elsif version_class.new(new_dep.version) > version_class.new(old_dep.version)
old_dep.version
else
new_dep.version
end
end

def version_class
@version_class ||= Utils.version_class_for_package_manager(@combined.package_manager)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ def lowest_resolvable_security_fix_version
lowest_security_fix_version
end

def updated_requirements # rubocop:disable Metrics/PerceivedComplexity
def updated_requirements
previous = dependency_source_details
updated = updated_source
return dependency.requirements if updated == previous

# Maintain a short git hash only if it matches the latest
if previous[:type] == "git" &&
Expand Down

0 comments on commit bac23a3

Please sign in to comment.