diff --git a/cli/pkg/release/providers/docker.go b/cli/pkg/release/providers/docker.go index 56cee50..280bff2 100644 --- a/cli/pkg/release/providers/docker.go +++ b/cli/pkg/release/providers/docker.go @@ -59,12 +59,8 @@ func (r *DockerReleaser) Release() error { container := r.project.Blueprint.Project.Container registries := r.project.Blueprint.Global.CI.Registries - var imageTag string - if r.project.Tag != nil { - imageTag = r.project.Tag.Version - } else if r.config.Tag != "" { - imageTag = r.config.Tag - } else { + imageTag := r.config.Tag + if imageTag == "" { return fmt.Errorf("no image tag specified") } diff --git a/cli/pkg/release/providers/docker_test.go b/cli/pkg/release/providers/docker_test.go index 2d025e3..f2ec377 100644 --- a/cli/pkg/release/providers/docker_test.go +++ b/cli/pkg/release/providers/docker_test.go @@ -19,7 +19,6 @@ func TestDockerReleaserRelease(t *testing.T) { container string, registries []string, platforms []string, - tag *project.ProjectTag, ) project.Project { return project.Project{ Blueprint: schema.Blueprint{ @@ -39,7 +38,6 @@ func TestDockerReleaserRelease(t *testing.T) { }, }, }, - Tag: tag, } } @@ -66,7 +64,6 @@ func TestDockerReleaserRelease(t *testing.T) { "test", []string{"test.com"}, []string{}, - nil, ), release: newRelease(), config: DockerReleaserConfig{ @@ -82,37 +79,12 @@ func TestDockerReleaserRelease(t *testing.T) { assert.Contains(t, calls, "push test.com/test:test") }, }, - { - name: "with git tag", - project: newProject( - "test", - []string{"test.com"}, - []string{}, - &project.ProjectTag{ - Version: "v1.0.0", - }, - ), - release: newRelease(), - config: DockerReleaserConfig{ - Tag: "test", - }, - firing: true, - force: false, - runFail: false, - validate: func(t *testing.T, calls []string, err error) { - require.NoError(t, err) - assert.Contains(t, calls, fmt.Sprintf("inspect %s:%s", CONTAINER_NAME, TAG_NAME)) - assert.Contains(t, calls, fmt.Sprintf("tag %s:%s test.com/test:v1.0.0", CONTAINER_NAME, TAG_NAME)) - assert.Contains(t, calls, "push test.com/test:v1.0.0") - }, - }, { name: "multiple platforms", project: newProject( "test", []string{"test.com"}, []string{"linux", "windows"}, - nil, ), release: newRelease(), config: DockerReleaserConfig{ @@ -140,7 +112,6 @@ func TestDockerReleaserRelease(t *testing.T) { "test", []string{"test.com"}, []string{"linux", "windows"}, - nil, ), release: schema.Release{}, config: DockerReleaserConfig{}, @@ -170,7 +141,6 @@ func TestDockerReleaserRelease(t *testing.T) { "test", []string{"test.com"}, []string{}, - nil, ), release: newRelease(), firing: true, @@ -189,7 +159,6 @@ func TestDockerReleaserRelease(t *testing.T) { "test", []string{"test.com"}, []string{}, - nil, ), release: newRelease(), firing: false, @@ -206,7 +175,6 @@ func TestDockerReleaserRelease(t *testing.T) { "test", []string{"test.com"}, []string{}, - nil, ), release: newRelease(), config: DockerReleaserConfig{ diff --git a/foundry/api/blueprint.cue b/foundry/api/blueprint.cue index 00c6a9c..470ecc8 100644 --- a/foundry/api/blueprint.cue +++ b/foundry/api/blueprint.cue @@ -33,7 +33,7 @@ project: { tag: {} } config: { - tag: _ @forge(name="GIT_COMMIT_HASH") + tag: _ @forge(name="GIT_HASH_OR_TAG") } } } diff --git a/lib/project/project/runtime.go b/lib/project/project/runtime.go index 727de70..5af1c3e 100644 --- a/lib/project/project/runtime.go +++ b/lib/project/project/runtime.go @@ -30,11 +30,13 @@ func (g *GitRuntime) Load(project *Project) map[string]cue.Value { g.logger.Warn("Failed to get commit hash", "error", err) } else { data["GIT_COMMIT_HASH"] = project.ctx.CompileString(fmt.Sprintf(`"%s"`, hash)) + data["GIT_HASH_OR_TAG"] = project.ctx.CompileString(fmt.Sprintf(`"%s"`, hash)) } if project.Tag != nil { data["GIT_TAG"] = project.ctx.CompileString(fmt.Sprintf(`"%s"`, project.Tag.Full)) data["GIT_TAG_VERSION"] = project.ctx.CompileString(fmt.Sprintf(`"%s"`, project.Tag.Version)) + data["GIT_HASH_OR_TAG"] = project.ctx.CompileString(fmt.Sprintf(`"%s"`, project.Tag.Version)) } else { g.logger.Debug("No project tag found") } diff --git a/tools/argocd/blueprint.cue b/tools/argocd/blueprint.cue index 74e8bf7..1988ee7 100644 --- a/tools/argocd/blueprint.cue +++ b/tools/argocd/blueprint.cue @@ -4,12 +4,11 @@ project: { release: { docker: { on: { - //merge: {} - //tag: {} - always: {} + merge: {} + tag: {} } config: { - tag: _ @forge(name="GIT_COMMIT_HASH") + tag: _ @forge(name="GIT_HASH_OR_TAG") } } }