diff --git a/core/command.go b/core/command.go index 155d40e..bd0812c 100644 --- a/core/command.go +++ b/core/command.go @@ -45,6 +45,21 @@ func IssueCommand(kind string, properties map[string]string, message string) { stdoutSetter.Unlock() } +// issueFileCommand implements stores the command in a file +// see https://github.com/actions/toolkit/pull/571/files#diff-9ce6eb99f5fb5529e795254801e03ae56d67d3d5fcbec635f91e9a8a61ad8b64R10 +func issueFileCommand(command string, message string) error { + path, ok := os.LookupEnv("GITHUB_" + command) + if ok { + fd, err := os.OpenFile(path, os.O_RDWR, 0) + if err != nil { + return err + } + fmt.Fprintln(fd, message) + return nil + } + return fmt.Errorf("unable to find command file GITHUB_%s", command) +} + type command struct { command string properties map[string]string diff --git a/core/core.go b/core/core.go index 511e17e..3d6ac17 100644 --- a/core/core.go +++ b/core/core.go @@ -22,8 +22,11 @@ var ( // ExportVariable sets the environment varaible name (for this action and future actions) func ExportVariable(name, value string) { + const delimiter = "_GitHubActionsFileCommandDelimeter_" + if err := issueFileCommand("ENV", fmt.Sprintf("%s<<%s%s%s%s%s", name, delimiter, EOF, value, delimiter, EOF)); err != nil { + IssueCommand("set-env", map[string]string{"name": name}, value) + } os.Setenv(name, value) - IssueCommand("set-env", map[string]string{"name": name}, value) } // SetSecret registers a secret which will get masked from logs @@ -33,8 +36,10 @@ func SetSecret(secret string) { // AddPath prepends inputPath to the PATH (for this action and future actions) func AddPath(path string) { + if err := issueFileCommand("PATH", path); err != nil { + Issue("add-path", path) + } // TODO js: process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}` - Issue("add-path", path) } // GetBoolInput gets the value of an input and returns whether it equals "true". @@ -63,6 +68,11 @@ func SetOutput(name, value string) { IssueCommand("set-output", map[string]string{"name": name}, value) } +// SetFailedf sets the action status to failed and sets an error message +func SetFailedf(format string, args ...interface{}) { + SetFailed(fmt.Sprintf(format, args...)) +} + // SetFailed sets the action status to failed and sets an error message func SetFailed(message string) { statusAccess.Lock() @@ -139,3 +149,8 @@ func SaveState(name, value string) { func GetState(name string) string { return os.Getenv("STATE_" + name) } + +// IsDebug returns whether the github actions is currently under debug +func IsDebug() bool { + return os.Getenv("RUNNER_DEBUG") == "1" +} diff --git a/core/core_unix.go b/core/core_unix.go new file mode 100644 index 0000000..5df125d --- /dev/null +++ b/core/core_unix.go @@ -0,0 +1,3 @@ +package core + +const EOF = "\n" diff --git a/core/core_windows.go b/core/core_windows.go new file mode 100644 index 0000000..a4b8c7f --- /dev/null +++ b/core/core_windows.go @@ -0,0 +1,3 @@ +package core + +const EOF = "\r\n"