Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main01 #14

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ We will welcome all help with open arms!

- [Michael Fellinger](https://github.com/manveru)
- [Peter Hoeg](https://github.com/peterhoeg)
- [Vidhvath J](https://github.com/vidhvath28)
Binary file added crystal2nix
Binary file not shown.
3 changes: 3 additions & 0 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ shards:
git: https://github.com/hugopl/version_from_shard.git
version: 1.2.5

carbon_smtp_adapter:
hg: https://hg.sr.ht/~peterhoeg/dummy
version: 0.1.1+hg.commit.4048cd7e156f3d4317e10ebd4e742020c8049310
5 changes: 5 additions & 0 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ 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
9 changes: 9 additions & 0 deletions shards.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@
rev = "v1.2.5";
sha256 = "0xizj0q4rd541rwjbx04cjifc2gfx4l5v6q2y7gmd0ndjmkgb8ik";
};
carbon_smtp_adapter = {
hg = "https://hg.sr.ht/~peterhoeg/dummy";
rev = "v0.1.1";
sha256 = "0kdb0k1xzl4yysfmlif7xmr2mnb3y5f3knqr8dy08f3sq9n31x4z";

}
}



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

Spectator.describe Repo do
Spectator.describe Crystal2Nix::Repo do
context "commit" do
let(:with_commit) {
<<-EOF
Expand All @@ -9,8 +9,12 @@ Spectator.describe Repo do
EOF
}

let(:shard) {
Crystal2Nix::Shard.from_yaml(with_commit)
}

let(:repo) {
Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_commit))
Crystal2Nix::Repo.new(shard.url, shard.rev, shard.type)
}

it "should have the commit as revision" do
Expand All @@ -26,12 +30,56 @@ Spectator.describe Repo do
EOF
}

let(:shard) {
Crystal2Nix::Shard.from_yaml(with_version)
}

let(:repo) {
Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_version))
Crystal2Nix::Repo.new(shard.url, shard.rev, shard.type)
}

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
20 changes: 7 additions & 13 deletions src/repo.cr
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
module Crystal2Nix
class Repo
@url : URI
getter rev : String
property url : String
property rev : String?
property type : Symbol

def initialize(entry : Shard)
@url = URI.parse(entry.git).normalize
@rev = if entry.version =~ /^(?<version>.+)\+git\.commit\.(?<rev>.+)$/
$~["rev"]
else
"v#{entry.version}"
end
end

def url : String
@url.to_s
def initialize(url : String, rev : String? = nil, type : Symbol = :git)
@url = url
@rev = rev
@type = type
end
end
end
2 changes: 1 addition & 1 deletion src/runner.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "./crystal2nix"
require "./cli"

Crystal2Nix::Cli.new.run
Crystal2Nix::Cli.new.run
21 changes: 20 additions & 1 deletion src/worker.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ module Crystal2Nix
exit 1
end
sha256 = ""
case
when repo.url.ends_with?(".git")

args = [
"--no-deepClone",
"--url", repo.url,
Expand All @@ -24,6 +27,22 @@ module Crystal2Nix
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
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 @@ -35,4 +54,4 @@ module Crystal2Nix
end
end
end
end
end
Loading