-
Notifications
You must be signed in to change notification settings - Fork 3
/
magefile.go
59 lines (53 loc) · 1.47 KB
/
magefile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//go:build mage
package main
import (
"fmt"
"os"
"os/exec"
)
// Generate protobufs and statik assets
func Generate() error {
fmt.Println("Generating protobufs and static assets...")
if err := run("buf", "generate"); err != nil {
return err
}
return run("statik", "-m", "-f", "-src", "third_party/OpenAPI/")
}
// Lint and check for breaking changes
func Lint() error {
fmt.Println("Running lint and breaking changes check...")
if err := run("buf", "lint"); err != nil {
return err
}
return run("buf", "breaking", "--against", "https://github.com/7cav/api.git#branch=develop")
}
// Install dependencies and tools
func Install() error {
fmt.Println("Installing dependencies and tools...")
if err := run("go", "install",
"google.golang.org/protobuf/cmd/protoc-gen-go",
"google.golang.org/grpc/cmd/protoc-gen-go-grpc",
"github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway",
"github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2",
"github.com/rakyll/statik",
); err != nil {
return err
}
return run("go", "get", "-u",
"github.com/bufbuild/buf/cmd/buf",
"github.com/square/certstrap",
"github.com/spf13/cobra",
)
}
// Helper function to run commands
func run(name string, args ...string) error {
fmt.Printf("Running command: %s %v\n", name, args)
cmd := exec.Command(name, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return fmt.Errorf("failed to run %s %v: %w", name, args, err)
}
return nil
}