🐛 clean up image name
This commit is contained in:
parent
98e188a32f
commit
26ae5311d9
|
|
@ -29,7 +29,8 @@ jobs:
|
|||
run: |
|
||||
echo "image_tags=$(
|
||||
.github/workflows/scripts/get-image-tags.rb \
|
||||
"${{ github.repository }}" \
|
||||
"${{ github.repository_owner }}" \
|
||||
"${{ github.event.repository.name }}" \
|
||||
"${{ github.ref_name }}" \
|
||||
"${{ github.ref_type }}" \
|
||||
"${{ github.event.repository.default_branch }}" \
|
||||
|
|
|
|||
|
|
@ -4,15 +4,16 @@ require 'json'
|
|||
require_relative 'lib'
|
||||
|
||||
def main
|
||||
git_repo = ARGV[0]
|
||||
git_ref_name = ARGV[1]
|
||||
git_ref_type = ARGV[2]
|
||||
git_default_branch = ARGV[3]
|
||||
repo_owner = ARGV[0]
|
||||
repo_name = ARGV[1]
|
||||
git_ref_name = ARGV[2]
|
||||
git_ref_type = ARGV[3]
|
||||
git_default_branch = ARGV[4]
|
||||
|
||||
# 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 "'#{repo_owner}', '#{repo_name}', '#{git_ref_name}', '#{git_ref_type}', '#{git_default_branch}'"
|
||||
|
||||
image_name = get_image_name(git_repo: git_repo)
|
||||
image_name = get_image_name(username: repo_owner, project_name: repo_name)
|
||||
|
||||
tags =
|
||||
get_image_tags(
|
||||
|
|
|
|||
|
|
@ -40,14 +40,24 @@ def get_image_tags(
|
|||
end
|
||||
|
||||
# @param registry [String]
|
||||
# @param git_repo [String]
|
||||
# @param username [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
|
||||
def get_image_name(
|
||||
registry: 'ghcr.io',
|
||||
username: nil,
|
||||
project_name: nil,
|
||||
sub_image: nil
|
||||
)
|
||||
username = username.downcase
|
||||
project_name = project_name.downcase.gsub(/^docker-/, '')
|
||||
|
||||
default_sub_image = File.basename git_repo
|
||||
container_repo = "#{registry}/#{git_repo}/#{sub_image ? sub_image : default_sub_image}"
|
||||
case registry
|
||||
when 'ghcr.io'
|
||||
container_repo = "#{registry}/#{username}/#{project_name}/#{sub_image ? sub_image : project_name}"
|
||||
when 'docker.io'
|
||||
container_repo = "#{registry}/#{username}/#{project_name}#{sub_image ? "-#{sub_image}" : ''}"
|
||||
end
|
||||
end
|
||||
|
||||
Semver = Struct.new('Semver', :major, :minor, :patch, :pre, :build)
|
||||
|
|
|
|||
|
|
@ -71,23 +71,53 @@ class TestGetImageName < Test::Unit::TestCase
|
|||
assert_equal(
|
||||
'ghcr.io/octocat/hello-world/hello-world',
|
||||
get_image_name(
|
||||
git_repo: 'Octocat/hello-world',
|
||||
username: 'Octocat',
|
||||
project_name: 'hello-world',
|
||||
),
|
||||
)
|
||||
|
||||
assert_equal(
|
||||
'ghcr.io/octocat/hello-world/hello-world',
|
||||
get_image_name(
|
||||
username: 'Octocat',
|
||||
project_name: 'docker-hello-world',
|
||||
),
|
||||
)
|
||||
|
||||
assert_equal(
|
||||
'ghcr.io/octocat/hello-world/foobar',
|
||||
get_image_name(
|
||||
git_repo: 'Octocat/hello-world',
|
||||
username: 'Octocat',
|
||||
project_name: 'hello-world',
|
||||
sub_image: 'foobar',
|
||||
),
|
||||
)
|
||||
|
||||
assert_equal(
|
||||
'docker.io/octocat/hello-world/hello-world',
|
||||
'ghcr.io/octocat/hello-world/foo',
|
||||
get_image_name(
|
||||
username: 'Octocat',
|
||||
project_name: 'hello-world',
|
||||
sub_image: 'foo'
|
||||
),
|
||||
)
|
||||
|
||||
assert_equal(
|
||||
'docker.io/octocat/hello-world',
|
||||
get_image_name(
|
||||
registry: 'docker.io',
|
||||
git_repo: 'Octocat/hello-world',
|
||||
username: 'Octocat',
|
||||
project_name: 'hello-world',
|
||||
),
|
||||
)
|
||||
|
||||
assert_equal(
|
||||
'docker.io/octocat/hello-world-foo',
|
||||
get_image_name(
|
||||
registry: 'docker.io',
|
||||
username: 'Octocat',
|
||||
project_name: 'hello-world',
|
||||
sub_image: 'foo'
|
||||
),
|
||||
)
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue