Skip to content

Commit

Permalink
Merge pull request #11055 from dependabot/dev/brettfo/nuget-rerun-dis…
Browse files Browse the repository at this point in the history
…covery

allow discovery to re-run if files are missing; log errors
  • Loading branch information
randhircs authored Dec 5, 2024
2 parents 6d1fb85 + 549444b commit 10033ae
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
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)
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)
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 }
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")
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"

# 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

0 comments on commit 10033ae

Please sign in to comment.