diff --git a/internal/actions/dump/dump.go b/internal/actions/dump/dump.go index d4c1d978..cc40934a 100644 --- a/internal/actions/dump/dump.go +++ b/internal/actions/dump/dump.go @@ -2,10 +2,10 @@ package dump import ( "errors" - "fmt" "github.com/clevyr/kubedb/internal/command" "github.com/clevyr/kubedb/internal/config" "github.com/clevyr/kubedb/internal/database/sqlformat" + "github.com/clevyr/kubedb/internal/github" "github.com/clevyr/kubedb/internal/progressbar" gzip "github.com/klauspost/pgzip" log "github.com/sirupsen/logrus" @@ -62,7 +62,9 @@ func (action Dump) Run() (err error) { }).Info("exporting database") if viper.GetBool("github-actions") { - fmt.Println("::set-output name=filename::" + action.Filename) + if err := github.SetOutput("filename", action.Filename); err != nil { + return err + } } var startTime = time.Now() diff --git a/internal/github/actions.go b/internal/github/actions.go new file mode 100644 index 00000000..7f3081b3 --- /dev/null +++ b/internal/github/actions.go @@ -0,0 +1,22 @@ +package github + +import ( + "fmt" + "os" +) + +func SetOutput(name, value string) error { + if filename := os.Getenv("GITHUB_OUTPUT"); filename != "" { + f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY, 0755) + if err != nil { + return err + } + if _, err := f.WriteString(name + "=" + value + "\n"); err != nil { + return err + } + return f.Close() + } else { + fmt.Println("::set-output name=" + name + "::" + value) + } + return nil +}