🐛 generalize image name
This commit is contained in:
parent
33cd306ec2
commit
98e188a32f
|
|
@ -12,14 +12,18 @@ def main
|
||||||
# log to stderr so that stdout only contains the full tags
|
# log to stderr so that stdout only contains the full tags
|
||||||
$stderr.puts "'#{git_repo}', '#{git_ref_name}', '#{git_ref_type}', '#{git_default_branch}'"
|
$stderr.puts "'#{git_repo}', '#{git_ref_name}', '#{git_ref_type}', '#{git_default_branch}'"
|
||||||
|
|
||||||
|
image_name = get_image_name(git_repo: git_repo)
|
||||||
|
|
||||||
tags =
|
tags =
|
||||||
get_image_tags(
|
get_image_tags(
|
||||||
git_repo: git_repo,
|
|
||||||
git_ref_name: git_ref_name,
|
git_ref_name: git_ref_name,
|
||||||
git_ref_type: git_ref_type,
|
git_ref_type: git_ref_type,
|
||||||
git_default_branch: git_default_branch,
|
git_default_branch: git_default_branch,
|
||||||
semver: '0.0.0',
|
semver: '0.0.0',
|
||||||
).to_a.join(',')
|
)
|
||||||
|
.to_a
|
||||||
|
.map {|tag| "#{image_name}:#{tag}" }
|
||||||
|
.join(',')
|
||||||
|
|
||||||
# log to stderr so that stdout only contains the full tags
|
# log to stderr so that stdout only contains the full tags
|
||||||
$stderr.puts tags
|
$stderr.puts tags
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,15 @@
|
||||||
require 'set'
|
require 'set'
|
||||||
|
|
||||||
# @param git_repo [String]
|
|
||||||
# @param git_ref_name [String]
|
# @param git_ref_name [String]
|
||||||
# @param git_ref_type [String]
|
# @param git_ref_type [String]
|
||||||
# @param git_default_branch [String]
|
# @param git_default_branch [String]
|
||||||
# @return [Set[String]]
|
# @return [Set[String]]
|
||||||
def get_image_tags(
|
def get_image_tags(
|
||||||
git_repo: nil,
|
|
||||||
git_ref_name: nil,
|
git_ref_name: nil,
|
||||||
git_ref_type: nil,
|
git_ref_type: nil,
|
||||||
git_default_branch: nil,
|
git_default_branch: nil,
|
||||||
semver: nil
|
semver: nil
|
||||||
)
|
)
|
||||||
container_repo = "ghcr.io/#{git_repo.downcase}"
|
|
||||||
versions = Set[]
|
versions = Set[]
|
||||||
|
|
||||||
if git_ref_type == 'branch'
|
if git_ref_type == 'branch'
|
||||||
|
|
@ -24,7 +21,7 @@ def get_image_tags(
|
||||||
# TODO: check that this is actually latest
|
# TODO: check that this is actually latest
|
||||||
parsed = parse_semver(semver)
|
parsed = parse_semver(semver)
|
||||||
if parsed.pre == nil
|
if parsed.pre == nil
|
||||||
versions.add(parsed.major)
|
versions.add(parsed.major.to_s)
|
||||||
versions.add("#{parsed.major}.#{parsed.minor}")
|
versions.add("#{parsed.major}.#{parsed.minor}")
|
||||||
versions.add("#{parsed.major}.#{parsed.minor}.#{parsed.patch}")
|
versions.add("#{parsed.major}.#{parsed.minor}.#{parsed.patch}")
|
||||||
end
|
end
|
||||||
|
|
@ -39,7 +36,18 @@ def get_image_tags(
|
||||||
versions.add('latest')
|
versions.add('latest')
|
||||||
end
|
end
|
||||||
|
|
||||||
return versions.map! { |v| "#{container_repo}/bot:#{v}" }
|
return versions
|
||||||
|
end
|
||||||
|
|
||||||
|
# @param registry [String]
|
||||||
|
# @param git_repo [String]
|
||||||
|
# @param sub_image [String?]
|
||||||
|
# @return String
|
||||||
|
def get_image_name(registry: 'ghcr.io', git_repo: nil, sub_image: nil)
|
||||||
|
git_repo = git_repo.downcase
|
||||||
|
|
||||||
|
default_sub_image = File.basename git_repo
|
||||||
|
container_repo = "#{registry}/#{git_repo}/#{sub_image ? sub_image : default_sub_image}"
|
||||||
end
|
end
|
||||||
|
|
||||||
Semver = Struct.new('Semver', :major, :minor, :patch, :pre, :build)
|
Semver = Struct.new('Semver', :major, :minor, :patch, :pre, :build)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'set'
|
require 'set'
|
||||||
|
|
@ -7,9 +9,8 @@ require_relative '../lib'
|
||||||
class TestGetImageTags < Test::Unit::TestCase
|
class TestGetImageTags < Test::Unit::TestCase
|
||||||
def test_simple_branch
|
def test_simple_branch
|
||||||
assert_equal(
|
assert_equal(
|
||||||
Set['ghcr.io/virginity-bot/virginity-bot/bot:feat-foo-bar'],
|
Set['feat-foo-bar'],
|
||||||
get_image_tags(
|
get_image_tags(
|
||||||
git_repo: 'Virginity-Bot/virginity-bot',
|
|
||||||
git_ref_name: 'feat/foo-bar',
|
git_ref_name: 'feat/foo-bar',
|
||||||
git_ref_type: 'branch',
|
git_ref_type: 'branch',
|
||||||
git_default_branch: 'master',
|
git_default_branch: 'master',
|
||||||
|
|
@ -18,12 +19,8 @@ class TestGetImageTags < Test::Unit::TestCase
|
||||||
)
|
)
|
||||||
|
|
||||||
assert_equal(
|
assert_equal(
|
||||||
Set[
|
Set['latest', 'master'],
|
||||||
'ghcr.io/virginity-bot/virginity.bot/bot:latest',
|
|
||||||
'ghcr.io/virginity-bot/virginity.bot/bot:master'
|
|
||||||
],
|
|
||||||
get_image_tags(
|
get_image_tags(
|
||||||
git_repo: 'Virginity-Bot/virginity.bot',
|
|
||||||
git_ref_name: 'master',
|
git_ref_name: 'master',
|
||||||
git_ref_type: 'branch',
|
git_ref_type: 'branch',
|
||||||
git_default_branch: 'master',
|
git_default_branch: 'master',
|
||||||
|
|
@ -34,15 +31,8 @@ class TestGetImageTags < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_simple_tag
|
def test_simple_tag
|
||||||
assert_equal(
|
assert_equal(
|
||||||
Set[
|
Set['latest', 'master', '1.0.0', '1.0', '1'],
|
||||||
'ghcr.io/virginity-bot/virginity.bot/bot:latest',
|
|
||||||
'ghcr.io/virginity-bot/virginity.bot/bot:master',
|
|
||||||
'ghcr.io/virginity-bot/virginity.bot/bot:1.0.0',
|
|
||||||
'ghcr.io/virginity-bot/virginity.bot/bot:1.0',
|
|
||||||
'ghcr.io/virginity-bot/virginity.bot/bot:1'
|
|
||||||
],
|
|
||||||
get_image_tags(
|
get_image_tags(
|
||||||
git_repo: 'Virginity-Bot/virginity.bot',
|
|
||||||
git_ref_name: '1.0.0',
|
git_ref_name: '1.0.0',
|
||||||
git_ref_type: 'tag',
|
git_ref_type: 'tag',
|
||||||
git_default_branch: 'master',
|
git_default_branch: 'master',
|
||||||
|
|
@ -53,13 +43,8 @@ class TestGetImageTags < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_pre_tag
|
def test_pre_tag
|
||||||
assert_equal(
|
assert_equal(
|
||||||
Set[
|
Set['latest', 'master', '1.0.0-pre'],
|
||||||
'ghcr.io/virginity-bot/virginity.bot/bot:latest',
|
|
||||||
'ghcr.io/virginity-bot/virginity.bot/bot:master',
|
|
||||||
'ghcr.io/virginity-bot/virginity.bot/bot:1.0.0-pre'
|
|
||||||
],
|
|
||||||
get_image_tags(
|
get_image_tags(
|
||||||
git_repo: 'Virginity-Bot/virginity.bot',
|
|
||||||
git_ref_name: '1.0.0',
|
git_ref_name: '1.0.0',
|
||||||
git_ref_type: 'tag',
|
git_ref_type: 'tag',
|
||||||
git_default_branch: 'master',
|
git_default_branch: 'master',
|
||||||
|
|
@ -70,9 +55,8 @@ class TestGetImageTags < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_unsafe_branch_name
|
def test_unsafe_branch_name
|
||||||
assert_equal(
|
assert_equal(
|
||||||
Set['ghcr.io/virginity-bot/virginity.bot/bot:feat-foo-bar'],
|
Set['feat-foo-bar'],
|
||||||
get_image_tags(
|
get_image_tags(
|
||||||
git_repo: 'Virginity-Bot/virginity.bot',
|
|
||||||
git_ref_name: 'feat/Foo---bar',
|
git_ref_name: 'feat/Foo---bar',
|
||||||
git_ref_type: 'branch',
|
git_ref_type: 'branch',
|
||||||
git_default_branch: 'master',
|
git_default_branch: 'master',
|
||||||
|
|
@ -82,6 +66,33 @@ class TestGetImageTags < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class TestGetImageName < Test::Unit::TestCase
|
||||||
|
def test_basic
|
||||||
|
assert_equal(
|
||||||
|
'ghcr.io/octocat/hello-world/hello-world',
|
||||||
|
get_image_name(
|
||||||
|
git_repo: 'Octocat/hello-world',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
assert_equal(
|
||||||
|
'ghcr.io/octocat/hello-world/foobar',
|
||||||
|
get_image_name(
|
||||||
|
git_repo: 'Octocat/hello-world',
|
||||||
|
sub_image: 'foobar',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
assert_equal(
|
||||||
|
'docker.io/octocat/hello-world/hello-world',
|
||||||
|
get_image_name(
|
||||||
|
registry: 'docker.io',
|
||||||
|
git_repo: 'Octocat/hello-world',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class TestParseSemver < Test::Unit::TestCase
|
class TestParseSemver < Test::Unit::TestCase
|
||||||
def test_parse_basic
|
def test_parse_basic
|
||||||
parsed = parse_semver('1.2.3')
|
parsed = parse_semver('1.2.3')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue