Skip to content

Commit 3084edd

Browse files
committed
Fix: consider version tag as actual version
Pre-releases weren't supported in Shards 0.8 and below, the only solution was to use a tag to exactly match a pre-release. Since a version is represented as a version tag in Shards, we can safely report a version tag as the dependency version.
1 parent a2a5e79 commit 3084edd

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/dependency.cr

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,23 @@ module Shards
1212
end
1313
end
1414

15-
def initialize(@name)
15+
protected def initialize(@name)
1616
super()
1717
end
1818

19-
# DEPRECATED: with no replacement
20-
def initialize(@name, config)
19+
protected def initialize(@name, config)
2120
super()
2221
config.each { |k, v| self[k.to_s] = v.to_s }
2322
end
2423

2524
def version
26-
fetch("version", "*")
25+
if version = self["version"]?
26+
version
27+
elsif self["tag"]? =~ VERSION_TAG
28+
$1
29+
else
30+
"*"
31+
end
2732
end
2833

2934
def refs

test/dependency_test.cr

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require "./test_helper"
2+
3+
class Shards::DependencyTest < Minitest::Test
4+
def test_version
5+
dependency = Dependency.new("app")
6+
assert_equal "*", dependency.version
7+
8+
dependency = Dependency.new("app", {version: "*"})
9+
assert_equal "*", dependency.version
10+
11+
dependency = Dependency.new("app", {version: "1.0.0"})
12+
assert_equal "1.0.0", dependency.version
13+
14+
dependency = Dependency.new("app", {version: "<= 2.0.0"})
15+
assert_equal "<= 2.0.0", dependency.version
16+
end
17+
18+
def test_version_with_tags
19+
dependency = Dependency.new("app", { tag: "fix/something" })
20+
assert_equal "*", dependency.version
21+
22+
dependency = Dependency.new("app", { tag: "1.2.3" })
23+
assert_equal "*", dependency.version
24+
25+
# version tag is considered a version:
26+
dependency = Dependency.new("app", { tag: "v1.2.3-pre1" })
27+
assert_equal "1.2.3-pre1", dependency.version
28+
end
29+
end

0 commit comments

Comments
 (0)