Skip to content

Commit 4e5c851

Browse files
committed
Backport new ExportVariable and SetPath
Backport implementation from actions/toolkit#571
1 parent e31e1f9 commit 4e5c851

4 files changed

Lines changed: 28 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: 7 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".

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)