auto adjust code

This commit is contained in:
Christopher Homberger
2026-02-22 20:58:46 +01:00
parent 949a40c7a5
commit d187ac2fc1
86 changed files with 617 additions and 617 deletions

View File

@@ -12,7 +12,7 @@ import (
// ActionRunsUsing is the type of runner for the action
type ActionRunsUsing string
func (a *ActionRunsUsing) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (a *ActionRunsUsing) UnmarshalYAML(unmarshal func(any) error) error {
var using string
if err := unmarshal(&using); err != nil {
return err

View File

@@ -10,39 +10,39 @@ import (
)
type GithubContext struct {
Event map[string]interface{} `json:"event"`
EventPath string `json:"event_path"`
Workflow string `json:"workflow"`
RunAttempt string `json:"run_attempt"`
RunID string `json:"run_id"`
RunNumber string `json:"run_number"`
Actor string `json:"actor"`
Repository string `json:"repository"`
EventName string `json:"event_name"`
Sha string `json:"sha"`
Ref string `json:"ref"`
RefName string `json:"ref_name"`
RefType string `json:"ref_type"`
HeadRef string `json:"head_ref"`
BaseRef string `json:"base_ref"`
Token string `json:"token"`
Workspace string `json:"workspace"`
Action string `json:"action"`
ActionPath string `json:"action_path"`
ActionRef string `json:"action_ref"`
ActionRepository string `json:"action_repository"`
Job string `json:"job"`
JobName string `json:"job_name"`
RepositoryOwner string `json:"repository_owner"`
RetentionDays string `json:"retention_days"`
RunnerPerflog string `json:"runner_perflog"`
RunnerTrackingID string `json:"runner_tracking_id"`
ServerURL string `json:"server_url"`
APIURL string `json:"api_url"`
GraphQLURL string `json:"graphql_url"`
Event map[string]any `json:"event"`
EventPath string `json:"event_path"`
Workflow string `json:"workflow"`
RunAttempt string `json:"run_attempt"`
RunID string `json:"run_id"`
RunNumber string `json:"run_number"`
Actor string `json:"actor"`
Repository string `json:"repository"`
EventName string `json:"event_name"`
Sha string `json:"sha"`
Ref string `json:"ref"`
RefName string `json:"ref_name"`
RefType string `json:"ref_type"`
HeadRef string `json:"head_ref"`
BaseRef string `json:"base_ref"`
Token string `json:"token"`
Workspace string `json:"workspace"`
Action string `json:"action"`
ActionPath string `json:"action_path"`
ActionRef string `json:"action_ref"`
ActionRepository string `json:"action_repository"`
Job string `json:"job"`
JobName string `json:"job_name"`
RepositoryOwner string `json:"repository_owner"`
RetentionDays string `json:"retention_days"`
RunnerPerflog string `json:"runner_perflog"`
RunnerTrackingID string `json:"runner_tracking_id"`
ServerURL string `json:"server_url"`
APIURL string `json:"api_url"`
GraphQLURL string `json:"graphql_url"`
}
func asString(v interface{}) string {
func asString(v any) string {
if v == nil {
return ""
} else if s, ok := v.(string); ok {
@@ -51,7 +51,7 @@ func asString(v interface{}) string {
return ""
}
func nestedMapLookup(m map[string]interface{}, ks ...string) (rval interface{}) {
func nestedMapLookup(m map[string]any, ks ...string) (rval any) {
var ok bool
if len(ks) == 0 { // degenerate input
@@ -61,20 +61,20 @@ func nestedMapLookup(m map[string]interface{}, ks ...string) (rval interface{})
return nil
} else if len(ks) == 1 { // we've reached the final key
return rval
} else if m, ok = rval.(map[string]interface{}); !ok {
} else if m, ok = rval.(map[string]any); !ok {
return nil
}
// 1+ more keys
return nestedMapLookup(m, ks[1:]...)
}
func withDefaultBranch(ctx context.Context, b string, event map[string]interface{}) map[string]interface{} {
func withDefaultBranch(ctx context.Context, b string, event map[string]any) map[string]any {
repoI, ok := event["repository"]
if !ok {
repoI = make(map[string]interface{})
repoI = make(map[string]any)
}
repo, ok := repoI.(map[string]interface{})
repo, ok := repoI.(map[string]any)
if !ok {
common.Logger(ctx).Warnf("unable to set default branch to %v", b)
return event
@@ -101,19 +101,19 @@ func (ghc *GithubContext) SetRef(ctx context.Context, defaultBranch string, repo
// https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads
switch ghc.EventName {
case "pull_request_target":
ghc.Ref = fmt.Sprintf("refs/heads/%s", ghc.BaseRef)
ghc.Ref = "refs/heads/" + ghc.BaseRef
case "pull_request", "pull_request_review", "pull_request_review_comment":
ghc.Ref = fmt.Sprintf("refs/pull/%.0f/merge", ghc.Event["number"])
case "deployment", "deployment_status":
ghc.Ref = asString(nestedMapLookup(ghc.Event, "deployment", "ref"))
case "release":
ghc.Ref = fmt.Sprintf("refs/tags/%s", asString(nestedMapLookup(ghc.Event, "release", "tag_name")))
ghc.Ref = "refs/tags/" + asString(nestedMapLookup(ghc.Event, "release", "tag_name"))
case "push", "create", "workflow_dispatch":
ghc.Ref = asString(ghc.Event["ref"])
default:
defaultBranch := asString(nestedMapLookup(ghc.Event, "repository", "default_branch"))
if defaultBranch != "" {
ghc.Ref = fmt.Sprintf("refs/heads/%s", defaultBranch)
ghc.Ref = "refs/heads/" + defaultBranch
}
}
@@ -134,7 +134,7 @@ func (ghc *GithubContext) SetRef(ctx context.Context, defaultBranch string, repo
}
if ghc.Ref == "" {
ghc.Ref = fmt.Sprintf("refs/heads/%s", asString(nestedMapLookup(ghc.Event, "repository", "default_branch")))
ghc.Ref = "refs/heads/" + asString(nestedMapLookup(ghc.Event, "repository", "default_branch"))
}
}
}

View File

@@ -2,7 +2,7 @@ package model
import (
"context"
"fmt"
"errors"
"testing"
log "github.com/sirupsen/logrus"
@@ -27,19 +27,19 @@ func TestSetRef(t *testing.T) {
tables := []struct {
eventName string
event map[string]interface{}
event map[string]any
ref string
refName string
}{
{
eventName: "pull_request_target",
event: map[string]interface{}{},
event: map[string]any{},
ref: "refs/heads/master",
refName: "master",
},
{
eventName: "pull_request",
event: map[string]interface{}{
event: map[string]any{
"number": 1234.,
},
ref: "refs/pull/1234/merge",
@@ -47,8 +47,8 @@ func TestSetRef(t *testing.T) {
},
{
eventName: "deployment",
event: map[string]interface{}{
"deployment": map[string]interface{}{
event: map[string]any{
"deployment": map[string]any{
"ref": "refs/heads/somebranch",
},
},
@@ -57,8 +57,8 @@ func TestSetRef(t *testing.T) {
},
{
eventName: "release",
event: map[string]interface{}{
"release": map[string]interface{}{
event: map[string]any{
"release": map[string]any{
"tag_name": "v1.0.0",
},
},
@@ -67,7 +67,7 @@ func TestSetRef(t *testing.T) {
},
{
eventName: "push",
event: map[string]interface{}{
event: map[string]any{
"ref": "refs/heads/somebranch",
},
ref: "refs/heads/somebranch",
@@ -75,8 +75,8 @@ func TestSetRef(t *testing.T) {
},
{
eventName: "unknown",
event: map[string]interface{}{
"repository": map[string]interface{}{
event: map[string]any{
"repository": map[string]any{
"default_branch": "main",
},
},
@@ -85,7 +85,7 @@ func TestSetRef(t *testing.T) {
},
{
eventName: "no-event",
event: map[string]interface{}{},
event: map[string]any{},
ref: "refs/heads/master",
refName: "master",
},
@@ -109,12 +109,12 @@ func TestSetRef(t *testing.T) {
t.Run("no-default-branch", func(t *testing.T) {
findGitRef = func(_ context.Context, _ string) (string, error) {
return "", fmt.Errorf("no default branch")
return "", errors.New("no default branch")
}
ghc := &GithubContext{
EventName: "no-default-branch",
Event: map[string]interface{}{},
Event: map[string]any{},
}
ghc.SetRef(context.Background(), "", "/some/dir")
@@ -141,14 +141,14 @@ func TestSetSha(t *testing.T) {
tables := []struct {
eventName string
event map[string]interface{}
event map[string]any
sha string
}{
{
eventName: "pull_request_target",
event: map[string]interface{}{
"pull_request": map[string]interface{}{
"base": map[string]interface{}{
event: map[string]any{
"pull_request": map[string]any{
"base": map[string]any{
"sha": "pr-base-sha",
},
},
@@ -157,15 +157,15 @@ func TestSetSha(t *testing.T) {
},
{
eventName: "pull_request",
event: map[string]interface{}{
event: map[string]any{
"number": 1234.,
},
sha: "1234fakesha",
},
{
eventName: "deployment",
event: map[string]interface{}{
"deployment": map[string]interface{}{
event: map[string]any{
"deployment": map[string]any{
"sha": "deployment-sha",
},
},
@@ -173,12 +173,12 @@ func TestSetSha(t *testing.T) {
},
{
eventName: "release",
event: map[string]interface{}{},
event: map[string]any{},
sha: "1234fakesha",
},
{
eventName: "push",
event: map[string]interface{}{
event: map[string]any{
"after": "push-sha",
"deleted": false,
},
@@ -186,12 +186,12 @@ func TestSetSha(t *testing.T) {
},
{
eventName: "unknown",
event: map[string]interface{}{},
event: map[string]any{},
sha: "1234fakesha",
},
{
eventName: "no-event",
event: map[string]interface{}{},
event: map[string]any{},
sha: "1234fakesha",
},
}

View File

@@ -8,7 +8,7 @@ import (
"os"
"path/filepath"
"regexp"
"sort"
"slices"
log "github.com/sirupsen/logrus"
)
@@ -288,11 +288,8 @@ func (wp *workflowPlanner) GetEvents() []string {
for _, w := range wp.workflows {
found := false
for _, e := range events {
for _, we := range w.On() {
if e == we {
found = true
break
}
if slices.Contains(w.On(), e) {
found = true
}
if found {
break
@@ -305,9 +302,7 @@ func (wp *workflowPlanner) GetEvents() []string {
}
// sort the list based on depth of dependencies
sort.Slice(events, func(i, j int) bool {
return events[i] < events[j]
})
slices.Sort(events)
return events
}
@@ -338,7 +333,7 @@ func (s *Stage) GetJobIDs() []string {
// Merge stages with existing stages in plan
func (p *Plan) mergeStages(stages []*Stage) {
newStages := make([]*Stage, int(math.Max(float64(len(p.Stages)), float64(len(stages)))))
for i := 0; i < len(newStages); i++ {
for i := range newStages {
newStages[i] = new(Stage)
if i >= len(p.Stages) {
newStages[i].Runs = append(newStages[i].Runs, stages[i].Runs...)

View File

@@ -55,6 +55,6 @@ func TestWorkflow(t *testing.T) {
// Check that a valid job id returns non-error
result, err := createStages(&workflow, "valid_job")
assert.Nil(t, err)
assert.NoError(t, err)
assert.NotNil(t, result)
}

View File

@@ -4,8 +4,10 @@ import (
"errors"
"fmt"
"io"
"maps"
"reflect"
"regexp"
"slices"
"strconv"
"strings"
@@ -61,7 +63,7 @@ func (w *Workflow) On() []string {
}
return val
case yaml.MappingNode:
var val map[string]interface{}
var val map[string]any
err := w.RawOn.Decode(&val)
if err != nil {
log.Fatal(err)
@@ -75,9 +77,9 @@ func (w *Workflow) On() []string {
return nil
}
func (w *Workflow) OnEvent(event string) interface{} {
func (w *Workflow) OnEvent(event string) any {
if w.RawOn.Kind == yaml.MappingNode {
var val map[string]interface{}
var val map[string]any
if !decodeNode(w.RawOn, &val) {
return nil
}
@@ -128,10 +130,8 @@ func (w *Workflow) WorkflowDispatchConfig() *WorkflowDispatch {
if !decodeNode(w.RawOn, &val) {
return nil
}
for _, v := range val {
if v == "workflow_dispatch" {
return &WorkflowDispatch{}
}
if slices.Contains(val, "workflow_dispatch") {
return &WorkflowDispatch{}
}
case yaml.MappingNode:
var val map[string]yaml.Node
@@ -206,7 +206,7 @@ type Job struct {
Defaults Defaults `yaml:"defaults"`
Outputs map[string]string `yaml:"outputs"`
Uses string `yaml:"uses"`
With map[string]interface{} `yaml:"with"`
With map[string]any `yaml:"with"`
RawSecrets yaml.Node `yaml:"secrets"`
Result string
}
@@ -384,9 +384,9 @@ func (j *Job) Environment() map[string]string {
}
// Matrix decodes RawMatrix YAML node
func (j *Job) Matrix() map[string][]interface{} {
func (j *Job) Matrix() map[string][]any {
if j.Strategy.RawMatrix.Kind == yaml.MappingNode {
var val map[string][]interface{}
var val map[string][]any
if !decodeNode(j.Strategy.RawMatrix, &val) {
return nil
}
@@ -397,32 +397,32 @@ func (j *Job) Matrix() map[string][]interface{} {
// GetMatrixes returns the matrix cross product
// It skips includes and hard fails excludes for non-existing keys
func (j *Job) GetMatrixes() ([]map[string]interface{}, error) {
matrixes := make([]map[string]interface{}, 0)
func (j *Job) GetMatrixes() ([]map[string]any, error) {
matrixes := make([]map[string]any, 0)
if j.Strategy != nil {
j.Strategy.FailFast = j.Strategy.GetFailFast()
j.Strategy.MaxParallel = j.Strategy.GetMaxParallel()
if m := j.Matrix(); m != nil {
includes := make([]map[string]interface{}, 0)
extraIncludes := make([]map[string]interface{}, 0)
includes := make([]map[string]any, 0)
extraIncludes := make([]map[string]any, 0)
for _, v := range m["include"] {
switch t := v.(type) {
case []interface{}:
case []any:
for _, i := range t {
i := i.(map[string]interface{})
i := i.(map[string]any)
includes = append(includes, i)
}
case interface{}:
v := v.(map[string]interface{})
case any:
v := v.(map[string]any)
includes = append(includes, v)
}
}
delete(m, "include")
excludes := make([]map[string]interface{}, 0)
excludes := make([]map[string]any, 0)
for _, e := range m["exclude"] {
e := e.(map[string]interface{})
e := e.(map[string]any)
for k := range e {
if _, ok := m[k]; ok {
excludes = append(excludes, e)
@@ -451,9 +451,7 @@ func (j *Job) GetMatrixes() ([]map[string]interface{}, error) {
if commonKeysMatch2(matrix, include, m) {
matched = true
log.Debugf("Adding include values '%v' to existing entry", include)
for k, v := range include {
matrix[k] = v
}
maps.Copy(matrix, include)
}
}
if !matched {
@@ -465,19 +463,19 @@ func (j *Job) GetMatrixes() ([]map[string]interface{}, error) {
matrixes = append(matrixes, include)
}
if len(matrixes) == 0 {
matrixes = append(matrixes, make(map[string]interface{}))
matrixes = append(matrixes, make(map[string]any))
}
} else {
matrixes = append(matrixes, make(map[string]interface{}))
matrixes = append(matrixes, make(map[string]any))
}
} else {
matrixes = append(matrixes, make(map[string]interface{}))
matrixes = append(matrixes, make(map[string]any))
log.Debugf("Empty Strategy, matrixes=%v", matrixes)
}
return matrixes, nil
}
func commonKeysMatch(a map[string]interface{}, b map[string]interface{}) bool {
func commonKeysMatch(a map[string]any, b map[string]any) bool {
for aKey, aVal := range a {
if bVal, ok := b[aKey]; ok && !reflect.DeepEqual(aVal, bVal) {
return false
@@ -486,7 +484,7 @@ func commonKeysMatch(a map[string]interface{}, b map[string]interface{}) bool {
return true
}
func commonKeysMatch2(a map[string]interface{}, b map[string]interface{}, m map[string][]interface{}) bool {
func commonKeysMatch2(a map[string]any, b map[string]any, m map[string][]any) bool {
for aKey, aVal := range a {
_, useKey := m[aKey]
if bVal, ok := b[aKey]; useKey && ok && !reflect.DeepEqual(aVal, bVal) {
@@ -604,7 +602,7 @@ func (s *Step) GetEnv() map[string]string {
for k, v := range s.With {
envKey := regexp.MustCompile("[^A-Z0-9-]").ReplaceAllString(strings.ToUpper(k), "_")
envKey = fmt.Sprintf("INPUT_%s", strings.ToUpper(envKey))
envKey = "INPUT_" + strings.ToUpper(envKey)
env[envKey] = v
}
return env
@@ -752,11 +750,11 @@ func (w *Workflow) GetJobIDs() []string {
return ids
}
var OnDecodeNodeError = func(node yaml.Node, out interface{}, err error) {
var OnDecodeNodeError = func(node yaml.Node, out any, err error) {
log.Fatalf("Failed to decode node %v into %T: %v", node, out, err)
}
func decodeNode(node yaml.Node, out interface{}) bool {
func decodeNode(node yaml.Node, out any) bool {
if err := node.Decode(out); err != nil {
if OnDecodeNodeError != nil {
OnDecodeNodeError(node, out, err)

View File

@@ -87,7 +87,7 @@ jobs:
workflow, err := ReadWorkflow(strings.NewReader(yaml), WorkflowConfig{})
assert.NoError(t, err, "read workflow should succeed")
assert.Equal(t, workflow.Jobs["test"].RunsOn(), []string{"ubuntu-latest"})
assert.Equal(t, []string{"ubuntu-latest"}, workflow.Jobs["test"].RunsOn())
}
func TestReadWorkflow_RunsOnLabelsWithGroup(t *testing.T) {
@@ -105,7 +105,7 @@ jobs:
workflow, err := ReadWorkflow(strings.NewReader(yaml), WorkflowConfig{})
assert.NoError(t, err, "read workflow should succeed")
assert.Equal(t, workflow.Jobs["test"].RunsOn(), []string{"ubuntu-latest", "linux"})
assert.Equal(t, []string{"ubuntu-latest", "linux"}, workflow.Jobs["test"].RunsOn())
}
func TestReadWorkflow_StringContainer(t *testing.T) {
@@ -201,27 +201,27 @@ jobs:
assert.Len(t, workflow.Jobs, 6)
jobType, err := workflow.Jobs["default-job"].Type()
assert.Equal(t, nil, err)
assert.NoError(t, err)
assert.Equal(t, JobTypeDefault, jobType)
jobType, err = workflow.Jobs["remote-reusable-workflow-yml"].Type()
assert.Equal(t, nil, err)
assert.NoError(t, err)
assert.Equal(t, JobTypeReusableWorkflowRemote, jobType)
jobType, err = workflow.Jobs["remote-reusable-workflow-yaml"].Type()
assert.Equal(t, nil, err)
assert.NoError(t, err)
assert.Equal(t, JobTypeReusableWorkflowRemote, jobType)
jobType, err = workflow.Jobs["remote-reusable-workflow-custom-path"].Type()
assert.Equal(t, nil, err)
assert.NoError(t, err)
assert.Equal(t, JobTypeReusableWorkflowRemote, jobType)
jobType, err = workflow.Jobs["local-reusable-workflow-yml"].Type()
assert.Equal(t, nil, err)
assert.NoError(t, err)
assert.Equal(t, JobTypeReusableWorkflowLocal, jobType)
jobType, err = workflow.Jobs["local-reusable-workflow-yaml"].Type()
assert.Equal(t, nil, err)
assert.NoError(t, err)
assert.Equal(t, JobTypeReusableWorkflowLocal, jobType)
}
@@ -246,19 +246,19 @@ jobs:
jobType, err := workflow.Jobs["remote-reusable-workflow-missing-version"].Type()
assert.Equal(t, JobTypeInvalid, jobType)
assert.NotEqual(t, nil, err)
assert.Error(t, err)
jobType, err = workflow.Jobs["remote-reusable-workflow-bad-extension"].Type()
assert.Equal(t, JobTypeInvalid, jobType)
assert.NotEqual(t, nil, err)
assert.Error(t, err)
jobType, err = workflow.Jobs["local-reusable-workflow-bad-extension"].Type()
assert.Equal(t, JobTypeInvalid, jobType)
assert.NotEqual(t, nil, err)
assert.Error(t, err)
jobType, err = workflow.Jobs["local-reusable-workflow-bad-path"].Type()
assert.Equal(t, JobTypeInvalid, jobType)
assert.NotEqual(t, nil, err)
assert.Error(t, err)
}
func TestReadWorkflow_StepsTypes(t *testing.T) {
@@ -335,71 +335,69 @@ func TestReadWorkflow_Strategy(t *testing.T) {
p, err := w.PlanJob("strategy-only-max-parallel")
assert.NoError(t, err)
assert.Equal(t, len(p.Stages), 1)
assert.Equal(t, len(p.Stages[0].Runs), 1)
assert.Len(t, p.Stages, 1)
assert.Len(t, p.Stages[0].Runs, 1)
wf := p.Stages[0].Runs[0].Workflow
job := wf.Jobs["strategy-only-max-parallel"]
matrixes, err := job.GetMatrixes()
assert.NoError(t, err)
assert.Equal(t, matrixes, []map[string]interface{}{{}})
assert.Equal(t, job.Matrix(), map[string][]interface{}(nil))
assert.Equal(t, job.Strategy.MaxParallel, 2)
assert.Equal(t, job.Strategy.FailFast, true)
assert.Equal(t, []map[string]any{{}}, matrixes)
assert.Equal(t, job.Matrix(), map[string][]any(nil))
assert.Equal(t, 2, job.Strategy.MaxParallel)
assert.True(t, job.Strategy.FailFast)
job = wf.Jobs["strategy-only-fail-fast"]
matrixes, err = job.GetMatrixes()
assert.NoError(t, err)
assert.Equal(t, matrixes, []map[string]interface{}{{}})
assert.Equal(t, job.Matrix(), map[string][]interface{}(nil))
assert.Equal(t, job.Strategy.MaxParallel, 4)
assert.Equal(t, job.Strategy.FailFast, false)
assert.Equal(t, []map[string]any{{}}, matrixes)
assert.Equal(t, job.Matrix(), map[string][]any(nil))
assert.Equal(t, 4, job.Strategy.MaxParallel)
assert.False(t, job.Strategy.FailFast)
job = wf.Jobs["strategy-no-matrix"]
matrixes, err = job.GetMatrixes()
assert.NoError(t, err)
assert.Equal(t, matrixes, []map[string]interface{}{{}})
assert.Equal(t, job.Matrix(), map[string][]interface{}(nil))
assert.Equal(t, job.Strategy.MaxParallel, 2)
assert.Equal(t, job.Strategy.FailFast, false)
assert.Equal(t, []map[string]any{{}}, matrixes)
assert.Equal(t, job.Matrix(), map[string][]any(nil))
assert.Equal(t, 2, job.Strategy.MaxParallel)
assert.False(t, job.Strategy.FailFast)
job = wf.Jobs["strategy-all"]
matrixes, err = job.GetMatrixes()
assert.NoError(t, err)
assert.Equal(t, matrixes,
[]map[string]interface{}{
{"datacenter": "site-c", "node-version": "14.x", "site": "staging", "php-version": 5.4},
{"datacenter": "site-c", "node-version": "16.x", "site": "staging", "php-version": 5.4},
{"datacenter": "site-d", "node-version": "16.x", "site": "staging", "php-version": 5.4},
{"datacenter": "site-a", "node-version": "10.x", "site": "prod"},
{"datacenter": "site-b", "node-version": "12.x", "site": "dev"},
},
assert.Equal(t, []map[string]any{
{"datacenter": "site-c", "node-version": "14.x", "site": "staging", "php-version": 5.4},
{"datacenter": "site-c", "node-version": "16.x", "site": "staging", "php-version": 5.4},
{"datacenter": "site-d", "node-version": "16.x", "site": "staging", "php-version": 5.4},
{"datacenter": "site-a", "node-version": "10.x", "site": "prod"},
{"datacenter": "site-b", "node-version": "12.x", "site": "dev"},
}, matrixes,
)
assert.Equal(t, job.Matrix(),
map[string][]interface{}{
"datacenter": {"site-c", "site-d"},
"exclude": {
map[string]interface{}{"datacenter": "site-d", "node-version": "14.x", "site": "staging"},
},
"include": {
map[string]interface{}{"php-version": 5.4},
map[string]interface{}{"datacenter": "site-a", "node-version": "10.x", "site": "prod"},
map[string]interface{}{"datacenter": "site-b", "node-version": "12.x", "site": "dev"},
},
"node-version": {"14.x", "16.x"},
"site": {"staging"},
assert.Equal(t, map[string][]any{
"datacenter": {"site-c", "site-d"},
"exclude": {
map[string]any{"datacenter": "site-d", "node-version": "14.x", "site": "staging"},
},
"include": {
map[string]any{"php-version": 5.4},
map[string]any{"datacenter": "site-a", "node-version": "10.x", "site": "prod"},
map[string]any{"datacenter": "site-b", "node-version": "12.x", "site": "dev"},
},
"node-version": {"14.x", "16.x"},
"site": {"staging"},
}, job.Matrix(),
)
assert.Equal(t, job.Strategy.MaxParallel, 2)
assert.Equal(t, job.Strategy.FailFast, false)
assert.Equal(t, 2, job.Strategy.MaxParallel)
assert.False(t, job.Strategy.FailFast)
}
func TestMatrixOnlyIncludes(t *testing.T) {
matrix := map[string][]interface{}{
"include": []interface{}{
map[string]interface{}{"a": "1", "b": "2"},
map[string]interface{}{"a": "3", "b": "4"},
matrix := map[string][]any{
"include": []any{
map[string]any{"a": "1", "b": "2"},
map[string]any{"a": "3", "b": "4"},
},
}
rN := yaml.Node{}
@@ -413,11 +411,10 @@ func TestMatrixOnlyIncludes(t *testing.T) {
assert.Equal(t, job.Matrix(), matrix)
matrixes, err := job.GetMatrixes()
require.NoError(t, err)
assert.Equal(t, matrixes,
[]map[string]interface{}{
{"a": "1", "b": "2"},
{"a": "3", "b": "4"},
},
assert.Equal(t, []map[string]any{
{"a": "1", "b": "2"},
{"a": "3", "b": "4"},
}, matrixes,
)
}
@@ -436,7 +433,7 @@ func TestStep_ShellCommand(t *testing.T) {
for _, tt := range tests {
t.Run(tt.shell, func(t *testing.T) {
got := (&Step{Shell: tt.shell, WorkflowShell: tt.workflowShell}).ShellCommand()
assert.Equal(t, got, tt.want)
assert.Equal(t, tt.want, got)
})
}
}