From 95e854a63939335a241e3a175b94fa43aa9ff569 Mon Sep 17 00:00:00 2001 From: novahow Date: Mon, 10 Jun 2024 22:54:36 +0800 Subject: [PATCH 1/6] reimplement functions in go-mouff-update, use ghreposervice Signed-off-by: novahow --- flytectl/cmd/upgrade/upgrade.go | 7 +- flytectl/pkg/github/githubutil.go | 3 +- flytectl/pkg/github/provider.go | 170 ++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+), 5 deletions(-) create mode 100644 flytectl/pkg/github/provider.go diff --git a/flytectl/cmd/upgrade/upgrade.go b/flytectl/cmd/upgrade/upgrade.go index 5d91848720..deb88db5b8 100644 --- a/flytectl/cmd/upgrade/upgrade.go +++ b/flytectl/cmd/upgrade/upgrade.go @@ -114,19 +114,20 @@ func upgrade(u *updater.Updater) (string, error) { } func isUpgradeSupported(goos platformutil.Platform) (bool, error) { - latest, err := github.FlytectlReleaseConfig.GetLatestVersion() + latest, err := github.FlytectlReleaseConfig.Provider.GetLatestVersion() if err != nil { return false, err } - if isGreater, err := util.IsVersionGreaterThan(latest, stdlibversion.Version); err != nil { + compatible_version := strings.TrimPrefix(latest, fmt.Sprintf("%s/", github.FlytectlReleaseConfig.ExecutableName)) + if isGreater, err := util.IsVersionGreaterThan(compatible_version, stdlibversion.Version); err != nil { return false, err } else if !isGreater { fmt.Println("You already have the latest version of Flytectl") return false, nil } - message, err := github.GetUpgradeMessage(latest, goos) + message, err := github.GetUpgradeMessage(compatible_version, goos) if err != nil { return false, err } diff --git a/flytectl/pkg/github/githubutil.go b/flytectl/pkg/github/githubutil.go index e439df44f8..845f7f75b6 100644 --- a/flytectl/pkg/github/githubutil.go +++ b/flytectl/pkg/github/githubutil.go @@ -15,7 +15,6 @@ import ( stdlibversion "github.com/flyteorg/flyte/flytestdlib/version" "github.com/google/go-github/v42/github" - "github.com/mouuff/go-rocket-update/pkg/provider" "github.com/mouuff/go-rocket-update/pkg/updater" "golang.org/x/oauth2" "golang.org/x/text/cases" @@ -40,7 +39,7 @@ var Client GHRepoService // FlytectlReleaseConfig represent the updater config for flytectl binary var FlytectlReleaseConfig = &updater.Updater{ - Provider: &provider.Github{ + Provider: &GitHubProvider{ RepositoryURL: flytectlRepository, ArchiveName: getFlytectlAssetName(), }, diff --git a/flytectl/pkg/github/provider.go b/flytectl/pkg/github/provider.go new file mode 100644 index 0000000000..0e37cee284 --- /dev/null +++ b/flytectl/pkg/github/provider.go @@ -0,0 +1,170 @@ +package github + +import ( + "context" + "errors" + "fmt" + "io" + "net/http" + "os" + "path/filepath" + "regexp" + "strings" + + go_github "github.com/google/go-github/v42/github" + "github.com/mouuff/go-rocket-update/pkg/provider" +) + +// type GitHubProvider struct { +// provider.Github +// } + +// Github provider finds a archive file in the repository's releases to provide files +type GitHubProvider struct { + RepositoryURL string // Repository URL, example github.com/mouuff/go-rocket-update + ArchiveName string // Archive name (the zip/tar.gz you upload for a release on github), example: binaries.zip + + tmpDir string // temporary directory this is used internally + decompressProvider provider.Provider // provider used to decompress the downloaded archive + archivePath string // path to the downloaded archive (should be in tmpDir) +} + +// githubTag struct used to unmarshal response from github +// https://api.github.com/repos/ownerName/projectName/tags +type githubTag struct { + Name string `json:"name"` +} + +// githubRepositoryInfo is used to get the name of the project and the owner name +// from this fields we are able to get other links (such as the release and tags link) +type githubRepositoryInfo struct { + RepositoryOwner string + RepositoryName string +} + +// getRepositoryInfo parses the github repository URL +func (c *GitHubProvider) repositoryInfo() (*githubRepositoryInfo, error) { + re := regexp.MustCompile(`github\.com/(.*?)/(.*?)$`) + submatches := re.FindAllStringSubmatch(c.RepositoryURL, 1) + if len(submatches) < 1 { + return nil, errors.New("Invalid github URL:" + c.RepositoryURL) + } + return &githubRepositoryInfo{ + RepositoryOwner: submatches[0][1], + RepositoryName: submatches[0][2], + }, nil +} + +// getArchiveURL get the archive URL for the github repository +// If no tag is provided then the latest version is selected +func (c *GitHubProvider) getArchiveURL(tag string) (string, error) { + if len(tag) == 0 { + // Get latest version if no tag is provided + var err error + tag, err = c.GetLatestVersion() + if err != nil { + return "", err + } + } + + info, err := c.repositoryInfo() + if err != nil { + return "", err + } + return fmt.Sprintf("https://github.com/%s/%s/releases/download/%s/%s", + info.RepositoryOwner, + info.RepositoryName, + tag, + c.ArchiveName, + ), nil +} + +// Open opens the provider +func (c *GitHubProvider) Open() (err error) { + archiveURL, err := c.getArchiveURL("") // get archive url for latest version + if err != nil { + return + } + resp, err := http.Get(archiveURL) + if err != nil { + return + } + defer resp.Body.Close() + + c.tmpDir, err = os.MkdirTemp("", "rocket-update") + if err != nil { + return + } + + c.archivePath = filepath.Join(c.tmpDir, c.ArchiveName) + archiveFile, err := os.Create(c.archivePath) + if err != nil { + return + } + _, err = io.Copy(archiveFile, resp.Body) + archiveFile.Close() + if err != nil { + return + } + c.decompressProvider, err = provider.Decompress(c.archivePath) + if err != nil { + return nil + } + return c.decompressProvider.Open() +} + +// Close closes the provider +func (c *GitHubProvider) Close() error { + if c.decompressProvider != nil { + c.decompressProvider.Close() + c.decompressProvider = nil + } + + if len(c.tmpDir) > 0 { + os.RemoveAll(c.tmpDir) + c.tmpDir = "" + c.archivePath = "" + } + return nil +} + +// GetLatestVersion gets the latest version +func (c *GitHubProvider) GetLatestVersion() (string, error) { + tags, err := c.getReleases() + if err != nil { + return "", err + } + latest_tag := tags[0].GetTagName() + return latest_tag, err +} + +func (c *GitHubProvider) getReleases() ([]*go_github.RepositoryRelease, error) { + g := GetGHRepoService() + releases, _, err := g.ListReleases(context.Background(), owner, flyte, &go_github.ListOptions{ + PerPage: 100, + }) + if err != nil { + return nil, err + } + var filteredReleases []*go_github.RepositoryRelease + for _, release := range releases { + if strings.HasPrefix(release.GetTagName(), flytectl) { + filteredReleases = append(filteredReleases, release) + } + } + return filteredReleases, err +} + +// Walk walks all the files provided +func (c *GitHubProvider) Walk(walkFn provider.WalkFunc) error { + if c.decompressProvider == nil { + // TODO specify error + return provider.ErrNotOpenned + } + return c.decompressProvider.Walk(walkFn) +} + +// Retrieve file relative to "provider" to destination +func (c *GitHubProvider) Retrieve(src string, dest string) error { + return c.decompressProvider.Retrieve(src, dest) +} From 1a2b92f7278980880b7c05bfc22420191ba400e1 Mon Sep 17 00:00:00 2001 From: novahow Date: Wed, 19 Jun 2024 17:49:22 +0800 Subject: [PATCH 2/6] add tests Signed-off-by: novahow --- flytectl/cmd/upgrade/upgrade.go | 6 +-- flytectl/pkg/github/githubutil.go | 3 +- flytectl/pkg/github/provider.go | 53 ++++++++++------------ flytectl/pkg/github/provider_test.go | 66 ++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 33 deletions(-) create mode 100644 flytectl/pkg/github/provider_test.go diff --git a/flytectl/cmd/upgrade/upgrade.go b/flytectl/cmd/upgrade/upgrade.go index deb88db5b8..9991f934e4 100644 --- a/flytectl/cmd/upgrade/upgrade.go +++ b/flytectl/cmd/upgrade/upgrade.go @@ -119,15 +119,15 @@ func isUpgradeSupported(goos platformutil.Platform) (bool, error) { return false, err } - compatible_version := strings.TrimPrefix(latest, fmt.Sprintf("%s/", github.FlytectlReleaseConfig.ExecutableName)) - if isGreater, err := util.IsVersionGreaterThan(compatible_version, stdlibversion.Version); err != nil { + compatibleVersion := strings.TrimPrefix(latest, fmt.Sprintf("%s/", github.FlytectlReleaseConfig.ExecutableName)) + if isGreater, err := util.IsVersionGreaterThan(compatibleVersion, stdlibversion.Version); err != nil { return false, err } else if !isGreater { fmt.Println("You already have the latest version of Flytectl") return false, nil } - message, err := github.GetUpgradeMessage(compatible_version, goos) + message, err := github.GetUpgradeMessage(compatibleVersion, goos) if err != nil { return false, err } diff --git a/flytectl/pkg/github/githubutil.go b/flytectl/pkg/github/githubutil.go index 845f7f75b6..babfaeace5 100644 --- a/flytectl/pkg/github/githubutil.go +++ b/flytectl/pkg/github/githubutil.go @@ -39,9 +39,10 @@ var Client GHRepoService // FlytectlReleaseConfig represent the updater config for flytectl binary var FlytectlReleaseConfig = &updater.Updater{ - Provider: &GitHubProvider{ + Provider: &GHProvider{ RepositoryURL: flytectlRepository, ArchiveName: getFlytectlAssetName(), + ghRepo: GetGHRepoService(), }, ExecutableName: flytectl, Version: stdlibversion.Version, diff --git a/flytectl/pkg/github/provider.go b/flytectl/pkg/github/provider.go index 0e37cee284..1d3b63e874 100644 --- a/flytectl/pkg/github/provider.go +++ b/flytectl/pkg/github/provider.go @@ -15,24 +15,15 @@ import ( "github.com/mouuff/go-rocket-update/pkg/provider" ) -// type GitHubProvider struct { -// provider.Github -// } - // Github provider finds a archive file in the repository's releases to provide files -type GitHubProvider struct { +type GHProvider struct { RepositoryURL string // Repository URL, example github.com/mouuff/go-rocket-update ArchiveName string // Archive name (the zip/tar.gz you upload for a release on github), example: binaries.zip tmpDir string // temporary directory this is used internally decompressProvider provider.Provider // provider used to decompress the downloaded archive archivePath string // path to the downloaded archive (should be in tmpDir) -} - -// githubTag struct used to unmarshal response from github -// https://api.github.com/repos/ownerName/projectName/tags -type githubTag struct { - Name string `json:"name"` + ghRepo GHRepoService // github repository service } // githubRepositoryInfo is used to get the name of the project and the owner name @@ -43,7 +34,7 @@ type githubRepositoryInfo struct { } // getRepositoryInfo parses the github repository URL -func (c *GitHubProvider) repositoryInfo() (*githubRepositoryInfo, error) { +func (c *GHProvider) repositoryInfo() (*githubRepositoryInfo, error) { re := regexp.MustCompile(`github\.com/(.*?)/(.*?)$`) submatches := re.FindAllStringSubmatch(c.RepositoryURL, 1) if len(submatches) < 1 { @@ -57,7 +48,7 @@ func (c *GitHubProvider) repositoryInfo() (*githubRepositoryInfo, error) { // getArchiveURL get the archive URL for the github repository // If no tag is provided then the latest version is selected -func (c *GitHubProvider) getArchiveURL(tag string) (string, error) { +func (c *GHProvider) getArchiveURL(tag string) (string, error) { if len(tag) == 0 { // Get latest version if no tag is provided var err error @@ -80,41 +71,45 @@ func (c *GitHubProvider) getArchiveURL(tag string) (string, error) { } // Open opens the provider -func (c *GitHubProvider) Open() (err error) { +func (c *GHProvider) Open() (err error) { archiveURL, err := c.getArchiveURL("") // get archive url for latest version if err != nil { - return + return err + } + req, err := http.NewRequest("GET", archiveURL, nil) + if err != nil { + return err } - resp, err := http.Get(archiveURL) + resp, err := http.DefaultClient.Do(req) if err != nil { - return + return err } defer resp.Body.Close() c.tmpDir, err = os.MkdirTemp("", "rocket-update") if err != nil { - return + return err } c.archivePath = filepath.Join(c.tmpDir, c.ArchiveName) archiveFile, err := os.Create(c.archivePath) if err != nil { - return + return err } _, err = io.Copy(archiveFile, resp.Body) archiveFile.Close() if err != nil { - return + return err } c.decompressProvider, err = provider.Decompress(c.archivePath) if err != nil { - return nil + return err } return c.decompressProvider.Open() } // Close closes the provider -func (c *GitHubProvider) Close() error { +func (c *GHProvider) Close() error { if c.decompressProvider != nil { c.decompressProvider.Close() c.decompressProvider = nil @@ -129,17 +124,17 @@ func (c *GitHubProvider) Close() error { } // GetLatestVersion gets the latest version -func (c *GitHubProvider) GetLatestVersion() (string, error) { +func (c *GHProvider) GetLatestVersion() (string, error) { tags, err := c.getReleases() if err != nil { return "", err } - latest_tag := tags[0].GetTagName() - return latest_tag, err + latestTag := tags[0].GetTagName() + return latestTag, err } -func (c *GitHubProvider) getReleases() ([]*go_github.RepositoryRelease, error) { - g := GetGHRepoService() +func (c *GHProvider) getReleases() ([]*go_github.RepositoryRelease, error) { + g := c.ghRepo releases, _, err := g.ListReleases(context.Background(), owner, flyte, &go_github.ListOptions{ PerPage: 100, }) @@ -156,7 +151,7 @@ func (c *GitHubProvider) getReleases() ([]*go_github.RepositoryRelease, error) { } // Walk walks all the files provided -func (c *GitHubProvider) Walk(walkFn provider.WalkFunc) error { +func (c *GHProvider) Walk(walkFn provider.WalkFunc) error { if c.decompressProvider == nil { // TODO specify error return provider.ErrNotOpenned @@ -165,6 +160,6 @@ func (c *GitHubProvider) Walk(walkFn provider.WalkFunc) error { } // Retrieve file relative to "provider" to destination -func (c *GitHubProvider) Retrieve(src string, dest string) error { +func (c *GHProvider) Retrieve(src string, dest string) error { return c.decompressProvider.Retrieve(src, dest) } diff --git a/flytectl/pkg/github/provider_test.go b/flytectl/pkg/github/provider_test.go new file mode 100644 index 0000000000..d9b18eee2d --- /dev/null +++ b/flytectl/pkg/github/provider_test.go @@ -0,0 +1,66 @@ +package github + +import ( + "testing" + + "github.com/flyteorg/flyte/flytectl/pkg/github/mocks" + go_github "github.com/google/go-github/v42/github" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +func TestGetLatestFlytectlVersion(t *testing.T) { + t.Run("Get latest release", func(t *testing.T) { + mockGh := &mocks.GHRepoService{} + // return a list of github releases + mockGh.OnListReleasesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( + []*go_github.RepositoryRelease{ + {TagName: go_github.String("flytectl/1.2.4")}, + {TagName: go_github.String("flytectl/1.2.3")}, + {TagName: go_github.String("other-1.0.0")}, + }, + nil, + nil, + ) + mockProvider := &GHProvider{ + RepositoryURL: flytectlRepository, + ArchiveName: getFlytectlAssetName(), + ghRepo: mockGh, + } + + latestVersion, err := mockProvider.GetLatestVersion() + assert.Nil(t, err) + assert.Equal(t, "flytectl/1.2.4", latestVersion) + }) +} + +func TestGetFlytectlReleases(t *testing.T) { + t.Run("Get releases", func(t *testing.T) { + mockGh := &mocks.GHRepoService{} + allReleases := []*go_github.RepositoryRelease{ + {TagName: go_github.String("flytectl/1.2.4")}, + {TagName: go_github.String("flytectl/1.2.3")}, + {TagName: go_github.String("other-1.0.0")}, + } + releases := []*go_github.RepositoryRelease{ + {TagName: go_github.String("flytectl/1.2.4")}, + {TagName: go_github.String("flytectl/1.2.3")}, + } + // return a list of github releases + mockGh.OnListReleasesMatch(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return( + allReleases, + nil, + nil, + ) + mockProvider := &GHProvider{ + RepositoryURL: flytectlRepository, + ArchiveName: getFlytectlAssetName(), + ghRepo: mockGh, + } + + flytectlReleases, err := mockProvider.getReleases() + assert.Nil(t, err) + assert.Equal(t, releases, flytectlReleases) + }) +} From 01970ffef677e432acc19f1c42f7379a76df9c38 Mon Sep 17 00:00:00 2001 From: novahow Date: Wed, 26 Jun 2024 11:09:29 +0800 Subject: [PATCH 3/6] fix version error Signed-off-by: novahow --- flytectl/cmd/upgrade/upgrade.go | 7 +++---- flytectl/cmd/version/version.go | 2 +- flytectl/pkg/github/provider.go | 10 ++++++++++ flytectl/pkg/github/provider_test.go | 3 +++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/flytectl/cmd/upgrade/upgrade.go b/flytectl/cmd/upgrade/upgrade.go index 9991f934e4..885b1994ff 100644 --- a/flytectl/cmd/upgrade/upgrade.go +++ b/flytectl/cmd/upgrade/upgrade.go @@ -114,20 +114,19 @@ func upgrade(u *updater.Updater) (string, error) { } func isUpgradeSupported(goos platformutil.Platform) (bool, error) { - latest, err := github.FlytectlReleaseConfig.Provider.GetLatestVersion() + latest, err := github.FlytectlReleaseConfig.Provider.(*github.GHProvider).GetCleanLatestVersion() if err != nil { return false, err } - compatibleVersion := strings.TrimPrefix(latest, fmt.Sprintf("%s/", github.FlytectlReleaseConfig.ExecutableName)) - if isGreater, err := util.IsVersionGreaterThan(compatibleVersion, stdlibversion.Version); err != nil { + if isGreater, err := util.IsVersionGreaterThan(latest, stdlibversion.Version); err != nil { return false, err } else if !isGreater { fmt.Println("You already have the latest version of Flytectl") return false, nil } - message, err := github.GetUpgradeMessage(compatibleVersion, goos) + message, err := github.GetUpgradeMessage(latest, goos) if err != nil { return false, err } diff --git a/flytectl/cmd/version/version.go b/flytectl/cmd/version/version.go index 7ff69cae29..65fe1dab96 100644 --- a/flytectl/cmd/version/version.go +++ b/flytectl/cmd/version/version.go @@ -53,7 +53,7 @@ func GetVersionCommand(rootCmd *cobra.Command) map[string]cmdCore.CommandEntry { func getVersion(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { goos := platformutil.Platform(runtime.GOOS) - version, err := github.FlytectlReleaseConfig.GetLatestVersion() + version, err := github.FlytectlReleaseConfig.Provider.(*github.GHProvider).GetCleanLatestVersion() if err != nil { logger.Error(ctx, "Unable to get the latest version because %v", err) } else { diff --git a/flytectl/pkg/github/provider.go b/flytectl/pkg/github/provider.go index 1d3b63e874..9c8407052b 100644 --- a/flytectl/pkg/github/provider.go +++ b/flytectl/pkg/github/provider.go @@ -133,6 +133,16 @@ func (c *GHProvider) GetLatestVersion() (string, error) { return latestTag, err } +// GetCleanLatestVersion gets the latest version without the "flytectl/" prefix +func (c *GHProvider) GetCleanLatestVersion() (string, error) { + latest, err := c.GetLatestVersion() + if err != nil { + return "", err + } + clearVersion := strings.TrimPrefix(latest, fmt.Sprintf("%s/", flytectl)) + return clearVersion, nil +} + func (c *GHProvider) getReleases() ([]*go_github.RepositoryRelease, error) { g := c.ghRepo releases, _, err := g.ListReleases(context.Background(), owner, flyte, &go_github.ListOptions{ diff --git a/flytectl/pkg/github/provider_test.go b/flytectl/pkg/github/provider_test.go index d9b18eee2d..280f69e82d 100644 --- a/flytectl/pkg/github/provider_test.go +++ b/flytectl/pkg/github/provider_test.go @@ -32,6 +32,9 @@ func TestGetLatestFlytectlVersion(t *testing.T) { latestVersion, err := mockProvider.GetLatestVersion() assert.Nil(t, err) assert.Equal(t, "flytectl/1.2.4", latestVersion) + cleanVersion, err := mockProvider.GetCleanLatestVersion() + assert.Nil(t, err) + assert.Equal(t, "1.2.4", cleanVersion) }) } From 73937427f5fe73f28af53398c9fe83ec2e694d70 Mon Sep 17 00:00:00 2001 From: novahow Date: Fri, 28 Jun 2024 12:19:22 +0800 Subject: [PATCH 4/6] remove testmain Signed-off-by: novahow --- flytectl/Makefile | 2 +- flytectl/cmd/upgrade/upgrade_test.go | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/flytectl/Makefile b/flytectl/Makefile index 14c1338a93..0cb9ad1854 100644 --- a/flytectl/Makefile +++ b/flytectl/Makefile @@ -4,7 +4,7 @@ include ../boilerplate/flyte/docker_build/Makefile include ../boilerplate/flyte/golang_test_targets/Makefile include ../boilerplate/flyte/end2end/Makefile -GIT_VERSION := $(shell git describe --always --tags) +GIT_VERSION := $(shell git describe --dirty --tags --long --match flytectl/* --first-parent | sed 's/^flytectl\///') GIT_HASH := $(shell git rev-parse --short HEAD) TIMESTAMP := $(shell date '+%Y-%m-%d') PACKAGE ?=github.com/flyteorg/flyte/flytestdlib diff --git a/flytectl/cmd/upgrade/upgrade_test.go b/flytectl/cmd/upgrade/upgrade_test.go index 5cb52f2e98..f1f97a74c4 100644 --- a/flytectl/cmd/upgrade/upgrade_test.go +++ b/flytectl/cmd/upgrade/upgrade_test.go @@ -1,7 +1,6 @@ package upgrade import ( - "fmt" "sort" "testing" @@ -176,7 +175,3 @@ func TestSelfUpgradeRollback(t *testing.T) { }) } - -func TestMain(_ *testing.M) { - fmt.Println("Skipping due to https://github.com/flyteorg/flyte/issues/5372") -} From ec301333fe176b18aeb041767885a8f4f6af004e Mon Sep 17 00:00:00 2001 From: Eduardo Apolinario Date: Mon, 1 Jul 2024 14:26:06 -0700 Subject: [PATCH 5/6] Run make lint-fix Signed-off-by: Eduardo Apolinario --- flytectl/pkg/github/provider_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/flytectl/pkg/github/provider_test.go b/flytectl/pkg/github/provider_test.go index 280f69e82d..e342ec04e9 100644 --- a/flytectl/pkg/github/provider_test.go +++ b/flytectl/pkg/github/provider_test.go @@ -5,7 +5,6 @@ import ( "github.com/flyteorg/flyte/flytectl/pkg/github/mocks" go_github "github.com/google/go-github/v42/github" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) From da3a344f4978028d9a6b6d0a5a2cff9a4d9bb013 Mon Sep 17 00:00:00 2001 From: Eduardo Apolinario Date: Mon, 1 Jul 2024 17:11:36 -0700 Subject: [PATCH 6/6] Call TearDown Signed-off-by: Eduardo Apolinario --- flytectl/Makefile | 2 +- flytectl/cmd/version/version_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/flytectl/Makefile b/flytectl/Makefile index 8233395701..17c8b5f2bc 100644 --- a/flytectl/Makefile +++ b/flytectl/Makefile @@ -4,7 +4,7 @@ include ../boilerplate/flyte/docker_build/Makefile include ../boilerplate/flyte/golang_test_targets/Makefile include ../boilerplate/flyte/end2end/Makefile -GIT_VERSION := $(shell git describe --dirty --tags --long --match flytectl/* --first-parent | sed 's/^flytectl\///') +GIT_VERSION := $(shell git describe --dirty --tags --long --match 'flytectl/*' --first-parent | sed 's/^flytectl\///') GIT_HASH := $(shell git rev-parse --short HEAD) TIMESTAMP := $(shell date '+%Y-%m-%d') PACKAGE ?=github.com/flyteorg/flyte/flytestdlib diff --git a/flytectl/cmd/version/version_test.go b/flytectl/cmd/version/version_test.go index a1abbd7883..791a895e46 100644 --- a/flytectl/cmd/version/version_test.go +++ b/flytectl/cmd/version/version_test.go @@ -55,6 +55,7 @@ func TestVersionCommand(t *testing.T) { func TestVersionCommandFunc(t *testing.T) { ctx := context.Background() s := testutils.Setup() + defer s.TearDown() stdlibversion.Build = "" stdlibversion.BuildTime = "" stdlibversion.Version = testVersion @@ -67,6 +68,7 @@ func TestVersionCommandFunc(t *testing.T) { func TestVersionCommandFuncError(t *testing.T) { ctx := context.Background() s := testutils.Setup() + defer s.TearDown() stdlibversion.Build = "" stdlibversion.BuildTime = "" stdlibversion.Version = "v" @@ -79,6 +81,7 @@ func TestVersionCommandFuncError(t *testing.T) { func TestVersionCommandFuncErr(t *testing.T) { ctx := context.Background() s := testutils.Setup() + defer s.TearDown() stdlibversion.Build = "" stdlibversion.BuildTime = "" stdlibversion.Version = testVersion