diff --git a/shard.lock.1 b/shard.lock.1 new file mode 100644 index 0000000..44b13c7 --- /dev/null +++ b/shard.lock.1 @@ -0,0 +1,46 @@ +version: 2.0 +shards: + carbon: + git: https://github.com/luckyframework/carbon.git + version: 0.2.1 + + carbon_smtp_adapter: + hg: https://hg.sr.ht/~peterhoeg/dummy + version: 0.1.1+hg.commit.4048cd7e156f3d4317e10ebd4e742020c8049310 + + email: + git: https://github.com/arcage/crystal-email.git + version: 0.6.4 + + habitat: + git: https://github.com/luckyframework/habitat.git + version: 0.4.8 + + libremiliacr: + fossil: https://chiselapp.com/user/MistressRemilia/repository/libremiliacr + version: 0.90.6 + + lucky_task: + git: https://github.com/luckyframework/lucky_task.git + version: 0.1.1 + + teeplate: + git: https://github.com/luckyframework/teeplate.git + version: 0.8.5 + + version_from_shard: + git: https://github.com/hugopl/version_from_shard.git + version: 1.2.5 + + wordsmith: + git: https://github.com/luckyframework/wordsmith.git + version: 0.3.0 + + yunosynth: + fossil: https://chiselapp.com/user/MistressRemilia/repository/yunosynth + version: 0.4.2+fossil.commit.e820a8489011d22d43383526726b40695238c79d8e8b335fbf60a42dd0215544 + + zstd: + git: https://github.com/didactic-drunk/zstd.cr.git + version: 1.2.0 + diff --git a/shard.yml b/shard.yml index db1c628..0349094 100644 --- a/shard.yml +++ b/shard.yml @@ -1,4 +1,3 @@ ---- name: crystal2nix version: 0.3.0 license: MIT @@ -18,12 +17,11 @@ dependencies: github: hugopl/version_from_shard version: ~> 1.2.4 + carbon_smtp_adapter: + hg: https://hg.sr.ht/~peterhoeg/dummy + version: ~> 0.1.1 + development_dependencies: spectator: gitlab: arctic-fox/spectator version: ~> 0.10.5 - -dependencies: - carbon_smtp_adapter: - hg: https://hg.sr.ht/~peterhoeg/dummy - version: ~> 0.1.1 \ No newline at end of file diff --git a/shards.nix b/shards.nix index 88f502d..e69de29 100644 --- a/shards.nix +++ b/shards.nix @@ -1,21 +0,0 @@ -{ - spectator = { - url = "https://gitlab.com/arctic-fox/spectator.git"; - rev = "v0.10.5"; - sha256 = "1fgjz5vg59h4m25v4fjklimcdn62ngqbchm00kw1160ggjpgpzw2"; - }; - version_from_shard = { - url = "https://github.com/hugopl/version_from_shard.git"; - rev = "v1.2.5"; - sha256 = "0xizj0q4rd541rwjbx04cjifc2gfx4l5v6q2y7gmd0ndjmkgb8ik"; - }; - carbon_smtp_adapter = { - hg = "https://hg.sr.ht/~peterhoeg/dummy"; - rev = "v0.1.1"; - sha256 = "0kdb0k1xzl4yysfmlif7xmr2mnb3y5f3knqr8dy08f3sq9n31x4z"; - - } -} - - - \ No newline at end of file diff --git a/spec/repo_spec.cr b/spec/repo_spec.cr index c889e98..31a355d 100644 --- a/spec/repo_spec.cr +++ b/spec/repo_spec.cr @@ -1,6 +1,6 @@ require "./spec_helper" -Spectator.describe Crystal2Nix::Repo do +Spectator.describe Repo do context "commit" do let(:with_commit) { <<-EOF @@ -9,12 +9,8 @@ Spectator.describe Crystal2Nix::Repo do EOF } - let(:shard) { - Crystal2Nix::Shard.from_yaml(with_commit) - } - let(:repo) { - Crystal2Nix::Repo.new(shard.url, shard.rev, shard.type) + Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_commit)) } it "should have the commit as revision" do @@ -30,56 +26,12 @@ Spectator.describe Crystal2Nix::Repo do EOF } - let(:shard) { - Crystal2Nix::Shard.from_yaml(with_version) - } - let(:repo) { - Crystal2Nix::Repo.new(shard.url, shard.rev, shard.type) + Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_version)) } it "should prefix version references with a v" do expect(repo.rev).to eq("v0.1.1") end end - - context "http url" do - let(:with_http_url) { - <<-EOF - http: https://example.com/archive.tar.gz - EOF - } - - let(:shard) { - Crystal2Nix::Shard.from_yaml(with_http_url) - } - - let(:repo) { - Crystal2Nix::Repo.new(shard.url, shard.rev, shard.type) - } - - it "should have the correct url" do - expect(repo.url).to eq("https://example.com/archive.tar.gz") - end - end - - context "git without revision" do - let(:without_revision) { - <<-EOF - git: https://github.com/example/repo.git - EOF - } - - let(:shard) { - Crystal2Nix::Shard.from_yaml(without_revision) - } - - let(:repo) { - Crystal2Nix::Repo.new(shard.url, shard.rev, shard.type) - } - - it "should have the correct url" do - expect(repo.url).to eq("https://github.com/example/repo.git") - end - end -end +end \ No newline at end of file diff --git a/src/worker.cr b/src/worker.cr index 3842f04..a12ade3 100644 --- a/src/worker.cr +++ b/src/worker.cr @@ -1,6 +1,34 @@ +require "json" +require "yaml" + module Crystal2Nix SHARDS_NIX = "shards.nix" + class PrefetchJSON + JSON.mapping({ + sha256: String + }) + end + + class Repo + getter url, rev + + def initialize(shard_info) + @url = shard_info["github"]? || shard_info["gitlab"]? || shard_info["url"]? + @rev = shard_info["version"]? || "master" + end + end + + class ShardLock + JSON.mapping({ + shards: Hash(String, Hash(String, String)) + }) + + def self.from_yaml(yaml_str : String) + from_json YAML.parse(yaml_str).to_json + end + end + class Worker def initialize(@lock_file : String) end @@ -14,35 +42,36 @@ module Crystal2Nix STDERR.puts "Unable to parse repository entry" exit 1 end + sha256 = "" - case + + case when repo.url.ends_with?(".git") - - args = [ - "--no-deepClone", - "--url", repo.url, - "--rev", repo.rev, - ] - Process.run("nix-prefetch-git", args: args) do |x| - x.error.each_line { |e| puts e } - sha256 = PrefetchJSON.from_json(x.output).sha256 - end - when repo.url.starts_with?("hg://") || repo.url.ends_with?(".hg") - args = [ - "--url", repo.url, - "--rev", repo.rev, - ] - Process.run("nix-prefetch-hg", args: args) do |x| - x.error.each_line { |e| puts e } - sha256 = PrefetchJSON.from_json(x.output).sha256 + args = [ + "--no-deepClone", + "--url", repo.url, + "--rev", repo.rev, + ] + Process.run("nix-prefetch-git", args: args) do |x| + x.error.each_line { |e| STDERR.puts e } + sha256 = PrefetchJSON.from_json(x.output).sha256 + end + when repo.url.starts_with?("hg://") || repo.url.ends_with?(".hg") + args = [ + "--url", repo.url, + "--rev", repo.rev, + ] + Process.run("nix-prefetch-hg", args: args) do |x| + x.error.each_line { |e| STDERR.puts e } + sha256 = PrefetchJSON.from_json(x.output).sha256 + end + when repo.url.ends_with?(".fossil") + STDERR.puts "Fossil repositories are not supported." + next + else + STDERR.puts "Unknown repository type for #{repo.url}" + next end - when repo.url.ends_with?(".fossil") - STDERR.puts "Fossil repositories are not supported." - next - else - STDERR.puts "Unknown repository type for #{repo.url}" - next - end file.puts %( #{key} = {) file.puts %( url = "#{repo.url}";) @@ -54,4 +83,4 @@ module Crystal2Nix end end end -end \ No newline at end of file +end