diff --git a/nuget/lib/dependabot/nuget/file_fetcher.rb b/nuget/lib/dependabot/nuget/file_fetcher.rb index 5dacfd983e..5f6a84b034 100644 --- a/nuget/lib/dependabot/nuget/file_fetcher.rb +++ b/nuget/lib/dependabot/nuget/file_fetcher.rb @@ -32,6 +32,7 @@ def fetch_files credentials: credentials ) + NativeDiscoveryJsonReader.debug_report_discovery_files(error_if_missing: false) 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) diff --git a/nuget/lib/dependabot/nuget/file_parser.rb b/nuget/lib/dependabot/nuget/file_parser.rb index 5663c777b4..334f18622a 100644 --- a/nuget/lib/dependabot/nuget/file_parser.rb +++ b/nuget/lib/dependabot/nuget/file_parser.rb @@ -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) + directory = source&.directory || "/" + discovery_json_reader = NativeDiscoveryJsonReader.run_discovery_in_directory( + 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 } diff --git a/nuget/lib/dependabot/nuget/native_discovery/native_discovery_json_reader.rb b/nuget/lib/dependabot/nuget/native_discovery/native_discovery_json_reader.rb index 7bcaadb865..2dd7ebff0b 100644 --- a/nuget/lib/dependabot/nuget/native_discovery/native_discovery_json_reader.rb +++ b/nuget/lib/dependabot/nuget/native_discovery/native_discovery_json_reader.rb @@ -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") + 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 diff --git a/nuget/script/run b/nuget/script/run index eaea942642..ea09331823 100644 --- a/nuget/script/run +++ b/nuget/script/run @@ -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" + + # 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