* Potentially solved merge conflict * Update pkg/model/planner.go Based on feedback Co-authored-by: Ryan (hackercat) <me@hackerc.at> * Fixed compilation error * added missed test * Fixed spelling error to work with lint error Co-authored-by: Ryan (hackercat) <me@hackerc.at> Co-authored-by: Casey Lee <cplee@nektos.com>
This commit is contained in:
@@ -50,6 +50,40 @@ func (r *Run) Job() *Job {
|
||||
return r.Workflow.GetJob(r.JobID)
|
||||
}
|
||||
|
||||
// Helper function for FixIfstatement
|
||||
func FixIfStatement1(val string, lines [][][]byte, l int) (string, error) {
|
||||
if val != "" {
|
||||
line := lines[l-1][0]
|
||||
outcome := regexp.MustCompile(`\s+if:\s+".*".*`).FindSubmatch(line)
|
||||
if outcome != nil {
|
||||
oldLines := regexp.MustCompile(`"(.*?)"`).FindAllSubmatch(line, 2)
|
||||
val = "${{" + string(oldLines[0][1]) + "}}"
|
||||
}
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
|
||||
// Fixes faulty if statements from decoder
|
||||
func FixIfStatement(content []byte, wr *Workflow) error {
|
||||
jobs := wr.Jobs
|
||||
lines := regexp.MustCompile(".*\n|.+$").FindAllSubmatch(content, -1)
|
||||
for j := range jobs {
|
||||
val, err := FixIfStatement1(jobs[j].If.Value, lines, jobs[j].If.Line)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jobs[j].If.Value = val
|
||||
for i := range jobs[j].Steps {
|
||||
val, err = FixIfStatement1(jobs[j].Steps[i].If.Value, lines, jobs[j].Steps[i].If.Line)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jobs[j].Steps[i].If.Value = val
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type WorkflowFiles struct {
|
||||
workflowFileInfo os.FileInfo
|
||||
dirPath string
|
||||
@@ -135,6 +169,21 @@ func NewWorkflowPlanner(path string, noWorkflowRecurse bool) (WorkflowPlanner, e
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_, err = f.Seek(0, 0)
|
||||
if err != nil {
|
||||
f.Close()
|
||||
return nil, errors.WithMessagef(err, "error occurring when resetting io pointer, %s", wf.workflowFileInfo.Name())
|
||||
}
|
||||
log.Debugf("Correcting if statements '%s'", f.Name())
|
||||
content, err := ioutil.ReadFile(filepath.Join(wf.dirPath, wf.workflowFileInfo.Name()))
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "error occurring when reading file, %s", wf.workflowFileInfo.Name())
|
||||
}
|
||||
|
||||
err = FixIfStatement(content, workflow)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if workflow.Name == "" {
|
||||
workflow.Name = wf.workflowFileInfo.Name()
|
||||
|
@@ -59,7 +59,7 @@ type Job struct {
|
||||
RawNeeds yaml.Node `yaml:"needs"`
|
||||
RawRunsOn yaml.Node `yaml:"runs-on"`
|
||||
Env map[string]string `yaml:"env"`
|
||||
If string `yaml:"if"`
|
||||
If yaml.Node `yaml:"if"`
|
||||
Steps []*Step `yaml:"steps"`
|
||||
TimeoutMinutes int64 `yaml:"timeout-minutes"`
|
||||
Services map[string]*ContainerSpec `yaml:"services"`
|
||||
@@ -211,7 +211,7 @@ type ContainerSpec struct {
|
||||
// Step is the structure of one step in a job
|
||||
type Step struct {
|
||||
ID string `yaml:"id"`
|
||||
If string `yaml:"if"`
|
||||
If yaml.Node `yaml:"if"`
|
||||
Name string `yaml:"name"`
|
||||
Uses string `yaml:"uses"`
|
||||
Run string `yaml:"run"`
|
||||
|
Reference in New Issue
Block a user