Skip to content

Commit

Permalink
chore: adds blueprint field and makes path optional
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgilman committed Sep 16, 2024
1 parent 56819d2 commit f16fc70
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
7 changes: 7 additions & 0 deletions blueprint.cue
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
version: "1.0"
global: {
ci: {
local: [
"^check.*$",
"^build.*$",
"^test.*$",
"^release.*$",
"^publish.*$",
]
registries: [
ci.providers.aws.registry,
]
Expand Down
3 changes: 3 additions & 0 deletions blueprint/schema/_embed/schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ package schema

// CI contains the configuration for the CI system.
#GlobalCI: {
// Local defines the filters to use when simulating a local CI run.
local: [...string] @go(Local,[]string)

// Providers contains the configuration for the providers being used by the CI system.
// +optional
providers?: #Providers @go(Providers)
Expand Down
3 changes: 3 additions & 0 deletions blueprint/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ type Project struct {

// CI contains the configuration for the CI system.
type GlobalCI struct {
// Local defines the filters to use when simulating a local CI run.
Local []string `json:"local"`

// Providers contains the configuration for the providers being used by the CI system.
// +optional
Providers Providers `json:"providers"`
Expand Down
3 changes: 3 additions & 0 deletions blueprint/schema/schema_go_gen.cue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ package schema

// CI contains the configuration for the CI system.
#GlobalCI: {
// Local defines the filters to use when simulating a local CI run.
local: [...string] @go(Local,[]string)

// Providers contains the configuration for the providers being used by the CI system.
// +optional
providers?: #Providers @go(Providers)
Expand Down
5 changes: 2 additions & 3 deletions forge/cli/cmd/cmds/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type CICmd struct {
Artifact string `short:"a" help:"Dump all produced artifacts to the given path."`
Path string `arg:"" help:"The path to scan from."`
Path string `arg:"" default:"" help:"The path to scan from."`
Platform []string `short:"p" help:"Run the target with the given platform."`
}

Expand All @@ -18,6 +18,5 @@ func (c *CICmd) Run(logger *slog.Logger, global GlobalArgs) error {
Platform: c.Platform,
}
opts := generateOpts(&flags, &global)
filters := []string{"^check.*$", "^build.*$", "^test.*$"}
return ci.Run(c.Path, filters, global.Local, opts...)
return ci.Run(c.Path, global.Local, opts...)
}
44 changes: 39 additions & 5 deletions forge/cli/tui/ci/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package ci
import (
"fmt"
"log/slog"
"os"
"path/filepath"
"strings"

"github.com/charmbracelet/bubbles/spinner"
Expand All @@ -11,6 +13,8 @@ import (
"github.com/input-output-hk/catalyst-forge/forge/cli/pkg/earthly"
"github.com/input-output-hk/catalyst-forge/forge/cli/pkg/project"
"github.com/input-output-hk/catalyst-forge/forge/cli/tui"
"github.com/input-output-hk/catalyst-forge/tools/pkg/git"
"github.com/input-output-hk/catalyst-forge/tools/pkg/walker"
)

var (
Expand Down Expand Up @@ -100,7 +104,6 @@ func (a App) line() string {

// Run starts the TUI application.
func Run(scanPath string,
filters []string,
local bool,
opts ...earthly.EarthlyExecutorOption,
) error {
Expand All @@ -117,17 +120,42 @@ func Run(scanPath string,
logger,
)

if scanPath == "" {
scanPath, err = findRoot(".", logger)
if err != nil {
return fmt.Errorf("failed to find root of git repository: %w", err)
}

cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("failed to get current working directory: %w", err)
}

scanPath, err = filepath.Rel(cwd, scanPath)
if err != nil {
return fmt.Errorf("failed to get relative path: %w", err)
}
}

project, err := loader.Load(scanPath)
if err != nil {
return fmt.Errorf("failed to load project: %w", err)
}
if len(project.Blueprint.Global.CI.Local) <= 0 {
return fmt.Errorf("no local CI filters found in project")
}

ci := CI{
filters: filters,
filters: project.Blueprint.Global.CI.Local,
loader: &loader,
logger: logger,
options: opts,
scanPath: scanPath,
}

logger.Info("Loading project")
logger.Info("Loading CI")
if err := ci.Load(); err != nil {
return err
return fmt.Errorf("failed to load CI: %w", err)
}

app := App{
Expand All @@ -138,8 +166,14 @@ func Run(scanPath string,
logger.Info("Starting program")
p := tea.NewProgram(app)
if _, err := p.Run(); err != nil {
return err
return fmt.Errorf("failed to run program: %w", err)
}

return nil
}

// findRoot finds the root of a git repository.
func findRoot(scanPath string, logger *slog.Logger) (string, error) {
rw := walker.NewDefaultFSReverseWalker(logger)
return git.FindGitRoot(scanPath, &rw)
}

0 comments on commit f16fc70

Please sign in to comment.