Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for environment files #598

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type cfgBuild struct {
KillDelay time.Duration `toml:"kill_delay"`
Rerun bool `toml:"rerun"`
RerunDelay int `toml:"rerun_delay"`
EnvironmentFile string `toml:"environment_file"`
regexCompiled []*regexp.Regexp
}

Expand Down
30 changes: 30 additions & 0 deletions runner/environment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package runner

import (
"bufio"
"fmt"
"os"
"os/exec"
)

func (e *Engine) modifyEnvironment(c *exec.Cmd) error {
if e.config.Build.EnvironmentFile == "" {
return nil
}

env := os.Environ()

envFile, err := os.Open(e.config.Build.EnvironmentFile)
if err != nil {
return fmt.Errorf("failed to open environment file: %w")

Check failure on line 19 in runner/environment.go

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

SA5009: Printf format %w reads arg #1, but call has only 0 args (staticcheck)
}
defer envFile.Close()

scan := bufio.NewScanner(envFile)
for scan.Scan() {
env = append(env, scan.Text())
mpldr marked this conversation as resolved.
Show resolved Hide resolved
}

c.Env = env
return nil
}
4 changes: 4 additions & 0 deletions runner/util_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func (e *Engine) killCmd(cmd *exec.Cmd) (pid int, err error) {

func (e *Engine) startCmd(cmd string) (*exec.Cmd, io.ReadCloser, io.ReadCloser, error) {
c := exec.Command("/bin/sh", "-c", cmd)
err := e.modifyEnvironment(c)
if err != nil {
return nil, nil, nil, err
}
f, err := pty.Start(c)
return c, f, f, err
}
4 changes: 4 additions & 0 deletions runner/util_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (e *Engine) startCmd(cmd string) (*exec.Cmd, io.ReadCloser, io.ReadCloser,
c.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
}
err := e.modifyEnvironment(c)
if err != nil {
return nil, nil, nil, err
}

stderr, err := c.StderrPipe()
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions runner/util_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func (e *Engine) startCmd(cmd string) (*exec.Cmd, io.ReadCloser, io.ReadCloser,
if err != nil {
return nil, nil, nil, err
}
err = e.modifyEnvironment(c)
if err != nil {
return nil, nil, nil, err
}
stdout, err := c.StdoutPipe()
if err != nil {
return nil, nil, nil, err
Expand Down
Loading