This commit is contained in:
zjhe 2022-04-07 16:37:28 +08:00
Родитель 3b121ffff8
Коммит 056e4ee707
2 изменённых файлов: 10 добавлений и 8 удалений

Просмотреть файл

@ -135,14 +135,14 @@ func sameMajorVersion(majorVersion int) func(i interface{}) bool {
}
}
func GetCurrentMajorVersionFromEnv() string {
func GetCurrentMajorVersionFromEnv() (int, error) {
currentMajorVer := os.Getenv("PREVIOUS_MAJOR_VERSION")
if currentMajorVer == "" {
return "v0"
return 0, nil
}
previousMajorVer, err := strconv.Atoi(strings.TrimPrefix(currentMajorVer, "v"))
if err != nil {
return ""
return 0, err
}
return fmt.Sprintf("v%d", previousMajorVer+1)
return previousMajorVer + 1, nil
}

Просмотреть файл

@ -43,12 +43,14 @@ func TestSkipIfNoTagsWithinMajorVersion(t *testing.T) {
}
func TestGetCurrentMajorVersionFromEnv_default(t *testing.T) {
majorVersionFromEnv := GetCurrentMajorVersionFromEnv()
assert.Equal(t, "v0", majorVersionFromEnv)
majorVersionFromEnv, err := GetCurrentMajorVersionFromEnv()
assert.Nil(t, err)
assert.Equal(t, 0, majorVersionFromEnv)
}
func TestGetCurrentMajorVersionFromEnv_basic(t *testing.T) {
os.Setenv("PREVIOUS_MAJOR_VERSION", "v0")
majorVersionFromEnv := GetCurrentMajorVersionFromEnv()
assert.Equal(t, "v1", majorVersionFromEnv)
majorVersionFromEnv, err := GetCurrentMajorVersionFromEnv()
assert.Nil(t, err)
assert.Equal(t, 1, majorVersionFromEnv)
}