dev
This commit is contained in:
62
.sage/einrideeslint.go
Normal file
62
.sage/einrideeslint.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"go.einride.tech/sage/sg"
|
||||
"go.einride.tech/sage/sgtool"
|
||||
)
|
||||
|
||||
const (
|
||||
name = "eslint"
|
||||
packageJSONContent = `{
|
||||
"dependencies": {
|
||||
"@einride/eslint-plugin": "4.2.0",
|
||||
"eslint": "8.5.0"
|
||||
}
|
||||
}`
|
||||
)
|
||||
|
||||
func eslintCommand(ctx context.Context, args ...string) *exec.Cmd {
|
||||
sg.Deps(ctx, prepareEslintCommand)
|
||||
// eslint plugins should be resolved from the tool dir
|
||||
defaultArgs := []string{
|
||||
"--resolve-plugins-relative-to",
|
||||
sg.FromToolsDir(name),
|
||||
}
|
||||
cmd := sg.Command(ctx, sg.FromBinDir(name), append(defaultArgs, args...)...)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func prepareEslintCommand(ctx context.Context) error {
|
||||
toolDir := sg.FromToolsDir(name)
|
||||
binary := filepath.Join(toolDir, "node_modules", ".bin", name)
|
||||
packageJSON := filepath.Join(toolDir, "package.json")
|
||||
if err := os.MkdirAll(toolDir, 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.WriteFile(packageJSON, []byte(packageJSONContent), 0o600); err != nil {
|
||||
return err
|
||||
}
|
||||
sg.Logger(ctx).Println("installing packages...")
|
||||
if err := sg.Command(
|
||||
ctx,
|
||||
"npm",
|
||||
"--silent",
|
||||
"install",
|
||||
"--prefix",
|
||||
toolDir,
|
||||
"--no-save",
|
||||
"--no-audit",
|
||||
"--ignore-script",
|
||||
).Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := sgtool.CreateSymlink(binary); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
5
.sage/go.mod
Normal file
5
.sage/go.mod
Normal file
@@ -0,0 +1,5 @@
|
||||
module sage
|
||||
|
||||
go 1.22
|
||||
|
||||
require go.einride.tech/sage v0.334.0
|
||||
2
.sage/go.sum
Normal file
2
.sage/go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
go.einride.tech/sage v0.334.0 h1:HY/u8jM2UQ/BerH+vk7JtXf2hg6J0z99Fh0YAQ4QeaE=
|
||||
go.einride.tech/sage v0.334.0/go.mod h1:EzV5uciFX7/2ho8EKB5K9JghOfXIxlzs694b+Tkl5GQ=
|
||||
121
.sage/main.go
Normal file
121
.sage/main.go
Normal file
@@ -0,0 +1,121 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.einride.tech/sage/sg"
|
||||
"go.einride.tech/sage/tools/sgconvco"
|
||||
"go.einride.tech/sage/tools/sggit"
|
||||
"go.einride.tech/sage/tools/sggo"
|
||||
"go.einride.tech/sage/tools/sggolangcilint"
|
||||
"go.einride.tech/sage/tools/sggoreleaser"
|
||||
"go.einride.tech/sage/tools/sggosemanticrelease"
|
||||
"go.einride.tech/sage/tools/sgmdformat"
|
||||
"go.einride.tech/sage/tools/sgyamlfmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
sg.GenerateMakefiles(
|
||||
sg.Makefile{
|
||||
Path: sg.FromGitRoot("Makefile"),
|
||||
DefaultTarget: All,
|
||||
},
|
||||
sg.Makefile{
|
||||
Namespace: Proto{},
|
||||
DefaultTarget: Proto.All,
|
||||
Path: sg.FromGitRoot("examples", "proto", "Makefile"),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func All(ctx context.Context) error {
|
||||
sg.Deps(ctx, ConvcoCheck, GoLint, GoTest, FormatMarkdown, FormatYAML)
|
||||
sg.SerialDeps(ctx, Proto.All, TypescriptLint)
|
||||
sg.SerialDeps(ctx, GoModTidy, GitVerifyNoDiff)
|
||||
return nil
|
||||
}
|
||||
|
||||
func FormatYAML(ctx context.Context) error {
|
||||
sg.Logger(ctx).Println("formatting YAML files...")
|
||||
return sgyamlfmt.Run(ctx)
|
||||
}
|
||||
|
||||
func GoModTidy(ctx context.Context) error {
|
||||
sg.Logger(ctx).Println("tidying Go module files...")
|
||||
return sg.Command(ctx, "go", "mod", "tidy", "-v").Run()
|
||||
}
|
||||
|
||||
func GoTest(ctx context.Context) error {
|
||||
sg.Logger(ctx).Println("running Go tests...")
|
||||
return sggo.TestCommand(ctx).Run()
|
||||
}
|
||||
|
||||
func GoLint(ctx context.Context) error {
|
||||
sg.Logger(ctx).Println("linting Go files...")
|
||||
return sggolangcilint.Run(ctx)
|
||||
}
|
||||
|
||||
func GoLintFix(ctx context.Context) error {
|
||||
sg.Logger(ctx).Println("fixing Go files...")
|
||||
return sggolangcilint.Fix(ctx)
|
||||
}
|
||||
|
||||
func FormatMarkdown(ctx context.Context) error {
|
||||
sg.Logger(ctx).Println("formatting Markdown files...")
|
||||
return sgmdformat.Command(ctx).Run()
|
||||
}
|
||||
|
||||
func ConvcoCheck(ctx context.Context) error {
|
||||
sg.Logger(ctx).Println("checking git commits...")
|
||||
return sgconvco.Command(ctx, "check", "origin/master..HEAD").Run()
|
||||
}
|
||||
|
||||
func GitVerifyNoDiff(ctx context.Context) error {
|
||||
sg.Logger(ctx).Println("verifying that git has no diff...")
|
||||
return sggit.VerifyNoDiff(ctx)
|
||||
}
|
||||
|
||||
func TypescriptLint(ctx context.Context) error {
|
||||
sg.Logger(ctx).Println("linting typescript files...")
|
||||
return eslintCommand(
|
||||
ctx,
|
||||
"--config",
|
||||
sg.FromGitRoot(".eslintrc.js"),
|
||||
"--quiet",
|
||||
"examples/proto/gen/typescript/**/*.ts",
|
||||
).Run()
|
||||
}
|
||||
|
||||
func SemanticRelease(ctx context.Context, repo string, dry bool) error {
|
||||
sg.Logger(ctx).Println("triggering release...")
|
||||
args := []string{
|
||||
"--allow-initial-development-versions",
|
||||
"--allow-no-changes",
|
||||
"--ci-condition=default",
|
||||
"--provider=github",
|
||||
"--provider-opt=slug=" + repo,
|
||||
}
|
||||
if dry {
|
||||
args = append(args, "--dry")
|
||||
}
|
||||
return sggosemanticrelease.Command(ctx, args...).Run()
|
||||
}
|
||||
|
||||
func GoReleaser(ctx context.Context, snapshot bool) error {
|
||||
sg.Logger(ctx).Println("building Go binary releases...")
|
||||
if err := sggit.Command(ctx, "fetch", "--force", "--tags").Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
args := []string{
|
||||
"release",
|
||||
"--clean",
|
||||
}
|
||||
if len(sggit.Tags(ctx)) == 0 && !snapshot {
|
||||
sg.Logger(ctx).Printf("no git tag found for %s, forcing snapshot mode", sggit.ShortSHA(ctx))
|
||||
snapshot = true
|
||||
}
|
||||
if snapshot {
|
||||
args = append(args, "--snapshot")
|
||||
}
|
||||
return sggoreleaser.Command(ctx, args...).Run()
|
||||
}
|
||||
56
.sage/proto.go
Normal file
56
.sage/proto.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.einride.tech/sage/sg"
|
||||
"go.einride.tech/sage/tools/sgbuf"
|
||||
)
|
||||
|
||||
type Proto sg.Namespace
|
||||
|
||||
func (Proto) All(ctx context.Context) error {
|
||||
sg.SerialDeps(ctx, Proto.Build)
|
||||
sg.Deps(ctx, Proto.BufLint, Proto.BufFormat, Proto.BufGenerate)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (Proto) Build(ctx context.Context) error {
|
||||
sg.Logger(ctx).Println("installing binary...")
|
||||
return sg.Command(
|
||||
ctx,
|
||||
"go",
|
||||
"build",
|
||||
"-o",
|
||||
sg.FromBinDir("protoc-gen-typescript-http"),
|
||||
".",
|
||||
).Run()
|
||||
}
|
||||
|
||||
func (Proto) BufLint(ctx context.Context) error {
|
||||
sg.Logger(ctx).Println("linting proto files...")
|
||||
cmd := sgbuf.Command(ctx, "lint")
|
||||
cmd.Dir = sg.FromGitRoot("examples", "proto")
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func (Proto) BufFormat(ctx context.Context) error {
|
||||
sg.Logger(ctx).Println("formatting proto files...")
|
||||
cmd := sgbuf.Command(ctx, "format", "--write")
|
||||
cmd.Dir = sg.FromGitRoot("examples", "proto")
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func (Proto) BufGenerate(ctx context.Context) error {
|
||||
sg.Logger(ctx).Println("generating from proto files...")
|
||||
cmd := sgbuf.Command(
|
||||
ctx,
|
||||
"generate",
|
||||
"--template",
|
||||
"buf.gen.yaml",
|
||||
"--path",
|
||||
"einride",
|
||||
)
|
||||
cmd.Dir = sg.FromGitRoot("examples", "proto")
|
||||
return cmd.Run()
|
||||
}
|
||||
Reference in New Issue
Block a user