Skip to content

Commit 439c5de

Browse files
authored
fix: init version flag (#4595)
## Changes <!-- Brief summary of your changes that is easy to understand --> ## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> ## Tests <!-- How have you tested the changes? --> <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. --> --------- Co-authored-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
1 parent 848fe0c commit 439c5de

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

cmd/apps/init.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,32 @@ import (
2828
)
2929

3030
const (
31-
templatePathEnvVar = "DATABRICKS_APPKIT_TEMPLATE_PATH"
32-
appkitRepoURL = "https://github.com/databricks/appkit"
33-
appkitTemplateDir = "template"
34-
appkitDefaultBranch = "main"
35-
defaultProfile = "DEFAULT"
31+
templatePathEnvVar = "DATABRICKS_APPKIT_TEMPLATE_PATH"
32+
appkitRepoURL = "https://github.com/databricks/appkit"
33+
appkitTemplateDir = "template"
34+
appkitDefaultBranch = "main"
35+
appkitTemplateTagPfx = "template-v"
36+
defaultProfile = "DEFAULT"
3637
)
3738

38-
// normalizeVersion ensures the version string has a "v" prefix if it looks like a semver.
39-
// Examples: "0.3.0" -> "v0.3.0", "v0.3.0" -> "v0.3.0", "latest" -> "main"
39+
// normalizeVersion converts a version string to the template tag format "template-vX.X.X".
40+
// Examples: "0.3.0" -> "template-v0.3.0", "v0.3.0" -> "template-v0.3.0",
41+
// "template-v0.3.0" -> "template-v0.3.0", "latest" -> "main"
4042
func normalizeVersion(version string) string {
4143
if version == "" {
4244
return version
4345
}
4446
if version == "latest" {
4547
return appkitDefaultBranch
4648
}
47-
// If it starts with a digit, prepend "v"
48-
if len(version) > 0 && version[0] >= '0' && version[0] <= '9' {
49-
return "v" + version
49+
if strings.HasPrefix(version, appkitTemplateTagPfx) {
50+
return version
51+
}
52+
if strings.HasPrefix(version, "v") {
53+
return appkitTemplateTagPfx + version[1:]
54+
}
55+
if version[0] >= '0' && version[0] <= '9' {
56+
return appkitTemplateTagPfx + version
5057
}
5158
return version
5259
}

cmd/apps/init_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,11 @@ func TestNormalizeVersion(t *testing.T) {
202202
input string
203203
expected string
204204
}{
205-
{"0.3.0", "v0.3.0"},
206-
{"1.0.0", "v1.0.0"},
207-
{"v0.3.0", "v0.3.0"},
208-
{"v1.0.0", "v1.0.0"},
205+
{"0.3.0", "template-v0.3.0"},
206+
{"1.0.0", "template-v1.0.0"},
207+
{"v0.3.0", "template-v0.3.0"},
208+
{"v1.0.0", "template-v1.0.0"},
209+
{"template-v0.3.0", "template-v0.3.0"},
209210
{"latest", "main"},
210211
{"", ""},
211212
{"main", "main"},

0 commit comments

Comments
 (0)