Skip to content

Commit d55dfd3

Browse files
authored
refactor: allows setting global tags (#144)
1 parent cdea920 commit d55dfd3

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

lib/project/project/loader.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,22 @@ func (p *DefaultProjectLoader) Load(projectPath string) (Project, error) {
118118
if err != nil {
119119
p.logger.Warn("Failed to get git tag", "error", err)
120120
} else if gitTag != "" {
121-
t, err := ParseProjectTag(string(gitTag))
122-
if err != nil {
123-
p.logger.Warn("Failed to parse project tag", "error", err)
124-
} else if t.Project == name {
125-
tag = &t
121+
if !IsProjectTag(gitTag) {
122+
p.logger.Debug("Git tag is not a project tag", "tag", gitTag)
123+
tag = &ProjectTag{
124+
Full: gitTag,
125+
Project: name,
126+
Version: gitTag,
127+
}
126128
} else {
127-
p.logger.Debug("Git tag does not match project name", "tag", gitTag, "project", name)
129+
t, err := ParseProjectTag(gitTag)
130+
if err != nil {
131+
p.logger.Warn("Failed to parse project tag", "error", err)
132+
} else if t.Project == name {
133+
tag = &t
134+
} else {
135+
p.logger.Debug("Git tag does not match project name", "tag", gitTag, "project", name)
136+
}
128137
}
129138
} else {
130139
p.logger.Debug("No git tag found")

lib/project/project/loader_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@ project: name: "foo"
7474
assert.Equal(t, "v1.0.0", string(p.Tag.Version))
7575
},
7676
},
77+
{
78+
name: "non-project tag",
79+
fs: afero.NewMemMapFs(),
80+
projectPath: "/project",
81+
files: map[string]string{
82+
"/project/Earthfile": earthfile,
83+
"/project/blueprint.cue": bp,
84+
},
85+
tag: "v1.0.0",
86+
injectors: []injector.BlueprintInjector{},
87+
runtimes: func(fs afero.Fs) []RuntimeData { return nil },
88+
env: map[string]string{},
89+
initGit: true,
90+
validate: func(t *testing.T, p Project, err error) {
91+
assert.Equal(t, "v1.0.0", p.Tag.Full)
92+
assert.Equal(t, "foo", p.Tag.Project)
93+
assert.Equal(t, "v1.0.0", string(p.Tag.Version))
94+
},
95+
},
7796
{
7897
name: "with injectors",
7998
fs: afero.NewMemMapFs(),

lib/project/project/tag.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ type ProjectTag struct {
2121
Version string
2222
}
2323

24+
// IsProjectTag checks if a git tag is a project tag.
25+
func IsProjectTag(tag string) bool {
26+
_, err := ParseProjectTag(tag)
27+
return err == nil
28+
}
29+
2430
// ParseProjectTag parses a project tag from a git tag.
2531
func ParseProjectTag(tag string) (ProjectTag, error) {
2632
parts := strings.Split(tag, "/")

0 commit comments

Comments
 (0)