Skip to content

Commit

Permalink
bake: re-enable all examples
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGamba committed Jun 16, 2024
1 parent 97b0c3d commit c0a8360
Show file tree
Hide file tree
Showing 2 changed files with 145 additions and 148 deletions.
10 changes: 5 additions & 5 deletions bake/examples/website/bake/go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module bake

go 1.20
go 1.22.3

require (
github.com/DavidGamba/dgtools/buildutils v0.4.0
github.com/DavidGamba/dgtools/fsmodtime v0.2.0
github.com/DavidGamba/dgtools/run v0.9.0
github.com/DavidGamba/go-getoptions v0.30.0
github.com/DavidGamba/dgtools/buildutils v0.4.0 // indirect
github.com/DavidGamba/dgtools/fsmodtime v0.2.0 // indirect
github.com/DavidGamba/dgtools/run v0.9.0 // indirect
github.com/DavidGamba/go-getoptions v0.30.0 // indirect
)
283 changes: 140 additions & 143 deletions bake/examples/website/bake/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,70 +27,68 @@ func Build(opt *getoptions.GetOpt) getoptions.CommandFn {
}
}

// // build:go - Builds go project
// func Go(opt *getoptions.GetOpt) getoptions.CommandFn {
// return func(ctx context.Context, opt *getoptions.GetOpt, args []string) error {
// Logger.Println("Running build:go")
// root, err := buildutils.GitRepoRoot()
// if err != nil {
// return fmt.Errorf("failed to get repo root: %w", err)
// }
// err = os.Chdir(filepath.Join(root, "bake/examples/website"))
// if err != nil {
// return fmt.Errorf("failed to chdir: %w", err)
// }
//
// files, modified, err := fsmodtime.Target(os.DirFS("."), []string{"website"}, []string{"go.mod", "go.sum", "*.go"})
// if err != nil {
// return fmt.Errorf("failed to detect changes: %w", err)
// }
// if !modified {
// return nil
// }
// Logger.Printf("Modified files: %v\n", files)
//
// err = run.CMD("go", "build").Log().Run()
// if err != nil {
// return fmt.Errorf("failed to build go project: %w", err)
// }
//
// return nil
// }
// }

// // build:diagram - Builds diagram
//
// func Dot(opt *getoptions.GetOpt) getoptions.CommandFn {
// return func(ctx context.Context, opt *getoptions.GetOpt, args []string) error {
// Logger.Println("Running build:diagram")
// root, err := buildutils.GitRepoRoot()
// if err != nil {
// return fmt.Errorf("failed to get repo root: %w", err)
// }
// err = os.Chdir(filepath.Join(root, "bake/examples/website"))
// if err != nil {
// return fmt.Errorf("failed to chdir: %w", err)
// }
//
// files, modified, err := fsmodtime.Target(os.DirFS("."), []string{"public/diagram.png"}, []string{"diagram.dot"})
// if err != nil {
// return fmt.Errorf("failed to detect changes: %w", err)
// }
// if !modified {
// return nil
// }
// Logger.Printf("Modified files: %v\n", files)
//
// _ = os.MkdirAll("public", 0755)
// err = run.CMD("dot", "-Tpng", "-opublic/diagram.png", "diagram.dot").Log().Run()
// if err != nil {
// return fmt.Errorf("failed to build diagram: %w", err)
// }
//
// return nil
// }
// }
//
// build:gobuild - Builds go project
func Go(opt *getoptions.GetOpt) getoptions.CommandFn {
return func(ctx context.Context, opt *getoptions.GetOpt, args []string) error {
Logger.Println("Running build:go")
root, err := buildutils.GitRepoRoot()
if err != nil {
return fmt.Errorf("failed to get repo root: %w", err)
}
err = os.Chdir(filepath.Join(root, "bake/examples/website"))
if err != nil {
return fmt.Errorf("failed to chdir: %w", err)
}

files, modified, err := fsmodtime.Target(os.DirFS("."), []string{"website"}, []string{"go.mod", "go.sum", "*.go"})
if err != nil {
return fmt.Errorf("failed to detect changes: %w", err)
}
if !modified {
return nil
}
Logger.Printf("Modified files: %v\n", files)

err = run.CMD("go", "build").Log().Run()
if err != nil {
return fmt.Errorf("failed to build go project: %w", err)
}

return nil
}
}

// build:diagram - Builds diagram
func Dot(opt *getoptions.GetOpt) getoptions.CommandFn {
return func(ctx context.Context, opt *getoptions.GetOpt, args []string) error {
Logger.Println("Running build:diagram")
root, err := buildutils.GitRepoRoot()
if err != nil {
return fmt.Errorf("failed to get repo root: %w", err)
}
err = os.Chdir(filepath.Join(root, "bake/examples/website"))
if err != nil {
return fmt.Errorf("failed to chdir: %w", err)
}

files, modified, err := fsmodtime.Target(os.DirFS("."), []string{"public/diagram.png"}, []string{"diagram.dot"})
if err != nil {
return fmt.Errorf("failed to detect changes: %w", err)
}
if !modified {
return nil
}
Logger.Printf("Modified files: %v\n", files)

_ = os.MkdirAll("public", 0755)
err = run.CMD("dot", "-Tpng", "-opublic/diagram.png", "diagram.dot").Log().Run()
if err != nil {
return fmt.Errorf("failed to build diagram: %w", err)
}

return nil
}
}

