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

allow discovery to re-run if files are missing; log errors #11055

Merged
merged 1 commit into from
Dec 5, 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
1 change: 1 addition & 0 deletions nuget/lib/dependabot/nuget/file_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def fetch_files
credentials: credentials
)

NativeDiscoveryJsonReader.debug_report_discovery_files(error_if_missing: false)
brettfo marked this conversation as resolved.
Show resolved Hide resolved
discovery_json_reader.dependency_file_paths.map do |p|
relative_path = Pathname.new(p).relative_path_from(directory).to_path
fetch_file_from_host(relative_path)
Expand Down
14 changes: 10 additions & 4 deletions nuget/lib/dependabot/nuget/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,16 @@ def parse

sig { returns(T::Array[Dependabot::Dependency]) }
def dependencies
@dependencies ||= T.let(NativeDiscoveryJsonReader.load_discovery_for_directory(
repo_contents_path: T.must(repo_contents_path),
directory: source&.directory || "/"
).dependency_set.dependencies, T.nilable(T::Array[Dependabot::Dependency]))
@dependencies ||= T.let(begin
NativeDiscoveryJsonReader.debug_report_discovery_files(error_if_missing: true)
brettfo marked this conversation as resolved.
Show resolved Hide resolved
directory = source&.directory || "/"
discovery_json_reader = NativeDiscoveryJsonReader.run_discovery_in_directory(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method will return the existing discovery JSON if it exists from the previous run, or run it again if required.

repo_contents_path: T.must(repo_contents_path),
directory: directory,
credentials: credentials
)
discovery_json_reader.dependency_set.dependencies
end, T.nilable(T::Array[Dependabot::Dependency]))
end

sig { override.void }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ def self.testonly_clear_discovery_files
FileUtils.rm_rf(discovery_directory)
end

sig { params(error_if_missing: T::Boolean).void }
def self.debug_report_discovery_files(error_if_missing:)
if File.exist?(discovery_map_file_path)
Dependabot.logger.info("Discovery map file (#{discovery_map_file_path}) contents: " \
"#{File.read(discovery_map_file_path)}")
Dependabot.logger.info("Discovery files: #{Dir.glob(File.join(discovery_directory, '*'))}")
elsif error_if_missing
Dependabot.logger.error("discovery map file missing")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This allows PR creation to continue, but will make a handy search point in the logs.

end
end

# Runs NuGet dependency discovery in the given directory and returns a new instance of NativeDiscoveryJsonReader.
# The location of the resultant JSON file is saved.
sig do
Expand Down
14 changes: 14 additions & 0 deletions nuget/script/run
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,19 @@ echo "NuGet native updater experiment value: $nuget_experiment_value"
if echo "$nuget_experiment_value" | grep -q 'true'; then
pwsh "$DEPENDABOT_HOME/dependabot-updater/bin/main.ps1" $*
else
operation=$1
dot_dependabot_directory="$DEPENDABOT_HOME/.dependabot"
discovery_map_path="$dot_dependabot_directory/discovery_map.json"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These checks are just to see what exists on disk before and after the processes are started/ended to help narrow down when and where the files are getting deleted.


# ensure discovery file exists before running update
if [[ "$operation" == "update_files" && ! -f $discovery_map_path ]]; then
echo "ERROR running update_files without discovery_map.json"
fi

"$DEPENDABOT_HOME/dependabot-updater/bin/run-original" $*

# ensure discovery file exists after running fetch
if [[ "$operation" == "fetch_files" && ! -f $discovery_map_path ]]; then
echo "ERROR ran fetch_files without producing discovery_map.json"
fi
fi
Loading