Skip to content

Commit

Permalink
error in the shards
Browse files Browse the repository at this point in the history
  • Loading branch information
vidhvath authored and vidhvath committed Jun 11, 2024
1 parent 5ef2a09 commit 785776f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 106 deletions.
46 changes: 46 additions & 0 deletions shard.lock.1
Original file line number Diff line number Diff line change
@@ -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

10 changes: 4 additions & 6 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: crystal2nix
version: 0.3.0
license: MIT
Expand All @@ -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
21 changes: 0 additions & 21 deletions shards.nix
Original file line number Diff line number Diff line change
@@ -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";

}
}



56 changes: 4 additions & 52 deletions spec/repo_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "./spec_helper"

Spectator.describe Crystal2Nix::Repo do
Spectator.describe Repo do
context "commit" do
let(:with_commit) {
<<-EOF
Expand All @@ -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
Expand All @@ -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
83 changes: 56 additions & 27 deletions src/worker.cr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}";)
Expand All @@ -54,4 +83,4 @@ module Crystal2Nix
end
end
end
end
end

0 comments on commit 785776f

Please sign in to comment.