Skip to content

Commit 11a3d51

Browse files
authored
Update core upstream (#19)
* Add SetFailedf and IsDebug helpers SetFailedf prevents from having to use Sprintf in caller methods * Backport new ExportVariable and SetPath Backport implementation from actions/toolkit#571
1 parent e2e00e7 commit 11a3d51

4 files changed

Lines changed: 38 additions & 2 deletions

File tree

core/command.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ func IssueCommand(kind string, properties map[string]string, message string) {
4545
stdoutSetter.Unlock()
4646
}
4747

48+
// issueFileCommand implements stores the command in a file
49+
// see https://github.com/actions/toolkit/pull/571/files#diff-9ce6eb99f5fb5529e795254801e03ae56d67d3d5fcbec635f91e9a8a61ad8b64R10
50+
func issueFileCommand(command string, message string) error {
51+
path, ok := os.LookupEnv("GITHUB_" + command)
52+
if ok {
53+
fd, err := os.OpenFile(path, os.O_RDWR, 0)
54+
if err != nil {
55+
return err
56+
}
57+
fmt.Fprintln(fd, message)
58+
return nil
59+
}
60+
return fmt.Errorf("unable to find command file GITHUB_%s", command)
61+
}
62+
4863
type command struct {
4964
command string
5065
properties map[string]string

core/core.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ var (
2222

2323
// ExportVariable sets the environment varaible name (for this action and future actions)
2424
func ExportVariable(name, value string) {
25+
const delimiter = "_GitHubActionsFileCommandDelimeter_"
26+
if err := issueFileCommand("ENV", fmt.Sprintf("%s<<%s%s%s%s%s", name, delimiter, EOF, value, delimiter, EOF)); err != nil {
27+
IssueCommand("set-env", map[string]string{"name": name}, value)
28+
}
2529
os.Setenv(name, value)
26-
IssueCommand("set-env", map[string]string{"name": name}, value)
2730
}
2831

2932
// SetSecret registers a secret which will get masked from logs
@@ -33,8 +36,10 @@ func SetSecret(secret string) {
3336

3437
// AddPath prepends inputPath to the PATH (for this action and future actions)
3538
func AddPath(path string) {
39+
if err := issueFileCommand("PATH", path); err != nil {
40+
Issue("add-path", path)
41+
}
3642
// TODO js: process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`
37-
Issue("add-path", path)
3843
}
3944

4045
// GetBoolInput gets the value of an input and returns whether it equals "true".
@@ -63,6 +68,11 @@ func SetOutput(name, value string) {
6368
IssueCommand("set-output", map[string]string{"name": name}, value)
6469
}
6570

71+
// SetFailedf sets the action status to failed and sets an error message
72+
func SetFailedf(format string, args ...interface{}) {
73+
SetFailed(fmt.Sprintf(format, args...))
74+
}
75+
6676
// SetFailed sets the action status to failed and sets an error message
6777
func SetFailed(message string) {
6878
statusAccess.Lock()
@@ -139,3 +149,8 @@ func SaveState(name, value string) {
139149
func GetState(name string) string {
140150
return os.Getenv("STATE_" + name)
141151
}
152+
153+
// IsDebug returns whether the github actions is currently under debug
154+
func IsDebug() bool {
155+
return os.Getenv("RUNNER_DEBUG") == "1"
156+
}

core/core_unix.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package core
2+
3+
const EOF = "\n"

core/core_windows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package core
2+
3+
const EOF = "\r\n"

0 commit comments

Comments
 (0)