From 3f8e39fdab977ad8df108411b1593e6b54e22d75 Mon Sep 17 00:00:00 2001 From: Magnus Ewe <6613394+magnusewe@users.noreply.github.com> Date: Tue, 9 Jul 2024 13:06:49 +0200 Subject: [PATCH] feat(protoc-gen-decap-cms): add Decap CMS proto generator --- tools/sgprotocgendecapcms/tools.go | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tools/sgprotocgendecapcms/tools.go diff --git a/tools/sgprotocgendecapcms/tools.go b/tools/sgprotocgendecapcms/tools.go new file mode 100644 index 00000000..70ea9bb4 --- /dev/null +++ b/tools/sgprotocgendecapcms/tools.go @@ -0,0 +1,50 @@ +package sgprotocgendecapcms + +import ( + "context" + "fmt" + "os" + "os/exec" + "path/filepath" + "runtime" + + "go.einride.tech/sage/sg" + "go.einride.tech/sage/sgtool" +) + +const ( + version = "1.1.0" + binaryName = "protoc-gen-decap-cms" +) + +func Command(ctx context.Context, args ...string) *exec.Cmd { + sg.Deps(ctx, PrepareCommand) + return sg.Command(ctx, sg.FromBinDir(binaryName), args...) +} + +func PrepareCommand(ctx context.Context) error { + binDir := sg.FromToolsDir(binaryName, version) + binary := filepath.Join(binDir, binaryName) + downloadURL := fmt.Sprintf( + "https://github.com/einride/protobuf-decap-cms/releases/download/v%s/protobuf-decap-cms_%s_%s_%s.tar.gz", + version, + version, + runtime.GOOS, + runtime.GOARCH, + ) + + if err := sgtool.FromRemote( + ctx, + downloadURL, + sgtool.WithDestinationDir(binDir), + sgtool.WithUntarGz(), + sgtool.WithSkipIfFileExists(binary), + sgtool.WithSymlink(binary), + ); err != nil { + return fmt.Errorf("unable to download %s: %w", binaryName, err) + } + if err := os.Chmod(binary, 0o755); err != nil { + return fmt.Errorf("unable to make %s command: %w", binaryName, err) + } + return nil +}