Skip to content

Commit

Permalink
Feat: CI or PIPELINE_WORKSPACE change default detached proxy behavior…
Browse files Browse the repository at this point in the history
… instead of ignoring TENV_DETACHED_PROXY (#309)

* CI or PIPELINE_WORKSPACE change default detached behavior, TENV_DETACHED_PROXY can still force it
* update README (TENV_DETACHED_PROXY default impacted by CI and PIPELINE_WORKSPACE)

Signed-off-by: Denis Vaumoron <dvaumoron@gmail.com>
  • Loading branch information
dvaumoron authored Dec 26, 2024
1 parent a48603f commit a4da089
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ If set to true **tenv** will automatically install missing tool versions needed.

<details><summary><b>TENV_DETACHED_PROXY</b></summary><br>

String (Default: false on Windows OS, true on other OS)
String (Default: false on Windows OS, true on other OS without CI or PIPELINE_WORKSPACE environment variable)

Enable **tenv** proxies detached behaviour (use a new process group id when launching tool command, allow to avoid killing proxied tool process earlier than expected when proxies redirect interrupt signal already sended to whole process group (issue occurrences known on macOS and Linux)).

Expand Down
5 changes: 3 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ const (

archEnvName = "ARCH"
autoInstallEnvName = "AUTO_INSTALL"
PipelineWsEnvName = "PIPELINE_WORKSPACE"
CiEnvName = "CI"
DefaultConstraint = "DEFAULT_CONSTRAINT"
DefaultVersion = "DEFAULT_" + Version
forceRemoteEnvName = "FORCE_REMOTE"
Expand All @@ -55,6 +53,9 @@ const (
rootPathEnvName = "ROOT"
Version = "VERSION"

CiEnvName = "CI"
PipelineWsEnvName = "PIPELINE_WORKSPACE"

githubPrefix = "GITHUB_"
githubActionsEnvName = githubPrefix + "ACTIONS"
GithubOutputEnvName = githubPrefix + "OUTPUT"
Expand Down
25 changes: 13 additions & 12 deletions versionmanager/proxy/detach/detached_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,25 @@ import (
configutils "github.com/tofuutils/tenv/v4/config/utils"
)

const msgCiErr = "Failed to read " + config.CiEnvName + " environment variable, disable behavior :"
const msgErr = "Failed to read " + config.TenvDetachedProxyEnvName + " environment variable, disable behavior :"
const msgPipelineWsErr = "Failed to read " + config.PipelineWsEnvName + " environment variable, disable behavior :"
const (
msgDisableErr = msgStart + config.TenvDetachedProxyEnvName + " environment variable, disable behavior :"
msgKeepErr = msgStart + config.CiEnvName + " or " + config.PipelineWsEnvName + " environment variable, keep detached default behavior to true :"
msgStart = "Failed to read "
)

func InitBehaviorFromEnv(cmd *exec.Cmd, getenv configutils.GetenvFunc) {
ciEnv, ciErr := getenv.Bool(false, config.CiEnvName)
ciEnv, ciErr := getenv.BoolFallback(false, config.CiEnvName, config.PipelineWsEnvName)
if ciErr != nil {
fmt.Println(msgCiErr, ciErr) //nolint
fmt.Println(msgKeepErr, ciErr) //nolint
}
detached, err := getenv.Bool(true, config.TenvDetachedProxyEnvName)

defaultDetached := !ciEnv
detached, err := getenv.Bool(defaultDetached, config.TenvDetachedProxyEnvName)
if err != nil {
fmt.Println(msgErr, err) //nolint
fmt.Println(msgDisableErr, err) //nolint
}
pipelineWsEnv, pipelineWsErr := getenv.Bool(false, config.PipelineWsEnvName)
if pipelineWsErr != nil {
fmt.Println(msgPipelineWsErr, pipelineWsErr) //nolint
}
if ciEnv || pipelineWsEnv || !detached {

if !detached {
return
}

Expand Down
8 changes: 4 additions & 4 deletions versionmanager/proxy/detach/detached_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ import (
)

const (
msgErr = msgStart + "failed to read environment variable :"
msgNotApplied = msgStart + "can not apply environment variable"
msgStart = config.TenvDetachedProxyEnvName + " behavior is always disabled on Windows OS, "
msgFailReadErr = msgStart + "failed to read environment variable :"
msgNotApplied = msgStart + "can not apply environment variable"
msgStart = config.TenvDetachedProxyEnvName + " behavior is always disabled on Windows OS, "
)

func InitBehaviorFromEnv(_ *exec.Cmd, getenv configutils.GetenvFunc) {
switch detached, err := getenv.Bool(false, config.TenvDetachedProxyEnvName); {
case err != nil:
fmt.Println(msgErr, err) //nolint
fmt.Println(msgFailReadErr, err) //nolint
case detached:
fmt.Println(msgNotApplied) //nolint
}
Expand Down

0 comments on commit a4da089

Please sign in to comment.