Merge branch 'master' into update-dependencies
This commit is contained in:
commit
0f8657b1c2
|
@ -68,6 +68,7 @@ Any setting (with the exception of `prefix`; [see below](#user-content-using-the
|
||||||
|
|
||||||
* Booleans can be yaml's `true` and `false` literals or the strings `"true"` and `"false"`.
|
* Booleans can be yaml's `true` and `false` literals or the strings `"true"` and `"false"`.
|
||||||
* Durations are strings formatted with the syntax accepted by [golang's ParseDuration function](https://golang.org/pkg/time/#ParseDuration) (e.g. 5m30s)
|
* Durations are strings formatted with the syntax accepted by [golang's ParseDuration function](https://golang.org/pkg/time/#ParseDuration) (e.g. 5m30s)
|
||||||
|
* For backward-compatibility with drone-helm, a duration can also be an integer, in which case it will be interpreted to mean seconds.
|
||||||
* List\<string\>s can be a yaml sequence or a comma-separated string.
|
* List\<string\>s can be a yaml sequence or a comma-separated string.
|
||||||
|
|
||||||
All of the following are equivalent:
|
All of the following are equivalent:
|
||||||
|
|
|
@ -4,8 +4,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/kelseyhightower/envconfig"
|
"github.com/kelseyhightower/envconfig"
|
||||||
"io"
|
"io"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var justNumbers = regexp.MustCompile(`^\d+$`)
|
||||||
|
|
||||||
// The Config struct captures the `settings` and `environment` blocks in the application's drone
|
// The Config struct captures the `settings` and `environment` blocks in the application's drone
|
||||||
// config. Configuration in drone's `settings` block arrives as uppercase env vars matching the
|
// config. Configuration in drone's `settings` block arrives as uppercase env vars matching the
|
||||||
// config key, prefixed with `PLUGIN_`. Config from the `environment` block is uppercased, but does
|
// config key, prefixed with `PLUGIN_`. Config from the `environment` block is uppercased, but does
|
||||||
|
@ -62,6 +65,10 @@ func NewConfig(stdout, stderr io.Writer) (*Config, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if justNumbers.MatchString(cfg.Timeout) {
|
||||||
|
cfg.Timeout = fmt.Sprintf("%ss", cfg.Timeout)
|
||||||
|
}
|
||||||
|
|
||||||
if cfg.Debug && cfg.Stderr != nil {
|
if cfg.Debug && cfg.Stderr != nil {
|
||||||
cfg.logDebug()
|
cfg.logDebug()
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,13 @@ func (suite *ConfigTestSuite) TestNewConfigWithConflictingVariables() {
|
||||||
suite.Equal("2m30s", cfg.Timeout)
|
suite.Equal("2m30s", cfg.Timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *ConfigTestSuite) TestNewConfigInfersNumbersAreSeconds() {
|
||||||
|
suite.setenv("PLUGIN_TIMEOUT", "42")
|
||||||
|
cfg, err := NewConfig(&strings.Builder{}, &strings.Builder{})
|
||||||
|
suite.Require().NoError(err)
|
||||||
|
suite.Equal("42s", cfg.Timeout)
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *ConfigTestSuite) TestNewConfigSetsWriters() {
|
func (suite *ConfigTestSuite) TestNewConfigSetsWriters() {
|
||||||
stdout := &strings.Builder{}
|
stdout := &strings.Builder{}
|
||||||
stderr := &strings.Builder{}
|
stderr := &strings.Builder{}
|
||||||
|
|
Loading…
Reference in a new issue