Skip to content

Commit

Permalink
Merge pull request #18 from vincenthsh/fix-autocomplete-ignore-non-ac…
Browse files Browse the repository at this point in the history
…tion

fix: Autocomplete fatal error on non-action libraries
  • Loading branch information
vincenthsh authored Jun 19, 2024
2 parents 2f28cfa + 4d1e9ce commit d479e59
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var Command = &cobra.Command{

logger.Info("collecting actions")

actions, err := ws.CollectActions()
actions, err := ws.CollectActions(true)
if err != nil {
logger.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/checkversions/checkversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var Command = &cobra.Command{
})
logger.Info("collecting actions")

actions, err := ws.CollectActions()
actions, err := ws.CollectActions(true)
if err != nil {
logger.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var Command = &cobra.Command{

logger.Info("collecting actions")

actions, err := ws.CollectActions()
actions, err := ws.CollectActions(true)
if err != nil {
logger.Fatal(err)
}
Expand Down
62 changes: 62 additions & 0 deletions cmd/list/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package list

import (
"time"

"github.com/jedib0t/go-pretty/v6/text"
"github.com/spf13/cobra"

"github.com/gravitational/gamma/internal/logger"
"github.com/gravitational/gamma/internal/utils"
"github.com/gravitational/gamma/internal/workspace"
)

var workingDirectory string
var workspaceManifest string

var Command = &cobra.Command{
Use: "list",
Short: "List all the actions in the monorepo",
Long: `List all the actions in the monorepo.`,
Run: func(_ *cobra.Command, _ []string) {
started := time.Now()

workingDirectory = utils.FetchWorkingDirectory(workingDirectory)

nd, err := utils.NormalizeDirectories(workingDirectory)
if err != nil {
logger.Fatal(err)
}

ws := workspace.New(workspace.Properties{
WorkingDirectory: nd[0],
WorkspaceManifest: workspaceManifest,
})

logger.Info("collecting actions")

actions, err := ws.CollectActions(true)
if err != nil {
logger.Fatal(err)
}

if len(actions) == 0 {
logger.Fatal("could not find any actions")
}

logger.Info("found actions:")
for _, action := range actions {
logger.Infof(" ✅ %s (%s/%s)", action.Name(), action.Owner(), action.RepoName())
}

took := time.Since(started)

bold := text.Colors{text.FgWhite, text.Bold}
logger.Success(bold.Sprintf("done in %.2fs", took.Seconds()))
},
}

func init() {
Command.Flags().StringVarP(&workingDirectory, "directory", "d", "the current working directory", "directory containing the monorepo of actions")
Command.Flags().StringVarP(&workspaceManifest, "workspace", "w", "gamma-workspace.yml", "workspace manifest for non-javascript actions")
}
7 changes: 6 additions & 1 deletion cmd/merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package merge

import (
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -51,6 +52,10 @@ func init() {
Command.Flags().StringVarP(&workingDirectory, "directory", "d", "the current working directory", "directory containing the monorepo of actions")
Command.Flags().StringVarP(&workspaceManifest, "workspace", "w", "gamma-workspace.yml", "workspace manifest for non-javascript actions")

if _, err := os.Stat(workspaceManifest); os.IsNotExist(err) {
return
}

workingDirectory = utils.FetchWorkingDirectory(workingDirectory)
wdArr, err := utils.NormalizeDirectories(workingDirectory)
if err != nil {
Expand All @@ -61,7 +66,7 @@ func init() {
WorkspaceManifest: workspaceManifest,
})

actions, err := ws.CollectActions()
actions, err := ws.CollectActions(false)
if err != nil {
logger.Fatal(err)
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/gravitational/gamma/cmd/build"
"github.com/gravitational/gamma/cmd/checkversions"
"github.com/gravitational/gamma/cmd/deploy"
"github.com/gravitational/gamma/cmd/list"
"github.com/gravitational/gamma/cmd/merge"
"github.com/gravitational/gamma/internal/color"
)
Expand Down Expand Up @@ -34,6 +35,7 @@ func init() {
cobra.AddTemplateFunc("logo", logo)

rootCmd.AddCommand(build.Command)
rootCmd.AddCommand(list.Command)
rootCmd.AddCommand(checkversions.Command)
rootCmd.AddCommand(merge.Command)
rootCmd.AddCommand(deploy.Command)
Expand Down Expand Up @@ -80,6 +82,8 @@ func colorize(s, name string) string {
switch s {
case build.Command.Name():
return color.Magenta(name)
case list.Command.Name():
return color.Purple(name)
case checkversions.Command.Name():
return color.Purple(name)
case deploy.Command.Name():
Expand All @@ -99,6 +103,8 @@ func emoji(s string) string {
switch s {
case build.Command.Name():
return "🔧"
case list.Command.Name():
return "🔍"
case checkversions.Command.Name():
return "🔍"
case deploy.Command.Name():
Expand Down
11 changes: 8 additions & 3 deletions internal/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"path"

"github.com/gravitational/gamma/internal/action"
"github.com/gravitational/gamma/internal/logger"
"github.com/gravitational/gamma/internal/node"
"github.com/gravitational/gamma/pkg/schema"
"gopkg.in/yaml.v3"
)

type Workspace interface {
CollectActions() ([]action.Action, error)
CollectActions(verbose bool) ([]action.Action, error)
}

type workspace struct {
Expand Down Expand Up @@ -44,7 +45,7 @@ func New(props Properties) Workspace {
}
}

func (w *workspace) CollectActions() ([]action.Action, error) {
func (w *workspace) CollectActions(verbose bool) ([]action.Action, error) {
// TODO: don't error if rootPackage doesn't exist
rootPackage, err := w.readRootPackage()
if err != nil {
Expand All @@ -69,7 +70,11 @@ func (w *workspace) CollectActions() ([]action.Action, error) {

action, err := action.New(config)
if err != nil {
return nil, err
if verbose {
logger.Warningf("Skipping action %s: %v\n", ws.Name, err)
}
// return nil, err
continue
}

actions = append(actions, action)
Expand Down

0 comments on commit d479e59

Please sign in to comment.