Display Git commit ID in output of odo commands where the version is shown (#7074)

* Display Git commit ID in output of odo commands where the version is displayed

This covers:
- odo init
- odo dev
- odo deploy

Displaying the commit ID (same as in `odo version`) will help quickly pinpoint the exact commit without having to run `odo version`.

See #6131 for more context

* Append the state of the working tree next to the Git commit ID

`git describe` is much more helpful to quickly understand the state of the working tree.

For backward compatibility, we are defaulting to `git rev-parse`,
just in case `git describe` does not work correctly.

* Fix integration tests

* Fix doc automation tests

Strip the Git commit ID from the full odo version string
prior to comparing the outputs.
We still want to compare the tag displayed.
This commit is contained in:
Armel Soro
2023-09-06 20:36:13 +02:00
committed by GitHub
parent adc96994d9
commit 725a64014a
13 changed files with 88 additions and 39 deletions

View File

@@ -36,6 +36,7 @@ import (
"golang.org/x/term"
"github.com/redhat-developer/odo/pkg/log/fidget"
"github.com/redhat-developer/odo/pkg/version"
)
// Spacing for logging
@@ -339,28 +340,41 @@ More details on https://odo.dev/docs/user-guides/advanced/experimental-mode
}
}
// Title Prints the logo as well as the first line being BLUE (indicator of the command information)
// the second and third lines are optional and provide information with regards to what is being ran
// Title Prints the logo as well as the first line being BLUE (indicator of the command information);
// the second line is optional and provides information in regard to what is being run.
// The last line displays information about the current odo version.
//
// __
// / \__ **First line**
// \__/ \ Second line
// / \__/ Third line
// \__/
func Title(firstLine, secondLine, thirdLine string) {
// __
// / \__ **First line**
// \__/ \ Second line
// / \__/ odo version: <VERSION>
// \__/
func Title(firstLine, secondLine string) {
if !IsJSON() {
fmt.Fprint(GetStdout(), Stitle(firstLine, secondLine, thirdLine))
fmt.Fprint(GetStdout(), Stitle(firstLine, secondLine))
}
}
// Stitle is the same as Title but returns the string instead
func Stitle(firstLine, secondLine, thirdLine string) string {
func Stitle(firstLine, secondLine string) string {
var versionMsg string
if version.VERSION != "" {
versionMsg = "odo version: " + version.VERSION
}
if version.GITCOMMIT != "" {
versionMsg += " (" + version.GITCOMMIT + ")"
}
return StitleWithVersion(firstLine, secondLine, versionMsg)
}
// StitleWithVersion is the same as Stitle, but it allows to customize the version message line
func StitleWithVersion(firstLine, secondLine, versionLine string) string {
blue := color.New(color.FgBlue).SprintFunc()
return fmt.Sprintf(` __
/ \__ %s
\__/ \ %s
/ \__/ %s
\__/%s`, blue(firstLine), secondLine, thirdLine, "\n")
\__/%s`, blue(firstLine), secondLine, versionLine, "\n")
}
// Sectionf outputs a title in BLUE and underlined for separating a section (such as building a container, deploying files, etc.)

View File

@@ -8,6 +8,9 @@ import (
"github.com/redhat-developer/odo/pkg/kclient"
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/templates"
"github.com/redhat-developer/odo/pkg/component"
"github.com/redhat-developer/odo/pkg/log"
"github.com/redhat-developer/odo/pkg/odo/cli/messages"
@@ -19,10 +22,6 @@ import (
"github.com/redhat-developer/odo/pkg/odo/util"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
scontext "github.com/redhat-developer/odo/pkg/segment/context"
"github.com/redhat-developer/odo/pkg/version"
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/templates"
)
// RecommendedCommandName is the recommended command name
@@ -87,9 +86,8 @@ func (o *DeployOptions) Run(ctx context.Context) error {
scontext.SetProjectType(ctx, devfileObj.Data.GetMetadata().ProjectType)
scontext.SetDevfileName(ctx, devfileName)
// Output what the command is doing / information
log.Title("Running the application in Deploy mode using "+devfileName+" Devfile",
"Namespace: "+namespace,
"odo version: "+version.VERSION)
log.Title("Running the application in Deploy mode using the \""+devfileName+"\" Devfile",
"Namespace: "+namespace)
genericclioptions.WarnIfDefaultNamespace(namespace, o.clientset.KubernetesClient)

View File

@@ -38,7 +38,6 @@ import (
scontext "github.com/redhat-developer/odo/pkg/segment/context"
"github.com/redhat-developer/odo/pkg/state"
"github.com/redhat-developer/odo/pkg/util"
"github.com/redhat-developer/odo/pkg/version"
)
// RecommendedCommandName is the recommended command name
@@ -219,9 +218,7 @@ func (o *DevOptions) Run(ctx context.Context) (err error) {
}
// Output what the command is doing / information
log.Title("Developing using the \""+componentName+"\" Devfile",
dest,
"odo version: "+version.VERSION)
log.Title("Developing using the \""+componentName+"\" Devfile", dest)
if platform == commonflags.PlatformCluster {
genericclioptions.WarnIfDefaultNamespace(odocontext.GetNamespace(ctx), o.clientset.KubernetesClient)
}

View File

@@ -12,6 +12,8 @@ import (
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/v2/pkg/devfile/parser"
"k8s.io/kubectl/pkg/util/templates"
"github.com/redhat-developer/odo/pkg/api"
"github.com/redhat-developer/odo/pkg/component"
"github.com/redhat-developer/odo/pkg/devfile"
@@ -30,9 +32,6 @@ import (
"github.com/redhat-developer/odo/pkg/odo/util"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
scontext "github.com/redhat-developer/odo/pkg/segment/context"
"github.com/redhat-developer/odo/pkg/version"
"k8s.io/kubectl/pkg/util/templates"
)
// RecommendedCommandName is the recommended command name
@@ -212,7 +211,7 @@ func (o *InitOptions) run(ctx context.Context) (devfileObj parser.DevfileObj, pa
} else if len(o.flags) == 0 {
infoOutput = messages.SourceCodeDetected
}
log.Title(messages.InitializingNewComponent, infoOutput, "odo version: "+version.VERSION)
log.Title(messages.InitializingNewComponent, infoOutput)
log.Println()
if len(o.flags) == 0 {
log.Info(messages.InteractiveModeEnabled)

View File

@@ -14,7 +14,6 @@ import (
"github.com/redhat-developer/odo/pkg/odo/cmdline"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
scontext "github.com/redhat-developer/odo/pkg/segment/context"
"github.com/redhat-developer/odo/pkg/version"
)
// runPreInit executes the Init command before running the main command
@@ -33,7 +32,7 @@ func runPreInit(ctx context.Context, workingDir string, deps *clientset.Clientse
func(interactiveMode bool) {
scontext.SetInteractive(cmdline.Context(), interactiveMode)
if interactiveMode {
log.Title(msg, messages.SourceCodeDetected, "odo version: "+version.VERSION)
log.Title(msg, messages.SourceCodeDetected)
log.Info("\n" + messages.InteractiveModeEnabled)
}
},