From 3deb154f41148cdd088cb18e0c3e416404ef3e34 Mon Sep 17 00:00:00 2001 From: vidhvath28 Date: Fri, 30 Aug 2024 21:14:53 +0530 Subject: [PATCH] added --- shards.nix | 12 ++++++++++++ src/worker.cr | 25 ++++++++++++------------- 2 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 shards.nix diff --git a/shards.nix b/shards.nix new file mode 100644 index 0000000..8444749 --- /dev/null +++ b/shards.nix @@ -0,0 +1,12 @@ +{ + spectator = { + url = "https://gitlab.com/arctic-fox/spectator.git"; + rev = "v0.10.6"; + sha256 = "0w6mv1q44is2m19pyspkyiwm84h55nchsm4pp82gdbb0j9ylhckx"; + }; + version_from_shard = { + url = "https://github.com/hugopl/version_from_shard.git"; + rev = "v1.2.5"; + sha256 = "0xizj0q4rd541rwjbx04cjifc2gfx4l5v6q2y7gmd0ndjmkgb8ik"; + }; +} diff --git a/src/worker.cr b/src/worker.cr index 86b1cfe..84d546b 100644 --- a/src/worker.cr +++ b/src/worker.cr @@ -12,7 +12,6 @@ module Crystal2Nix end def run - errors = [] of String temp_file_path = "#{SHARDS_NIX}.tmp" File.open temp_file_path, "w+" do |file| @@ -21,8 +20,7 @@ module Crystal2Nix begin repo = Repo.new value rescue ex : Exception - log_message = "Error processing repository '#{key}': #{ex.message}. Please check the repository details and try again." - + log_message "Error processing repository '#{key}': #{ex.message}. Please check the repository details and try again." next end @@ -41,11 +39,10 @@ module Crystal2Nix sha256 = GitPrefetchJSON.from_json(json_output).sha256 end rescue ex : Exception - log_message = "Error running nix-prefetch-git for '#{key}': #{ex.message}. + log_message "Error running nix-prefetch-git for '#{key}': #{ex.message}. Try running the command manually to troubleshoot: nix-prefetch-git #{args.join " "} Ensure that the git repository is accessible and try again." - next end @@ -61,19 +58,18 @@ module Crystal2Nix sha256 = output.strip.split("\n").first end rescue ex : Exception - log_message = "Error running nix-prefetch-hg for '#{key}': #{ex.message}. + log_message "Error running nix-prefetch-hg for '#{key}': #{ex.message}. Try running the command manually to troubleshoot: nix-prefetch-hg #{args.join " "} Ensure that the Mercurial repository is accessible and try again." - next end else - log_message = "Unsupported repository type for '#{key}': #{repo.type}. Currently supported types are: git, hg. Please update your configuration or contact support for further assistance." - + log_message "Unsupported repository type for '#{key}': #{repo.type}. Currently supported types are: git, hg. Please update your configuration or contact support for further assistance." break end + file.puts %( #{key} = {) file.puts %( url = "#{repo.url}";) file.puts %( rev = "#{repo.rev}";) @@ -82,15 +78,18 @@ module Crystal2Nix end file.puts %(}) end - if errors.empty? + + # Check the instance variable @errors instead of the local errors array + if @errors.any? File.delete(temp_file_path) STDERR.puts "\nSummary of errors encountered:" - errors.each { |error| STDERR.puts " - #{error}" } + @errors.each { |error| STDERR.puts " - #{error}" } STDERR.puts "\nProcess not completed due to the above errors. Please review and resolve them before re-running." exit 1 end - File.rename(temp_file_path, SHARDS_NIX) - puts "Processing completed successfully with no errors." + + File.rename(temp_file_path, SHARDS_NIX) + puts "Processing completed successfully with no errors." end end end