From a7c67bd9fc97a7f75778c1ef8f36ab587a04a788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20K=C3=A4ldstr=C3=B6m?= Date: Thu, 10 Jun 2021 15:56:49 +0300 Subject: [PATCH] Output relative paths --- cmd/render-drawio/main.go | 5 +---- pkg/render/render.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cmd/render-drawio/main.go b/cmd/render-drawio/main.go index 3823352..96ef344 100644 --- a/cmd/render-drawio/main.go +++ b/cmd/render-drawio/main.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "os" - "strings" "time" "github.com/racklet/render-drawio-action/pkg/render" @@ -85,7 +84,5 @@ func run() error { } // Set the GH Action output - render.GitHubActionSetOutput("rendered-files", strings.Join(outputFiles, " ")) - - return nil + return render.GitHubActionSetFilesOutput("rendered-files", cfg.RootDir, outputFiles) } diff --git a/pkg/render/render.go b/pkg/render/render.go index 2dc2bc0..cc42ab7 100644 --- a/pkg/render/render.go +++ b/pkg/render/render.go @@ -243,3 +243,20 @@ func GitHubActionSetOutput(key, val string) { zap.S().Infow("Setting Github Action output", key, val) fmt.Printf("::set-output name=%s::%s\n", key, val) } + +func GitHubActionSetFilesOutput(key, rootDir string, files []string) error { + // Only run filepath.Rel if rootDir != "" + if len(rootDir) != 0 { + var err error + for i := range files { + // Make the file path relative to root dir + files[i], err = filepath.Rel(rootDir, files[i]) + if err != nil { + return err + } + } + } + // Run the generic function + GitHubActionSetOutput(key, strings.Join(files, " ")) + return nil +}