From 8bd95de51178e12a15301044a1890d95efd1fe1a Mon Sep 17 00:00:00 2001 From: Cristovao Cordeiro Date: Thu, 24 Oct 2024 09:32:23 +0200 Subject: [PATCH] fix(cli-client): empty directories cause CI validation error (#277) --- tools/cli-client/internals/trigger/build_metadata.go | 3 ++- tools/cli-client/internals/trigger/build_metadata_test.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/cli-client/internals/trigger/build_metadata.go b/tools/cli-client/internals/trigger/build_metadata.go index 50cec384..377f0107 100644 --- a/tools/cli-client/internals/trigger/build_metadata.go +++ b/tools/cli-client/internals/trigger/build_metadata.go @@ -71,7 +71,8 @@ func InferBuildMetadata() BuildMetadata { logger.Panicf("Subprocess `git rev-parse --show-prefix` failed: %v", err) } // remote the trailing newline - prefix := strings.TrimSpace(string(prefixBytes)) + // also prepend a "./" to cope with empty prefixes + prefix := "./" + strings.TrimSpace(string(prefixBytes)) logger.Debugf("Directory: %s", prefix) buildMetadata := BuildMetadata{ diff --git a/tools/cli-client/internals/trigger/build_metadata_test.go b/tools/cli-client/internals/trigger/build_metadata_test.go index f228eb23..3285364c 100644 --- a/tools/cli-client/internals/trigger/build_metadata_test.go +++ b/tools/cli-client/internals/trigger/build_metadata_test.go @@ -33,7 +33,7 @@ func (s *BuildMetadataSuite) TestGetRockcraftYamlName(c *C) { c.Assert(result, Equals, expected) } -func (s *BuildMetadataSuite) TestGetBuildMetadataCustomDirector(c *C) { +func (s *BuildMetadataSuite) TestGetBuildMetadataCustomDirectory(c *C) { cmd := exec.Command("git", "--version") if err := cmd.Run(); err != nil { c.Fatal("git not installed") @@ -52,7 +52,7 @@ func (s *BuildMetadataSuite) TestGetBuildMetadataCustomDirector(c *C) { result := trigger.InferBuildMetadata() - prefix := filepath.Join("mock_rock", "1.0") + "/" + prefix := "./" + filepath.Join("mock_rock", "1.0") + "/" head, err := exec.Command("git", "rev-parse", "HEAD").Output() headStr := strings.TrimSpace(string(head)) c.Assert(err, IsNil)