fix: fail workflow if the job name is invalid (#596)

This commit is contained in:
hackercat
2021-04-02 16:01:45 +02:00
committed by GitHub
parent 5044ec6c43
commit 94d736a602
4 changed files with 56 additions and 0 deletions

View File

@@ -1,11 +1,13 @@
package model
import (
"fmt"
"io"
"io/ioutil"
"math"
"os"
"path/filepath"
"regexp"
"sort"
"github.com/pkg/errors"
@@ -92,6 +94,12 @@ func NewWorkflowPlanner(path string) (WorkflowPlanner, error) {
if workflow.Name == "" {
workflow.Name = file.Name()
}
jobNameRegex := regexp.MustCompile(`^([[:alpha:]_][[:alnum:]_\-]*)$`)
for k := range workflow.Jobs {
if ok := jobNameRegex.MatchString(k); !ok {
return nil, fmt.Errorf("The workflow is not valid. %s: Job name %s is invalid. Names must start with a letter or '_' and contain only alphanumeric characters, '-', or '_'", workflow.Name, k)
}
}
wp.workflows = append(wp.workflows, workflow)
f.Close()
}