Skip to content

Commit

Permalink
Fix SetEnv overwriting the result of the previous call (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtharp committed Feb 1, 2022
1 parent 2d72218 commit 1e25ca7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions actions.go
Expand Up @@ -125,10 +125,14 @@ func (c *Action) IssueFileCommand(cmd *Command) error {

filepath := c.getenv(e)
msg := []byte(cmd.Message + EOF)
if err := ioutil.WriteFile(filepath, msg, os.ModeAppend); err != nil {
f, err := os.OpenFile(filepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return fmt.Errorf(errFileCmdFmt, err)
}
defer f.Close()
if _, err := f.Write(msg); err != nil {
return fmt.Errorf(errFileCmdFmt, err)
}

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions actions_test.go
Expand Up @@ -290,6 +290,7 @@ func TestAction_SetEnv(t *testing.T) {
fakeGetenvFunc := newFakeGetenvFunc(t, envGitHubEnv, file.Name())
a := New(WithWriter(&b), WithGetenv(fakeGetenvFunc))
a.SetEnv("key", "value")
a.SetEnv("key2", "value2")

// expect an empty stdout buffer
if got, want := b.String(), ""; got != want {
Expand All @@ -303,6 +304,7 @@ func TestAction_SetEnv(t *testing.T) {
}

want := "key<<_GitHubActionsFileCommandDelimeter_" + EOF + "value" + EOF + "_GitHubActionsFileCommandDelimeter_" + EOF
want += "key2<<_GitHubActionsFileCommandDelimeter_" + EOF + "value2" + EOF + "_GitHubActionsFileCommandDelimeter_" + EOF
if got := string(data); got != want {
t.Errorf("expected %q to be %q", got, want)
}
Expand Down

0 comments on commit 1e25ca7

Please sign in to comment.