-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SUP-1453 Allow local directory config override for default pipeline (#…
…213) * SUP-1453 Allow local directory config override for default pipeline
- Loading branch information
Showing
8 changed files
with
152 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package pipelines | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/buildkite/cli/v3/pkg/cmd/factory" | ||
) | ||
|
||
func ResolveFromConfig(f *factory.Factory) ([]string, error) { | ||
|
||
var localPipelines []string | ||
// check if there is a local config file | ||
err := f.LocalConfig.Read() | ||
if err != nil { | ||
fmt.Printf("Error reading local config: %s", err) | ||
return nil, err | ||
} | ||
// if there is a pipeline defined in the local config, return it | ||
if len(f.LocalConfig.Pipeline) > 0 { | ||
//assume pipelines are comma separated - final format TBD | ||
localPipelines = strings.Split(f.LocalConfig.Pipeline, ",") | ||
} | ||
return localPipelines, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package pipelines | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/buildkite/cli/v3/internal/config" | ||
"github.com/buildkite/cli/v3/pkg/cmd/factory" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func TestResolvePipelineFromConfig(t *testing.T) { | ||
|
||
t.Run("local config does not exist", func(t *testing.T) { | ||
f := factory.Factory{ | ||
LocalConfig: &config.LocalConfig{}, | ||
} | ||
|
||
pipelines, _ := ResolveFromConfig(&f) | ||
if len(pipelines) > 0 { | ||
t.Errorf("Expected empty string, got %d pipelines: %v", len(pipelines), pipelines) | ||
} | ||
}) | ||
|
||
t.Run("local config exists but no pipeline defined", func(t *testing.T) { | ||
f := factory.Factory{ | ||
LocalConfig: &config.LocalConfig{}, | ||
} | ||
|
||
f.LocalConfig.Pipeline = "" | ||
pipelines, _ := ResolveFromConfig(&f) | ||
if len(pipelines) > 0 { | ||
t.Errorf("Expected empty string, got %d pipelines: %v", len(pipelines), pipelines) | ||
} | ||
|
||
}) | ||
|
||
t.Run("local config exists and a pipeline is defined", func(t *testing.T) { | ||
f := factory.Factory{ | ||
LocalConfig: &config.LocalConfig{}, | ||
} | ||
|
||
newLocalConfig := make(map[string]interface{}) | ||
newLocalConfig["pipeline"] = "new-sample-pipeline" | ||
newData, err := yaml.Marshal(&newLocalConfig) | ||
if err != nil { | ||
t.Errorf("Error: %s", err) | ||
} | ||
|
||
err = os.WriteFile(".bk.yaml", newData, 0o644) | ||
if err != nil { | ||
t.Errorf("Error: %s", err) | ||
} | ||
|
||
pipelines, _ := ResolveFromConfig(&f) | ||
if len(pipelines) > 0 && pipelines[0] != newLocalConfig["pipeline"] { | ||
t.Errorf("Expected %s, got %s", newLocalConfig["pipeline"], pipelines[0]) | ||
} | ||
os.Remove(".bk.yaml") | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters