Skip to content

Commit

Permalink
feat: adds GIT_HASH_OR_TAG runtime value (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgilman authored Nov 26, 2024
1 parent bb76916 commit 3fe776b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 43 deletions.
8 changes: 2 additions & 6 deletions cli/pkg/release/providers/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
32 changes: 0 additions & 32 deletions cli/pkg/release/providers/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -39,7 +38,6 @@ func TestDockerReleaserRelease(t *testing.T) {
},
},
},
Tag: tag,
}
}

Expand All @@ -66,7 +64,6 @@ func TestDockerReleaserRelease(t *testing.T) {
"test",
[]string{"test.com"},
[]string{},
nil,
),
release: newRelease(),
config: DockerReleaserConfig{
Expand All @@ -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{
Expand Down Expand Up @@ -140,7 +112,6 @@ func TestDockerReleaserRelease(t *testing.T) {
"test",
[]string{"test.com"},
[]string{"linux", "windows"},
nil,
),
release: schema.Release{},
config: DockerReleaserConfig{},
Expand Down Expand Up @@ -170,7 +141,6 @@ func TestDockerReleaserRelease(t *testing.T) {
"test",
[]string{"test.com"},
[]string{},
nil,
),
release: newRelease(),
firing: true,
Expand All @@ -189,7 +159,6 @@ func TestDockerReleaserRelease(t *testing.T) {
"test",
[]string{"test.com"},
[]string{},
nil,
),
release: newRelease(),
firing: false,
Expand All @@ -206,7 +175,6 @@ func TestDockerReleaserRelease(t *testing.T) {
"test",
[]string{"test.com"},
[]string{},
nil,
),
release: newRelease(),
config: DockerReleaserConfig{
Expand Down
2 changes: 1 addition & 1 deletion foundry/api/blueprint.cue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ project: {
tag: {}
}
config: {
tag: _ @forge(name="GIT_COMMIT_HASH")
tag: _ @forge(name="GIT_HASH_OR_TAG")
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/project/project/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
7 changes: 3 additions & 4 deletions tools/argocd/blueprint.cue
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Expand Down

0 comments on commit 3fe776b

Please sign in to comment.