Gestion des versions

This commit is contained in:
admju 2024-09-12 13:17:36 +00:00
parent 5d4de618dd
commit dfa9fe3f1e
5 changed files with 11 additions and 9 deletions

View File

@ -24,7 +24,7 @@ func cobraInstallCmd() *cobra.Command {
Long: `deploy Charts`, Long: `deploy Charts`,
Args: cobra.MaximumNArgs(0), Args: cobra.MaximumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return InstallCmd(context, "v"+version, modules) return InstallCmd(context, version, modules)
}, },
Example: "oc-deploy install --version 0.1.0 --context ex1", Example: "oc-deploy install --version 0.1.0 --context ex1",
} }
@ -51,7 +51,7 @@ func cobraGenerateCmd() *cobra.Command{
Long: "Value", Long: "Value",
Args: cobra.MaximumNArgs(0), Args: cobra.MaximumNArgs(0),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return GenerateCmd(context, "v"+version) return GenerateCmd(context, version)
}, },
Example: "oc-deploy generate --version 0.1.0 --context ex1", Example: "oc-deploy generate --version 0.1.0 --context ex1",
} }

View File

@ -75,10 +75,6 @@ func (this *InstallClass) SetCommands() {
this.commandKubectl.New() this.commandKubectl.New()
} }
// func (this *InstallClass) SetCommandsMock(mock helm.HelmCommandInterface) {
// this.commandHelm = mock
// }
func (this *InstallClass) getToolBin(name string) (string, error) { func (this *InstallClass) getToolBin(name string) (string, error) {
for key, value := range this.toolsBin { for key, value := range this.toolsBin {
if key == name { if key == name {
@ -132,7 +128,7 @@ func (this *InstallClass) extractVersion() (string, error) {
} }
this.Version = version this.Version = version
} else { } else {
log.Log().Debug().Msg("Téléchargement du fichier de version") log.Log().Debug().Msg("Téléchargement du fichier de version "+ this.Version)
version, fileversion, err := versionOc.GetFromOnline(this.Version) version, fileversion, err := versionOc.GetFromOnline(this.Version)
if err != nil { if err != nil {
return "", err return "", err

View File

@ -36,6 +36,7 @@ func GetFromOnline(version string) (string, string, error) {
type releaseStruct struct { type releaseStruct struct {
Id int `json:"id"` Id int `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Message string `json:"message"`
} }
type ocJsonStruct struct { type ocJsonStruct struct {
@ -49,6 +50,7 @@ func readLatestFromOnline() (string, error) {
occonst.OCDEPLOY_ONLINE_URL, occonst.OCDEPLOY_ONLINE_URL,
occonst.OCDEPLOY_ONLINE_REPO) occonst.OCDEPLOY_ONLINE_REPO)
log.Log().Debug().Msg(url)
res, err := http.Get(url) res, err := http.Get(url)
if err != nil { if err != nil {
return "", err return "", err
@ -64,6 +66,10 @@ func readLatestFromOnline() (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
if len(data.Message) > 0 {
log.Log().Debug().Msg(data.Message)
return "", fmt.Errorf("Dernière version introuvable")
}
return data.Name, err return data.Name, err
} }

View File

@ -26,5 +26,5 @@ func GetFromFile(fileversion string) (string, error) {
return "", err return "", err
} }
return objmap.Version, nil return "v" + objmap.Version, nil
} }

View File

@ -14,7 +14,7 @@ func TestGetFromFile(t *testing.T) {
version, err := GetFromFile(ocyaml) version, err := GetFromFile(ocyaml)
assert.Nilf(t, err, "error message %s", ocyaml) assert.Nilf(t, err, "error message %s", ocyaml)
assert.Equal(t, "99.0", version, "TestGetFromFile error") assert.Equal(t, "v99.0", version, "TestGetFromFile error")
} }
func TestGetFromFileErr(t *testing.T) { func TestGetFromFileErr(t *testing.T) {