From f21a18e4ba7ed4e398f6b13276ccb61914973add Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Wed, 12 Oct 2022 18:29:27 -0500 Subject: [PATCH] :alien: Update GitHub Actions output due to set-output deprecation See https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ --- internal/actions/dump/dump.go | 6 ++++-- internal/github/actions.go | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 internal/github/actions.go 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 +}