Skip to content

Commit

Permalink
Simpler list view (RasaHQ#382)
Browse files Browse the repository at this point in the history
* Simpler list view

* lint

* readding graph viz with -g/--graph

Co-authored-by: Leonid Shamis <[email protected]>
Co-authored-by: Casey Lee <[email protected]>
  • Loading branch information
3 people authored Oct 12, 2020
1 parent 014d71a commit 644bc2b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on: [push, pull_request]

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -13,6 +14,7 @@ jobs:
CGO_ENABLED: 0

test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -24,6 +26,7 @@ jobs:
CGO_ENABLED: 0

snapshot:
name: Snapshot
if: ${{ github.event_name == 'pull_request' }}
needs:
- lint
Expand All @@ -40,6 +43,7 @@ jobs:
SNAPSHOT_VERSION: "v0.0.0"

release:
name: Release
if: startsWith(github.ref, 'refs/tags/v')
needs:
- lint
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:

jobs:
stale:
name: Stale
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v3
Expand Down
57 changes: 57 additions & 0 deletions cmd/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cmd

import (
"fmt"
"strconv"

"github.com/nektos/act/pkg/model"
)

func printList(plan *model.Plan) error {
type lineInfoDef struct {
id string
stage string
name string
}
lineInfos := []lineInfoDef{}

header := lineInfoDef{
id: "ID",
stage: "Stage",
name: "Name",
}

idMaxWidth := len(header.id)
stageMaxWidth := len(header.stage)
nameMaxWidth := len(header.name)

for i, stage := range plan.Stages {
for _, r := range stage.Runs {
line := lineInfoDef{
id: r.JobID,
stage: strconv.Itoa(i),
name: r.String(),
}
lineInfos = append(lineInfos, line)
if idMaxWidth < len(line.id) {
idMaxWidth = len(line.id)
}
if stageMaxWidth < len(line.stage) {
stageMaxWidth = len(line.stage)
}
if nameMaxWidth < len(line.name) {
nameMaxWidth = len(line.name)
}
}
}

idMaxWidth += 2
stageMaxWidth += 2
nameMaxWidth += 2

fmt.Printf("%*s%*s%*s\n", -idMaxWidth, header.id, -stageMaxWidth, header.stage, -nameMaxWidth, header.name)
for _, line := range lineInfos {
fmt.Printf("%*s%*s%*s\n", -idMaxWidth, line.id, -stageMaxWidth, line.stage, -nameMaxWidth, line.name)
}
return nil
}
10 changes: 9 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func Execute(ctx context.Context, version string) {
}
rootCmd.Flags().BoolP("watch", "w", false, "watch the contents of the local repo and run when files change")
rootCmd.Flags().BoolP("list", "l", false, "list workflows")
rootCmd.Flags().BoolP("graph", "g", false, "draw workflows")
rootCmd.Flags().StringP("job", "j", "", "run job")
rootCmd.Flags().StringArrayVarP(&input.secrets, "secret", "s", []string{}, "secret to make available to actions with optional value (e.g. -s mysecret=foo or -s mysecret)")
rootCmd.Flags().StringArrayVarP(&input.platforms, "platform", "P", []string{}, "custom image to use per platform (e.g. -P ubuntu-18.04=nektos/act-environments-ubuntu:18.04)")
Expand Down Expand Up @@ -150,9 +151,16 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
plan = planner.PlanEvent(eventName)
}

// check if we should just print the graph
// check if we should just list the workflows
if list, err := cmd.Flags().GetBool("list"); err != nil {
return err
} else if list {
return printList(plan)
}

// check if we should just print the graph
if list, err := cmd.Flags().GetBool("graph"); err != nil {
return err
} else if list {
return drawGraph(plan)
}
Expand Down

0 comments on commit 644bc2b

Please sign in to comment.