Skip to content

Commit d0fb591

Browse files
committed
fix: gobake project info
1 parent 6d16292 commit d0fb591

File tree

4 files changed

+68
-16
lines changed

4 files changed

+68
-16
lines changed

public/projects/gobake/details.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ go install github.com/fezcode/gobake/cmd/gobake@latest
2626

2727
### Commands
2828

29-
* `gobake init`: Scaffolds a new `Recipe.go` and `recipe.piml`. Handles `go.mod` and dependencies.
30-
* `gobake version`: Displays the current version of gobake.
31-
* `gobake help`: Displays the list of commands and available tasks.
32-
* `gobake bump [patch|minor|major]`: Increments the version in `recipe.piml`.
29+
* **`gobake init`**: Scaffolds a new `Recipe.go` and `recipe.piml`. Handles `go.mod` and dependencies.
30+
* **`gobake version`**: Displays the current version of gobake.
31+
* **`gobake help`**: Displays the list of commands and available tasks.
32+
* **`gobake bump [patch|minor|major]`**: Increments the version in `recipe.piml`.
33+
* **`gobake template <git-url>`**: Initialize from a remote repository template.
3334

3435
### The `Recipe.go` File
3536

@@ -47,7 +48,11 @@ func Run(bake *gobake.Engine) error {
4748
return fmt.Errorf("error loading recipe.piml: %v", err)
4849
}
4950

50-
bake.Task("build", "Builds the binary", func(ctx *gobake.Context) error {
51+
bake.Task("test", "Runs project tests", func(ctx *gobake.Context) error {
52+
return ctx.Run("go", "test", "./...")
53+
})
54+
55+
bake.TaskWithDeps("build", "Builds the binary", []string{"test"}, func(ctx *gobake.Context) error {
5156
return ctx.BakeBinary("linux", "amd64", "bin/app")
5257
})
5358

public/projects/gobake/examples.txt

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import (
1414
)
1515

1616
func Run(bake *gobake.Engine) error {
17-
bake.LoadRecipeInfo("recipe.piml")
17+
if err := bake.LoadRecipeInfo("recipe.piml"); err != nil {
18+
return err
19+
}
1820

1921
bake.Task("release", "Build for all platforms", func(ctx *gobake.Context) error {
2022
platforms := []struct {
@@ -59,10 +61,15 @@ This recipe installs `stringer` and uses it to generate code before building.
5961
//go:build gobake
6062
package bake_recipe
6163

62-
import "github.com/fezcode/gobake"
64+
import (
65+
"fmt"
66+
"github.com/fezcode/gobake"
67+
)
6368

6469
func Run(bake *gobake.Engine) error {
65-
bake.LoadRecipeInfo("recipe.piml")
70+
if err := bake.LoadRecipeInfo("recipe.piml"); err != nil {
71+
return fmt.Errorf("error loading recipe.piml: %v", err)
72+
}
6673

6774
bake.Task("generate", "Generates code", func(ctx *gobake.Context) error {
6875
// Ensure tools are installed first
@@ -80,3 +87,33 @@ func Run(bake *gobake.Engine) error {
8087
return nil
8188
}
8289
```
90+
91+
## 3. Injecting Version with ldflags
92+
93+
Inject project version from `recipe.piml` into your binary.
94+
95+
**Recipe.go:**
96+
```go
97+
//go:build gobake
98+
package bake_recipe
99+
100+
import (
101+
"fmt"
102+
"github.com/fezcode/gobake"
103+
)
104+
105+
func Run(bake *gobake.Engine) error {
106+
if err := bake.LoadRecipeInfo("recipe.piml"); err != nil {
107+
return err
108+
}
109+
110+
bake.Task("build", "Build with version", func(ctx *gobake.Context) error {
111+
ldflags := fmt.Sprintf("-X main.Version=%s", bake.Info.Version)
112+
113+
ctx.Log("Building version %s...", bake.Info.Version)
114+
return ctx.Run("go", "build", "-ldflags", ldflags, "-o", "bin/app")
115+
})
116+
117+
return nil
118+
}
119+
```

public/projects/gobake/guide.txt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
`gobake` operates on a simple principle: **Your build system should be as robust as your application.**
44

55
Instead of relying on fragile shell scripts or complex Makefiles, `gobake` uses:
6-
1. **Engine:** The core Go library that manages tasks.
7-
2. **Context:** A helper object passed to every task, providing access to the shell, logging, and metadata.
6+
1. **Engine:** The core Go library that manages tasks and metadata.
7+
2. **Context:** A helper object passed to every task, providing access to the shell, logging, and environment.
88
3. **Recipe:** The `Recipe.go` file (using `//go:build gobake`) that ties it all together.
99

1010
# CLI Command Reference
1111

1212
## Project Management
1313

14-
* **`gobake init`**: Initialize a new project in the current directory. Automates `go mod` and dependencies.
14+
* **`gobake init`**: Initialize a new project in the current directory. Automates `go mod` and dependency setup.
1515
* **`gobake version`**: Show the current version of gobake.
1616
* **`gobake help`**: Show the list of available commands and project tasks.
17-
* **`gobake template <git-url>`**: Clone a repository and initialize it.
17+
* **`gobake template <git-url>`**: Clone a repository and initialize it as a gobake project.
1818

1919
## Dependency & Tool Management
2020

2121
* **`gobake add-tool <url>`**: Adds a tool to the `(tools)` list in `recipe.piml`.
22-
* **`gobake add-dep <url>`**: Adds a library dependency to `go.mod`.
2322
* **`gobake remove-tool <url>`**: Removes a tool from `recipe.piml`.
24-
* **`gobake remove-dep <url>`**: Removes a dependency.
23+
* **`gobake add-dep <url>`**: Adds a library dependency using `go get`.
24+
* **`gobake remove-dep <url>`**: Removes a library dependency.
2525

2626
## Versioning
2727

@@ -35,7 +35,7 @@ The `recipe.piml` file is the single source of truth for your project.
3535
(name) my-project
3636
(version) 1.2.3
3737
(authors)
38-
> Ahmed <ahmed@example.com>
38+
> Fezcode
3939
(tools)
4040
> github.com/swaggo/swag/cmd/swag@latest
4141
```
@@ -52,3 +52,13 @@ You can define tasks that depend on other tasks using `bake.TaskWithDeps`.
5252
bake.Task("test", "Run tests", func(ctx *gobake.Context) error { ... })
5353
bake.TaskWithDeps("build", "Build app", []string{"test"}, func(ctx *gobake.Context) error { ... })
5454
```
55+
56+
## Cross-Compilation
57+
58+
Use `ctx.BakeBinary(os, arch, output, flags...)` for simple cross-compilation tasks.
59+
60+
```go
61+
bake.Task("release", "Cross-compile", func(ctx *gobake.Context) error {
62+
return ctx.BakeBinary("linux", "amd64", "bin/app")
63+
})
64+
```

public/projects/gobake/terminal.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ btnLink: #installation
99
:::card
1010
type: code
1111
title: Define Recipe
12-
code: bake.Task("build", "Build app", func(ctx) { return ctx.Bake("bin/app") })
12+
code: bake.Task("build", "Build app", func(ctx *gobake.Context) error { return ctx.BakeBinary("linux", "amd64", "bin/app") })
1313
btnText: GUIDE!
1414
btnLink: #docs
1515
:::

0 commit comments

Comments
 (0)