As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit cbde8976 authored by Igor Drozdov's avatar Igor Drozdov
Browse files

Merge branch 'ashmckenzie/add-version-support-to-all' into 'main'

parents 17beda32 a6072938
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -12,7 +12,16 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/logger"
)
var (
// Version is the current version of gitlab-shell
Version = "(unknown version)" // Set at build time in the Makefile
// BuildTime signifies the time the binary was build
BuildTime = "19700101.000000" // Set at build time in the Makefile
)
func main() {
command.CheckForVersionFlag(os.Args, Version, BuildTime)
readWriter := &readwriter.ReadWriter{
Out: os.Stdout,
In: os.Stdin,
Loading
Loading
Loading
Loading
@@ -13,7 +13,16 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/logger"
)
var (
// Version is the current version of gitlab-shell
Version = "(unknown version)" // Set at build time in the Makefile
// BuildTime signifies the time the binary was build
BuildTime = "19700101.000000" // Set at build time in the Makefile
)
func main() {
command.CheckForVersionFlag(os.Args, Version, BuildTime)
readWriter := &readwriter.ReadWriter{
Out: os.Stdout,
In: os.Stdin,
Loading
Loading
Loading
Loading
@@ -13,7 +13,16 @@ import (
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/logger"
)
var (
// Version is the current version of gitlab-shell
Version = "(unknown version)" // Set at build time in the Makefile
// BuildTime signifies the time the binary was build
BuildTime = "19700101.000000" // Set at build time in the Makefile
)
func main() {
command.CheckForVersionFlag(os.Args, Version, BuildTime)
readWriter := &readwriter.ReadWriter{
Out: os.Stdout,
In: os.Stdin,
Loading
Loading
Loading
Loading
@@ -29,12 +29,7 @@ var (
)
func main() {
// We can't use the flag library because gitlab-shell receives other arguments
// that confuse the parser.
if len(os.Args) == 2 && os.Args[1] == "-version" {
fmt.Printf("gitlab-shell %s-%s\n", Version, BuildTime)
os.Exit(0)
}
command.CheckForVersionFlag(os.Args, Version, BuildTime)
readWriter := &readwriter.ReadWriter{
Out: os.Stdout,
Loading
Loading
Loading
Loading
@@ -20,10 +20,10 @@ import (
var (
configDir = flag.String("config-dir", "", "The directory the config is in")
// BuildTime signifies the time the binary was build.
BuildTime = "2021-02-16T09:28:07+01:00" // Set at build time in the Makefile
// Version is the current version of GitLab Shell sshd.
// Version is the current version of gitlab-shell
Version = "(unknown version)" // Set at build time in the Makefile
// BuildTime signifies the time the binary was build
BuildTime = "19700101.000000" // Set at build time in the Makefile
)
func overrideConfigFromEnvironment(cfg *config.Config) {
Loading
Loading
@@ -39,11 +39,13 @@ func overrideConfigFromEnvironment(cfg *config.Config) {
if gitlabLogFormat := os.Getenv("GITLAB_LOG_FORMAT"); gitlabLogFormat != "" {
cfg.LogFormat = gitlabLogFormat
}
return
}
func main() {
command.CheckForVersionFlag(os.Args, Version, BuildTime)
flag.Parse()
cfg := new(config.Config)
if *configDir != "" {
var err error
Loading
Loading
@@ -52,6 +54,7 @@ func main() {
log.WithError(err).Fatal("failed to load configuration from specified directory")
}
}
overrideConfigFromEnvironment(cfg)
if err := cfg.IsSane(); err != nil {
if *configDir == "" {
Loading
Loading
Loading
Loading
@@ -2,6 +2,9 @@ package command
import (
"context"
"fmt"
"os"
"path"
"strings"
"gitlab.com/gitlab-org/gitlab-shell/v14/internal/config"
Loading
Loading
@@ -19,6 +22,17 @@ type LogMetadata struct {
RootNamespace string `json:"root_namespace,omitempty"`
}
func CheckForVersionFlag(osArgs []string, version, buildTime string) {
// We can't use the flag library because gitlab-shell receives other arguments
// that confuse the parser.
//
// See: https://gitlab.com/gitlab-org/gitlab-shell/-/merge_requests/800#note_1459474735
if len(osArgs) == 2 && osArgs[1] == "-version" {
fmt.Printf("%s %s-%s\n", path.Base(osArgs[0]), version, buildTime)
os.Exit(0)
}
}
// Setup() initializes tracing from the configuration file and generates a
// background context from which all other contexts in the process should derive
// from, as it has a service name and initial correlation ID set.
Loading
Loading
Loading
Loading
@@ -2,6 +2,7 @@ package command
import (
"os"
"os/exec"
"testing"
"github.com/stretchr/testify/require"
Loading
Loading
@@ -74,7 +75,6 @@ func addAdditionalEnv(envMap map[string]string) func() {
for _, k := range unsetValues {
os.Unsetenv(k)
}
}
}
Loading
Loading
@@ -114,3 +114,17 @@ func TestNewLogMetadata(t *testing.T) {
})
}
}
func TestCheckForVersionFlag(t *testing.T) {
if os.Getenv("GITLAB_SHELL_TEST_CHECK_FOR_VERSION_FLAG") == "1" {
CheckForVersionFlag([]string{"test", "-version"}, "1.2.3", "456")
return
}
cmd := exec.Command(os.Args[0], "-test.run=TestCheckForVersionFlag")
cmd.Env = append(os.Environ(), "GITLAB_SHELL_TEST_CHECK_FOR_VERSION_FLAG=1")
out, err := cmd.Output()
require.Nil(t, err)
require.Equal(t, "test 1.2.3-456\n", string(out))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment