Skip to content

Commit

Permalink
chore: merge branch 'master' into releases
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgilman committed Oct 28, 2024
2 parents b636247 + ef39ba0 commit b9e9586
Show file tree
Hide file tree
Showing 39 changed files with 1,246 additions and 330 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Deploy
uses: input-output-hk/catalyst-forge/actions/run@ci/v1.2.2
with:
command: deploy
command: deploy push
args: ${{ matrix.deployment }}
local: ${{ inputs.local }}
verbosity: ${{ inputs.verbosity }}
Expand Down
7 changes: 7 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
VERSION 0.8

# This target exists solely for validating the root Earthfile is scanned
test:
FROM ubuntu:latest

RUN echo "Testing"
2 changes: 1 addition & 1 deletion actions/run/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion actions/run/dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion actions/run/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function run() {
forgeArgs.push("--local");
}

forgeArgs.push(command);
forgeArgs.push(...command.split(" "));

if (args !== "") {
forgeArgs.push(...args.split(" "));
Expand Down
2 changes: 1 addition & 1 deletion blueprint.cue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ global: {
"^test(-.*)?$",
]
registries: [
ci.providers.aws.registry,
"ghcr.io/input-output-hk/catalyst-forge",
]
providers: {
aws: {
Expand Down
6 changes: 6 additions & 0 deletions cli/cmd/cmds/deploy/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package deploy

type DeployCmd struct {
Push PushCmd `cmd:"" help:"Pushes a project deployment to the GitOps repo."`
Template TemplateCmd `cmd:"" help:"Generates a project's deployment YAML."`
}
6 changes: 3 additions & 3 deletions cli/cmd/cmds/deploy.go → cli/cmd/cmds/deploy/deploy.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmds
package deploy

import (
"fmt"
Expand All @@ -7,11 +7,11 @@ import (
"github.com/input-output-hk/catalyst-forge/cli/pkg/run"
)

type DeployCmd struct {
type PushCmd struct {
Project string `arg:"" help:"The path to the project to deploy." kong:"arg,predictor=path"`
}

func (c *DeployCmd) Run(ctx run.RunContext) error {
func (c *PushCmd) Run(ctx run.RunContext) error {
project, err := ctx.ProjectLoader.Load(c.Project)
if err != nil {
return fmt.Errorf("could not load project: %w", err)
Expand Down
38 changes: 38 additions & 0 deletions cli/cmd/cmds/deploy/template.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package deploy

import (
"fmt"

"github.com/input-output-hk/catalyst-forge/cli/pkg/deployment"
"github.com/input-output-hk/catalyst-forge/cli/pkg/run"
)

type TemplateCmd struct {
Project string `arg:"" help:"The path to the project." kong:"arg,predictor=path"`
}

func (c *TemplateCmd) Run(ctx run.RunContext) error {
project, err := ctx.ProjectLoader.Load(c.Project)
if err != nil {
return fmt.Errorf("could not load project: %w", err)
}

bundle, err := deployment.GenerateBundle(&project)
if err != nil {
return fmt.Errorf("could not generate bundle: %w", err)
}

templater, err := deployment.NewDefaultBundleTemplater(ctx.Logger)
if err != nil {
return fmt.Errorf("could not create bundle templater: %w", err)
}

out, err := templater.Render(bundle)
if err != nil {
return fmt.Errorf("could not render bundle: %w", err)
}

fmt.Println(out)

return nil
}
28 changes: 28 additions & 0 deletions cli/cmd/cmds/run.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmds

import (
"github.com/input-output-hk/catalyst-forge/cli/pkg/earthly"
"github.com/input-output-hk/catalyst-forge/cli/pkg/run"
"github.com/input-output-hk/catalyst-forge/lib/tools/earthfile"
)
Expand Down Expand Up @@ -35,3 +36,30 @@ func (c *RunCmd) Run(ctx run.RunContext) error {

return nil
}

// generateOpts generates the options for the Earthly executor based on command
// flags.
func generateOpts(flags *RunCmd, ctx run.RunContext) []earthly.EarthlyExecutorOption {
var opts []earthly.EarthlyExecutorOption

if flags != nil {
if flags.Artifact != "" {
opts = append(opts, earthly.WithArtifact(flags.Artifact))
}

if ctx.CI {
opts = append(opts, earthly.WithCI())
}

// Users can explicitly set the platforms to use without being in CI mode.
if flags.Platform != nil {
opts = append(opts, earthly.WithPlatforms(flags.Platform...))
}

if len(flags.TargetArgs) > 0 && flags.TargetArgs[0] != "" {
opts = append(opts, earthly.WithTargetArgs(flags.TargetArgs...))
}
}

return opts
}
27 changes: 20 additions & 7 deletions cli/cmd/cmds/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"cuelang.org/go/cue"
"github.com/input-output-hk/catalyst-forge/cli/pkg/run"
"github.com/input-output-hk/catalyst-forge/cli/pkg/scan"
"github.com/input-output-hk/catalyst-forge/cli/pkg/utils"
"golang.org/x/exp/maps"
)

Expand Down Expand Up @@ -55,14 +56,14 @@ func (c *ScanCmd) Run(ctx run.RunContext) error {
}
}

printJson(result, c.Pretty)
utils.PrintJson(result, c.Pretty)
case c.Blueprint:
result := make(map[string]cue.Value)
for path, project := range projects {
result[path] = project.Raw().Value()
}

printJson(result, c.Pretty)
utils.PrintJson(result, c.Pretty)
case c.Earthfile && len(c.Filter) > 0:
result := make(map[string]map[string][]string)
for _, filter := range c.Filter {
Expand Down Expand Up @@ -97,9 +98,9 @@ func (c *ScanCmd) Run(ctx run.RunContext) error {
sort.Strings(enumerated[filter])
}

printJson(enumerated, c.Pretty)
utils.PrintJson(enumerated, c.Pretty)
} else {
printJson(result, c.Pretty)
utils.PrintJson(result, c.Pretty)
}
case c.Earthfile:
result := make(map[string][]string)
Expand All @@ -112,15 +113,27 @@ func (c *ScanCmd) Run(ctx run.RunContext) error {
if ctx.CI {
enumerated := enumerate(result)
sort.Strings(enumerated)
printJson(enumerated, c.Pretty)
utils.PrintJson(enumerated, c.Pretty)
} else {
printJson(result, c.Pretty)
utils.PrintJson(result, c.Pretty)
}
default:
keys := maps.Keys(projects)
sort.Strings(keys)
printJson(keys, c.Pretty)
utils.PrintJson(keys, c.Pretty)
}

return nil
}

// enumerate enumerates the Earthfile+Target pairs from the target map.
func enumerate(data map[string][]string) []string {
var result []string
for path, targets := range data {
for _, target := range targets {
result = append(result, fmt.Sprintf("%s+%s", path, target))
}
}

return result
}
3 changes: 2 additions & 1 deletion cli/cmd/cmds/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/input-output-hk/catalyst-forge/cli/pkg/run"
"github.com/input-output-hk/catalyst-forge/cli/pkg/utils"
"github.com/input-output-hk/catalyst-forge/lib/project/schema"
"github.com/input-output-hk/catalyst-forge/lib/project/secrets"
)
Expand Down Expand Up @@ -99,7 +100,7 @@ func (c *Get) Run(ctx run.RunContext) error {
fmt.Println(mappedSecret[c.Key])
return nil
} else {
printJson(mappedSecret, false)
utils.PrintJson(mappedSecret, false)
return nil
}
}
Expand Down
73 changes: 0 additions & 73 deletions cli/cmd/cmds/util.go

This file was deleted.

29 changes: 18 additions & 11 deletions cli/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/alecthomas/kong"
"github.com/charmbracelet/log"
"github.com/input-output-hk/catalyst-forge/cli/cmd/cmds"
"github.com/input-output-hk/catalyst-forge/cli/cmd/cmds/deploy"
"github.com/input-output-hk/catalyst-forge/cli/pkg/run"
"github.com/input-output-hk/catalyst-forge/lib/project/project"
"github.com/input-output-hk/catalyst-forge/lib/project/schema"
Expand All @@ -21,18 +22,24 @@ import (

var version = "dev"

type GlobalArgs struct {
CI bool `help:"Run in CI mode."`
Local bool `short:"l" help:"Forces all runs to happen locally (ignores any remote satellites)."`
Verbose int `short:"v" type:"counter" help:"Enable verbose logging."`
}

var cli struct {
cmds.GlobalArgs

Deploy cmds.DeployCmd `kong:"cmd" help:"Deploy a project."`
Dump cmds.DumpCmd `kong:"cmd" help:"Dumps a project's blueprint to JSON."`
CI cmds.CICmd `kong:"cmd" help:"Simulate a CI run."`
Release cmds.ReleaseCmd `kong:"cmd" help:"Release a project."`
Run cmds.RunCmd `kong:"cmd" help:"Run an Earthly target."`
Scan cmds.ScanCmd `kong:"cmd" help:"Scan for Earthfiles."`
Secret cmds.SecretCmd `kong:"cmd" help:"Manage secrets."`
Validate cmds.ValidateCmd `kong:"cmd" help:"Validates a project."`
Version VersionCmd `kong:"cmd" help:"Print the version."`
GlobalArgs

Deploy deploy.DeployCmd `kong:"cmd" help:"Deploy a project."`
Dump cmds.DumpCmd `cmd:"" help:"Dumps a project's blueprint to JSON."`
CI cmds.CICmd `cmd:"" help:"Simulate a CI run."`
Release cmds.ReleaseCmd `cmd:"" help:"Release a project."`
Run cmds.RunCmd `cmd:"" help:"Run an Earthly target."`
Scan cmds.ScanCmd `cmd:"" help:"Scan for Earthfiles."`
Secret cmds.SecretCmd `cmd:"" help:"Manage secrets."`
Validate cmds.ValidateCmd `cmd:"" help:"Validates a project."`
Version VersionCmd `cmd:"" help:"Print the version."`

InstallCompletions kongplete.InstallCompletions `cmd:"" help:"install shell completions"`
}
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/testdata/scan/3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ exec forge --ci scan --earthfile .
cmp stdout golden_ci.txt

-- golden.txt --
{"./dir1":["foo","bar"],"./dir1/dir2":["foo","bar"],"./dir3/dir4/dir5":["foo"]}
{".":["foo","bar"],"./dir1":["foo","bar"],"./dir1/dir2":["foo","bar"],"./dir3/dir4/dir5":["foo"]}
-- golden_ci.txt --
["./dir1+bar","./dir1+foo","./dir1/dir2+bar","./dir1/dir2+foo","./dir3/dir4/dir5+foo"]
[".+bar",".+foo","./dir1+bar","./dir1+foo","./dir1/dir2+bar","./dir1/dir2+foo","./dir3/dir4/dir5+foo"]
-- blueprint.cue --
version: "1.0"
-- Earthfile --
Expand Down
Loading

0 comments on commit b9e9586

Please sign in to comment.