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

Improve error handling for missing dependency versions for github actions #11144

Merged
merged 4 commits into from
Dec 19, 2024
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
22 changes: 22 additions & 0 deletions common/lib/dependabot/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ def self.parser_error_details(error)
"error-type": "git_dependencies_not_reachable",
"error-detail": { "dependency-urls": error.dependency_urls }
}
when Dependabot::UnresolvableVersionError
{
"error-type": "unresolvable_version",
"error-detail": { dependencies: error.dependencies }
}
when Dependabot::NotImplemented
{
"error-type": "not_implemented",
Expand Down Expand Up @@ -661,6 +666,23 @@ def initialize(dependencies)
end
end

class UnresolvableVersionError < DependabotError
extend T::Sig

sig { returns(T::Array[String]) }
attr_reader :dependencies

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding a new class; I think you'll have to make some changes on the API end too to get this error to sho up. @kbukum1 , can you share some sample past PRs?

sig { params(dependencies: T::Array[String]).void }
def initialize(dependencies)
@dependencies = dependencies

msg = "Unable to determine semantic version from tags or commits for dependencies. " \
"Dependencies must have a tag or commit that references a semantic version. " \
"Affected dependencies: #{@dependencies.join(', ')}"
super(msg)
end
end

class GitDependenciesNotReachable < DependabotError
extend T::Sig

Expand Down
6 changes: 6 additions & 0 deletions github_actions/lib/dependabot/github_actions/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def parse
dependency_set += workfile_file_dependencies(file)
end

dependencies_without_version = dependency_set.dependencies.select { |dep| dep.version.nil? }
unless dependencies_without_version.empty?
raise UnresolvableVersionError,
dependencies_without_version.map(&:name)
end

dependency_set.dependencies
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,5 +560,26 @@ def mock_service_pack_request(nwo)
end
end
end

context "with an unresolvable version" do
let(:workflow_file_fixture_name) { "unresolved_version.yml" }
let(:service_pack_url) do
"https://github.com/taiki-e/install-action.git/info/refs" \
"?service=git-upload-pack"
end

before do
mock_service_pack_request("taiki-e/install-action")
end

it "raises an UnresolvableVersionError error" do
expect { parser.parse }.to raise_error(
Dependabot::UnresolvableVersionError,
"Unable to determine semantic version from tags or commits for dependencies. " \
"Dependencies must have a tag or commit that references a semantic version. " \
"Affected dependencies: taiki-e/install-action"
)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
on: [push]

name: Integration
jobs:
chore:
steps:
- uses: taiki-e/install-action@nextest
Loading