// build:index - Builds index page
// NOTE: Run clean before changing the language since no changes will be detected.
Expand Down Expand Up @@ -137,82 +135,81 @@ func Asciidoc(opt *getoptions.GetOpt) getoptions.CommandFn {
}
}

//
// // build:all - Builds website
// func All(opt *getoptions.GetOpt) getoptions.CommandFn {
// opt.String("lang", "en", opt.ValidValues("en", "es"))
// return func(ctx context.Context, opt *getoptions.GetOpt, args []string) error {
// Logger.Println("Running build:diagram")
//
// root, err := buildutils.GitRepoRoot()
// if err != nil {
// return fmt.Errorf("failed to get repo root: %w", err)
// }
// err = os.Chdir(filepath.Join(root, "bake/examples/website"))
// if err != nil {
// return fmt.Errorf("failed to chdir: %w", err)
// }
//
// g := dag.NewGraph("website")
// g.TaskDependensOn(TM.Get("build:index"), TM.Get("build:diagram"))
// g.AddTask(TM.Get("build:go"))
//
// err = g.Validate(TM)
// if err != nil {
// return fmt.Errorf("validation: %w", err)
// }
// err = g.Run(ctx, opt, args)
// if err != nil {
// return fmt.Errorf("dag err: %w", err)
// }
//
// return nil
// }
// }
//
// // serve - Serves website on :8080
// func Serve(opt *getoptions.GetOpt) getoptions.CommandFn {
// return func(ctx context.Context, opt *getoptions.GetOpt, args []string) error {
// Logger.Println("Running serve")
// root, err := buildutils.GitRepoRoot()
// if err != nil {
// return fmt.Errorf("failed to get repo root: %w", err)
// }
// err = os.Chdir(filepath.Join(root, "bake/examples/website"))
// if err != nil {
// return fmt.Errorf("failed to chdir: %w", err)
// }
//
// err = run.CMD("./website").Ctx(ctx).Log().Run()
// if err != nil {
// return fmt.Errorf("failed to serve: %w", err)
// }
//
// return nil
// }
// }
//
// // clean - Clean build artifacts
// func Clean(opt *getoptions.GetOpt) getoptions.CommandFn {
// return func(ctx context.Context, opt *getoptions.GetOpt, args []string) error {
// Logger.Println("Running clean")
// root, err := buildutils.GitRepoRoot()
// if err != nil {
// return fmt.Errorf("failed to get repo root: %w", err)
// }
// err = os.Chdir(filepath.Join(root, "bake/examples/website"))
// if err != nil {
// return fmt.Errorf("failed to chdir: %w", err)
// }
//
// _ = os.RemoveAll("public")
// _ = os.Remove("website")
//
// return nil
// }
// }
//
// // notused - Not used because it doesn't return a getoptions.CommandFn
// func NotUsed() error {
// return nil
// }
// build:all - Builds website
func All(opt *getoptions.GetOpt) getoptions.CommandFn {
opt.String("lang", "en", opt.ValidValues("en", "es"))
return func(ctx context.Context, opt *getoptions.GetOpt, args []string) error {
Logger.Println("Running build:all")

root, err := buildutils.GitRepoRoot()
if err != nil {
return fmt.Errorf("failed to get repo root: %w", err)
}
err = os.Chdir(filepath.Join(root, "bake/examples/website"))
if err != nil {
return fmt.Errorf("failed to chdir: %w", err)
}

g := dag.NewGraph("website")
g.TaskDependensOn(TM.Get("build:index"), TM.Get("build:diagram"))
g.AddTask(TM.Get("build:gobuild"))

err = g.Validate(TM)
if err != nil {
return fmt.Errorf("validation: %w", err)
}
err = g.Run(ctx, opt, args)
if err != nil {
return fmt.Errorf("dag err: %w", err)
}

return nil
}
}

// serve - Serves website on :8080
func Serve(opt *getoptions.GetOpt) getoptions.CommandFn {
return func(ctx context.Context, opt *getoptions.GetOpt, args []string) error {
Logger.Println("Running serve")
root, err := buildutils.GitRepoRoot()
if err != nil {
return fmt.Errorf("failed to get repo root: %w", err)
}
err = os.Chdir(filepath.Join(root, "bake/examples/website"))
if err != nil {
return fmt.Errorf("failed to chdir: %w", err)
}

err = run.CMD("./website").Ctx(ctx).Log().Run()
if err != nil {
return fmt.Errorf("failed to serve: %w", err)
}

return nil
}
}

// clean - Clean build artifacts
func Clean(opt *getoptions.GetOpt) getoptions.CommandFn {
return func(ctx context.Context, opt *getoptions.GetOpt, args []string) error {
Logger.Println("Running clean")
root, err := buildutils.GitRepoRoot()
if err != nil {
return fmt.Errorf("failed to get repo root: %w", err)
}
err = os.Chdir(filepath.Join(root, "bake/examples/website"))
if err != nil {
return fmt.Errorf("failed to chdir: %w", err)
}

_ = os.RemoveAll("public")
_ = os.Remove("website")

return nil
}
}

// notused - Not used because it doesn't return a getoptions.CommandFn
func NotUsed() error {
return nil
}

0 comments on commit c0a8360

Please sign in to comment.