| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
|
| 6 |
"go.einride.tech/sage/sg" |
| 7 |
"go.einride.tech/sage/sgtool" |
| 8 |
"go.einride.tech/sage/tools/sgconvco" |
| 9 |
"go.einride.tech/sage/tools/sggit" |
| 10 |
"go.einride.tech/sage/tools/sggo" |
| 11 |
"go.einride.tech/sage/tools/sggolangcilint" |
| 12 |
"go.einride.tech/sage/tools/sggolines" |
| 13 |
"go.einride.tech/sage/tools/sggosemanticrelease" |
| 14 |
"go.einride.tech/sage/tools/sgmdformat" |
| 15 |
"go.einride.tech/sage/tools/sgyamlfmt" |
| 16 |
) |
| 17 |
|
| 18 |
func main() { |
| 19 |
sg.GenerateMakefiles( |
| 20 |
sg.Makefile{ |
| 21 |
Path: sg.FromGitRoot("Makefile"), |
| 22 |
DefaultTarget: All, |
| 23 |
}, |
| 24 |
sg.Makefile{ |
| 25 |
Path: sg.FromGitRoot("proto/Makefile"), |
| 26 |
DefaultTarget: Proto.All, |
| 27 |
Namespace: Proto{}, |
| 28 |
}, |
| 29 |
) |
| 30 |
} |
| 31 |
|
| 32 |
func All(ctx context.Context) error { |
| 33 |
sg.Deps(ctx, ConvcoCheck, FormatMarkdown, FormatYAML, GoGenerate, Proto.All) |
| 34 |
sg.Deps(ctx, GoLint, GoTest) |
| 35 |
sg.SerialDeps(ctx, GoModTidy, GitVerifyNoDiff) |
| 36 |
return nil |
| 37 |
} |
| 38 |
|
| 39 |
func ConvcoCheck(ctx context.Context) error { |
| 40 |
sg.Logger(ctx).Println("checking git commits...") |
| 41 |
return sgconvco.Command(ctx, "check", "origin/master..HEAD").Run() |
| 42 |
} |
| 43 |
|
| 44 |
func FormatYAML(ctx context.Context) error { |
| 45 |
sg.Logger(ctx).Println("formatting YAML files...") |
| 46 |
return sgyamlfmt.Run(ctx) |
| 47 |
} |
| 48 |
|
| 49 |
func FormatMarkdown(ctx context.Context) error { |
| 50 |
sg.Logger(ctx).Println("formatting Markdown files...") |
| 51 |
return sgmdformat.Command(ctx).Run() |
| 52 |
} |
| 53 |
|
| 54 |
func GoLint(ctx context.Context) error { |
| 55 |
sg.Logger(ctx).Println("linting Go files...") |
| 56 |
return sggolangcilint.Run(ctx) |
| 57 |
} |
| 58 |
|
| 59 |
func GoLintFix(ctx context.Context) error { |
| 60 |
sg.Logger(ctx).Println("fixing Go files...") |
| 61 |
return sggolangcilint.Fix(ctx) |
| 62 |
} |
| 63 |
|
| 64 |
func GoLines(ctx context.Context) error { |
| 65 |
sg.Logger(ctx).Println("wrapping Go lines...") |
| 66 |
return sggolines.Run(ctx) |
| 67 |
} |
| 68 |
|
| 69 |
func GoModTidy(ctx context.Context) error { |
| 70 |
sg.Logger(ctx).Println("tidying Go module files...") |
| 71 |
return sg.Command(ctx, "go", "mod", "tidy", "-v").Run() |
| 72 |
} |
| 73 |
|
| 74 |
func GoTest(ctx context.Context) error { |
| 75 |
sg.Logger(ctx).Println("running Go tests...") |
| 76 |
return sggo.TestCommand(ctx).Run() |
| 77 |
} |
| 78 |
|
| 79 |
func GitVerifyNoDiff(ctx context.Context) error { |
| 80 |
sg.Logger(ctx).Println("verifying that git has no diff...") |
| 81 |
return sggit.VerifyNoDiff(ctx) |
| 82 |
} |
| 83 |
|
| 84 |
func Stringer(ctx context.Context) error { |
| 85 |
sg.Logger(ctx).Println("building...") |
| 86 |
_, err := sgtool.GoInstall(ctx, "golang.org/x/tools/cmd/stringer", "v0.31.0") |
| 87 |
return err |
| 88 |
} |
| 89 |
|
| 90 |
func GoGenerate(ctx context.Context) error { |
| 91 |
sg.Deps(ctx, Stringer) |
| 92 |
sg.Logger(ctx).Println("generating Go code...") |
| 93 |
return sg.Command(ctx, "go", "generate", "./...").Run() |
| 94 |
} |
| 95 |
|
| 96 |
func SemanticRelease(ctx context.Context, repo string, dry bool) error { |
| 97 |
sg.Logger(ctx).Println("triggering release...") |
| 98 |
args := []string{ |
| 99 |
"--allow-initial-development-versions", |
| 100 |
"--allow-no-changes", |
| 101 |
"--ci-condition=default", |
| 102 |
"--provider=github", |
| 103 |
"--provider-opt=slug=" + repo, |
| 104 |
} |
| 105 |
if dry { |
| 106 |
args = append(args, "--dry") |
| 107 |
} |
| 108 |
return sggosemanticrelease.Command(ctx, args...).Run() |
| 109 |
} |