Skip to content

Commit 37aaec8

Browse files
author
Ryan
authored
feat: improve list (#786)
1 parent de44a50 commit 37aaec8

File tree

3 files changed

+59
-19
lines changed

3 files changed

+59
-19
lines changed

cmd/list.go

+57-19
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,102 @@ package cmd
33
import (
44
"fmt"
55
"strconv"
6+
"strings"
67

78
"github.com/nektos/act/pkg/model"
89
)
910

1011
func printList(plan *model.Plan) error {
1112
type lineInfoDef struct {
12-
id string
13-
stage string
14-
name string
13+
jobID string
14+
jobName string
15+
stage string
16+
wfName string
17+
wfFile string
18+
events string
1519
}
1620
lineInfos := []lineInfoDef{}
1721

1822
header := lineInfoDef{
19-
id: "ID",
20-
stage: "Stage",
21-
name: "Name",
23+
jobID: "Job ID",
24+
jobName: "Job name",
25+
stage: "Stage",
26+
wfName: "Workflow name",
27+
wfFile: "Workflow file",
28+
events: "Events",
2229
}
2330

2431
jobs := map[string]bool{}
2532
duplicateJobIDs := false
2633

27-
idMaxWidth := len(header.id)
34+
jobIDMaxWidth := len(header.jobID)
35+
jobNameMaxWidth := len(header.jobName)
2836
stageMaxWidth := len(header.stage)
29-
nameMaxWidth := len(header.name)
37+
wfNameMaxWidth := len(header.wfName)
38+
wfFileMaxWidth := len(header.wfFile)
39+
eventsMaxWidth := len(header.events)
3040

3141
for i, stage := range plan.Stages {
3242
for _, r := range stage.Runs {
3343
jobID := r.JobID
3444
line := lineInfoDef{
35-
id: jobID,
36-
stage: strconv.Itoa(i),
37-
name: r.String(),
45+
jobID: jobID,
46+
jobName: r.String(),
47+
stage: strconv.Itoa(i),
48+
wfName: r.Workflow.Name,
49+
wfFile: r.Workflow.File,
50+
events: strings.Join(r.Workflow.On(), `,`),
3851
}
3952
if _, ok := jobs[jobID]; ok {
4053
duplicateJobIDs = true
4154
} else {
4255
jobs[jobID] = true
4356
}
4457
lineInfos = append(lineInfos, line)
45-
if idMaxWidth < len(line.id) {
46-
idMaxWidth = len(line.id)
58+
if jobIDMaxWidth < len(line.jobID) {
59+
jobIDMaxWidth = len(line.jobID)
60+
}
61+
if jobNameMaxWidth < len(line.jobName) {
62+
jobNameMaxWidth = len(line.jobName)
4763
}
4864
if stageMaxWidth < len(line.stage) {
4965
stageMaxWidth = len(line.stage)
5066
}
51-
if nameMaxWidth < len(line.name) {
52-
nameMaxWidth = len(line.name)
67+
if wfNameMaxWidth < len(line.wfName) {
68+
wfNameMaxWidth = len(line.wfName)
69+
}
70+
if wfFileMaxWidth < len(line.wfFile) {
71+
wfFileMaxWidth = len(line.wfFile)
72+
}
73+
if eventsMaxWidth < len(line.events) {
74+
eventsMaxWidth = len(line.events)
5375
}
5476
}
5577
}
5678

57-
idMaxWidth += 2
79+
jobIDMaxWidth += 2
80+
jobNameMaxWidth += 2
5881
stageMaxWidth += 2
59-
nameMaxWidth += 2
82+
wfNameMaxWidth += 2
83+
wfFileMaxWidth += 2
6084

61-
fmt.Printf("%*s%*s%*s\n", -idMaxWidth, header.id, -stageMaxWidth, header.stage, -nameMaxWidth, header.name)
85+
fmt.Printf("%*s%*s%*s%*s%*s%*s\n",
86+
-stageMaxWidth, header.stage,
87+
-jobIDMaxWidth, header.jobID,
88+
-jobNameMaxWidth, header.jobName,
89+
-wfNameMaxWidth, header.wfName,
90+
-wfFileMaxWidth, header.wfFile,
91+
-eventsMaxWidth, header.events,
92+
)
6293
for _, line := range lineInfos {
63-
fmt.Printf("%*s%*s%*s\n", -idMaxWidth, line.id, -stageMaxWidth, line.stage, -nameMaxWidth, line.name)
94+
fmt.Printf("%*s%*s%*s%*s%*s%*s\n",
95+
-stageMaxWidth, line.stage,
96+
-jobIDMaxWidth, line.jobID,
97+
-jobNameMaxWidth, line.jobName,
98+
-wfNameMaxWidth, line.wfName,
99+
-wfFileMaxWidth, line.wfFile,
100+
-eventsMaxWidth, line.events,
101+
)
64102
}
65103
if duplicateJobIDs {
66104
fmt.Print("\nDetected multiple jobs with the same job name, use `-W` to specify the path to the specific workflow.\n")

pkg/model/planner.go

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ func NewWorkflowPlanner(path string, noWorkflowRecurse bool) (WorkflowPlanner, e
186186
return nil, err
187187
}
188188

189+
workflow.File = wf.workflowFileInfo.Name()
189190
if workflow.Name == "" {
190191
workflow.Name = wf.workflowFileInfo.Name()
191192
}

pkg/model/workflow.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
// Workflow is the structure of the files in .github/workflows
1717
type Workflow struct {
18+
File string
1819
Name string `yaml:"name"`
1920
RawOn yaml.Node `yaml:"on"`
2021
Env map[string]string `yaml:"env"`

0 commit comments

Comments
 (0)