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

Ensure Docker versions are valid Dependabot::Versions #7984

Merged
merged 5 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions docker/lib/dependabot/docker/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ class Version < Dependabot::Version
def initialize(version)
release_part, update_part = version.split("_", 2)

@release_part = Dependabot::Version.new(release_part.tr("-", "."))
@release_part = Dependabot::Version.new(release_part.sub("v", "").tr("-", "."))

@update_part = Dependabot::Version.new(update_part&.start_with?(/[0-9]/) ? update_part : 0)
end

def self.correct?(version)
super(new(version).to_semver)
rescue ArgumentError
# if we can't instantiate a version, it can't be correct
false
super(@release_part)
end

def to_semver
Expand Down
12 changes: 9 additions & 3 deletions docker/spec/dependabot/docker/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@
end

describe ".correct?" do
def check_version_for_correctness?(version)
docker_version = described_class.new(version)
described_class.correct?(docker_version)
end

it "classifies standard versions as correct" do
expect(described_class.correct?("2.4.2")).to be true
expect(check_version_for_correctness?("2.4.2")).to be true
end

it "classifies java versions as correct" do
expect(described_class.correct?("11.0.16_8")).to be true
expect(described_class.correct?("11.0.16.1")).to be true
expect(check_version_for_correctness?("11.0.16_8")).to be true
expect(check_version_for_correctness?("v11.0.16_8")).to be true
expect(check_version_for_correctness?("11.0.16.1")).to be true
end
end

Expand Down
5 changes: 4 additions & 1 deletion updater/lib/dependabot/updater/group_update_creation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,11 @@ def semver_rules_allow_grouping?(group, dependency, checker)
return false if git_dependency?(dependency)

version = Dependabot::Utils.version_class_for_package_manager(job.package_manager).new(dependency.version.to_s)
latest_version = Dependabot::Utils.version_class_for_package_manager(job.package_manager).
new(checker.latest_version)

# Not every version class implements .major, .minor, .patch so we calculate it here from the segments
latest = semver_segments(checker.latest_version)
latest = semver_segments(latest_version)
current = semver_segments(version)
return group.rules["update-types"].include?("major") if latest[:major] > current[:major]
return group.rules["update-types"].include?("minor") if latest[:minor] > current[:minor]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,13 @@
expect(dependency_change.updated_dependency_files_hash.length).to eql(2)
expect(dependency_change.updated_dependency_files.map(&:name)).
to eql(%w(Dockerfile.bundler Dockerfile.cargo))

# We are able to handle the irregular semver version strings like "v2.0.20230509134123"
expect(
dependency_change.updated_dependencies.
map { |dependency| Dependabot::Docker::Version.new(dependency.version) }.
all? { |dependency| Dependabot::Docker::Version.correct?(dependency) }
).to be_truthy
end

group_update_all.perform
Expand Down
Loading