Skip to content

Commit

Permalink
Add no output timeout property (#309)
Browse files Browse the repository at this point in the history
Added a new Step property no_output_timeout, that can be used to set the timeout (in seconds) until the Step is aborted when no stdout/stderr is received.

This Step level property will override any global value set via BITRISE_NO_OUTPUT_TIMEOUT env var.

- Inject CLI version during release.
  • Loading branch information
lpusok authored Aug 8, 2022
1 parent 051a282 commit 6e12d27
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ builds:
- goos: linux
goarch: arm64
ldflags:
- -X github.com/bitrise-io/stepman/version.Version={{ .Version }}
- -X github.com/bitrise-io/stepman/version.Commit={{ .FullCommit }}
- -X github.com/bitrise-io/stepman/version.BuildNumber={{ index .Env "BITRISE_BUILD_NUMBER" }}

Expand Down
4 changes: 2 additions & 2 deletions _tests/integration/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func Test_VersionOutput(t *testing.T) {
{
out, err := command.RunCommandAndReturnCombinedStdoutAndStderr(binPath(), "version")
require.NoError(t, err, out)
require.Equal(t, "0.13.2", out)
require.Equal(t, "0.0.0-development", out)
}

t.Log("Version --full")
Expand All @@ -23,7 +23,7 @@ func Test_VersionOutput(t *testing.T) {
require.NoError(t, err, out)

expectedOSVersion := fmt.Sprintf("%s (%s)", runtime.GOOS, runtime.GOARCH)
expectedVersionOut := fmt.Sprintf(`version: 0.13.2
expectedVersionOut := fmt.Sprintf(`version: 0.0.0-development
os: %s
go: %s
build_number:
Expand Down
4 changes: 2 additions & 2 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"os"
"path"

log "github.com/sirupsen/logrus"
"github.com/bitrise-io/stepman/stepman"
"github.com/bitrise-io/stepman/version"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -51,7 +51,7 @@ func Run() {
app := cli.NewApp()
app.Name = path.Base(os.Args[0])
app.Usage = "Step manager"
app.Version = version.VERSION
app.Version = version.Version

app.Author = ""
app.Email = ""
Expand Down
2 changes: 1 addition & 1 deletion cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func printVersionCmd(c *cli.Context) error {
}

versionOutput := VersionOutputModel{}
versionOutput.Version = ver.VERSION
versionOutput.Version = ver.Version
versionOutput.OS = fmt.Sprintf("%s (%s)", runtime.GOOS, runtime.GOARCH)
versionOutput.GO = runtime.Version()
versionOutput.BuildNumber = ver.BuildNumber
Expand Down
17 changes: 10 additions & 7 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ type KotlinStepToolkitModel struct {

// StepToolkitModel ...
type StepToolkitModel struct {
Bash *BashStepToolkitModel `json:"bash,omitempty" yaml:"bash,omitempty"`
Go *GoStepToolkitModel `json:"go,omitempty" yaml:"go,omitempty"`
Swift *SwiftStepToolkitModel `json:"swift,omitempty" yaml:"swift,omitempty"`
Kotlin *KotlinStepToolkitModel `json:"kotlin,omitempty" yaml:"kotlin,omitempty"`
Bash *BashStepToolkitModel `json:"bash,omitempty" yaml:"bash,omitempty"`
Go *GoStepToolkitModel `json:"go,omitempty" yaml:"go,omitempty"`
Swift *SwiftStepToolkitModel `json:"swift,omitempty" yaml:"swift,omitempty"`
Kotlin *KotlinStepToolkitModel `json:"kotlin,omitempty" yaml:"kotlin,omitempty"`
}

// StepModel ...
Expand Down Expand Up @@ -105,9 +105,12 @@ type StepModel struct {
// steps will run which are marked with IsAlwaysRun.
IsSkippable *bool `json:"is_skippable,omitempty" yaml:"is_skippable,omitempty"`
// RunIf : only run the step if the template example evaluates to true
RunIf *string `json:"run_if,omitempty" yaml:"run_if,omitempty"`
Timeout *int `json:"timeout,omitempty" yaml:"timeout,omitempty"`
Meta map[string]interface{} `json:"meta,omitempty" yaml:"meta,omitempty"`
RunIf *string `json:"run_if,omitempty" yaml:"run_if,omitempty"`
Timeout *int `json:"timeout,omitempty" yaml:"timeout,omitempty"`
// The timeout (in seconds) until a Step with no output (stdout/stderr) is aborted
// 0 means timeout is disabled.
NoOutputTimeout *int `json:"no_output_timeout,omitempty" yaml:"no_output_timeout,omitempty"`
Meta map[string]interface{} `json:"meta,omitempty" yaml:"meta,omitempty"`
//
Inputs []envmanModels.EnvironmentItemModel `json:"inputs,omitempty" yaml:"inputs,omitempty"`
Outputs []envmanModels.EnvironmentItemModel `json:"outputs,omitempty" yaml:"outputs,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions models/models_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ func (step *StepModel) AuditBeforeShare() error {
return errors.New("Invalid step: timeout less then 0")
}

if step.NoOutputTimeout != nil && *step.NoOutputTimeout < 0 {
return errors.New("Invalid step: 'no_output_timeout' is less then 0")
}

return step.ValidateInputAndOutputEnvs(true)
}

Expand Down Expand Up @@ -230,6 +234,7 @@ func (step *StepModel) FillMissingDefaults() error {
if step.Timeout == nil {
step.Timeout = pointers.NewIntPtr(DefaultTimeout)
}
// NoOutputTimeout is left as is, so we can tell when it is nil (unset) vs set to 0 (disabled).

for _, input := range step.Inputs {
err := input.FillMissingDefaults()
Expand Down
9 changes: 7 additions & 2 deletions models/models_methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func TestValidate(t *testing.T) {
require.EqualError(t, step.Audit(), "Invalid step: missing or empty required 'source.commit' property")
step.Source.Commit = "1e1482141079fc12def64d88cb7825b8f1cb1dc3"

step.NoOutputTimeout = new(int)
*step.NoOutputTimeout = -1
require.EqualError(t, step.Audit(), "Invalid step: 'no_output_timeout' is less then 0")

step.Timeout = new(int)
*step.Timeout = -1
require.EqualError(t, step.Audit(), "Invalid step: timeout less then 0")
Expand Down Expand Up @@ -210,10 +214,8 @@ func TestValidateStepInputOutputModel(t *testing.T) {

func TestFillMissingDefaults(t *testing.T) {
title := "name 1"
// "desc 1" := ""desc 1" 1"
website := "web/1"
git := "https://git.url"
// fork := "fork/1"

step := StepModel{
Title: pointers.NewStringPtr(title),
Expand Down Expand Up @@ -252,6 +254,9 @@ func TestFillMissingDefaults(t *testing.T) {
if step.Timeout == nil || *step.Timeout != 0 {
t.Fatal("Timeout missing")
}
if step.NoOutputTimeout != nil {
t.Fatalf("No output timeout has a default value")
}
}

func TestGetStep(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package version

// VERSION ...
const VERSION = "0.13.2"
// Version is the stepman version number. It's defined at build time using -ldflags
var Version = "0.0.0-development"

0 comments on commit 6e12d27

Please sign in to comment.