Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds GIT_HASH_OR_TAG runtime value #99

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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