From a45e0474117106ee91bbfcff957193c07f2707c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Guimar=C3=A3es?= Date: Mon, 13 Apr 2020 17:15:29 -0300 Subject: [PATCH 01/12] run in tmp path --- cmd/team/main.go | 2 +- pkg/formula/formula.go | 6 ++++++ pkg/formula/runner.go | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cmd/team/main.go b/cmd/team/main.go index bbeff96a9..b79604734 100644 --- a/cmd/team/main.go +++ b/cmd/team/main.go @@ -25,7 +25,7 @@ import ( ) func main() { - if cmd.ServerURL == "" { + if cmd.ServerURL == "https://ritchie-server.itiaws.dev" { panic("The env cmd.ServerURL is required") } diff --git a/pkg/formula/formula.go b/pkg/formula/formula.go index c490437b2..6d6944b0d 100644 --- a/pkg/formula/formula.go +++ b/pkg/formula/formula.go @@ -8,6 +8,7 @@ import ( const ( PathPattern = "%s/formulas/%s" + TmpWorkDirPattern = "%s/tmp/%s/%s" DefaultConfig = "config.json" ConfigPattern = "%s/%s" CommandEnv = "COMMAND" @@ -61,6 +62,11 @@ func (d *Definition) FormulaPath(home string) string { return fmt.Sprintf(PathPattern, home, d.Path) } +// TmpWorkDirPath builds the tmp path to run formula +func (d *Definition) TmpWorkDirPath(home, uuidHash string) string { + return fmt.Sprintf(TmpWorkDirPattern, home, uuidHash, d.Path) +} + // BinName builds the bin name from definition params func (d *Definition) BinName() string { if strings.Contains(d.Bin, "${so}") { diff --git a/pkg/formula/runner.go b/pkg/formula/runner.go index 0607a67f9..30974fc3a 100644 --- a/pkg/formula/runner.go +++ b/pkg/formula/runner.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/google/uuid" "io" "io/ioutil" "log" @@ -88,6 +89,19 @@ func (d DefaultRunner) Run(def Definition) error { } } + //TMP for execution + cPwd, _ := os.Getwd() + fmt.Println("Current pwd: ", cPwd) + u := uuid.New().String() + tdPath := def.TmpWorkDirPath(d.ritchieHome, u) + + fileutil.CreateDirIfNotExists(tdPath, 0755) + + fileutil.CopyDirectory(bPath, tdPath) //Diff + + os.Chdir(tdPath) + bFilePath = def.BinFilePath(tdPath, bName) + cmd := exec.Command(bFilePath) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout @@ -105,6 +119,10 @@ func (d DefaultRunner) Run(def Definition) error { return err } + //realizo o diff + //Copio a diferenca para o pwd + //deleto o temp dir + return nil } From a45a20fd089f1c3293e20e67858fe166fbb73dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Guimar=C3=A3es?= Date: Fri, 17 Apr 2020 09:09:44 -0300 Subject: [PATCH 02/12] created workdir --- pkg/file/fileutil/file_util.go | 48 +++++++++++++++++++++++ pkg/formula/formula.go | 12 ++++-- pkg/formula/runner.go | 72 ++++++++++++++++++++++------------ 3 files changed, 102 insertions(+), 30 deletions(-) diff --git a/pkg/file/fileutil/file_util.go b/pkg/file/fileutil/file_util.go index 41425c764..a866a9930 100644 --- a/pkg/file/fileutil/file_util.go +++ b/pkg/file/fileutil/file_util.go @@ -226,3 +226,51 @@ func Unzip(src string, dest string) error { func IsNotExistErr(err error) bool { return os.IsNotExist(errors.Cause(err)) } + +// Read all files and dir in current directory +func readFilesDir(path string) ([]os.FileInfo, error) { + f, err := os.Open(path) + if err != nil { + return nil, err + } + fl, err := f.Readdir(-1) + f.Close() + return fl, err +} + +//Move files from oPath to nPath +func MoveFiles(oPath, nPath string, files []string) error { + for _, f := range files { + pwdOF := fmt.Sprintf("%s/%s", oPath, f) + pwdNF := fmt.Sprintf("%s/%s", nPath, f) + if err := os.Rename(pwdOF, pwdNF); err != nil { + return err + } + } + return nil +} + +// List new files in nPath differing of oPath +func ListNewFiles(oPath, nPath string) ([]string, error) { + of, err := readFilesDir(oPath) + if err != nil { + return nil, err + } + nf, err := readFilesDir(nPath) + if err != nil { + return nil, err + } + control := make(map[string]int) + for _, file := range of { + control[file.Name()]++ + } + var new []string + for _, file := range nf { + if control[file.Name()] == 0 { + new = append(new, file.Name()) + } + } + return new, nil +} + + diff --git a/pkg/formula/formula.go b/pkg/formula/formula.go index 6d6944b0d..2ac015487 100644 --- a/pkg/formula/formula.go +++ b/pkg/formula/formula.go @@ -8,7 +8,8 @@ import ( const ( PathPattern = "%s/formulas/%s" - TmpWorkDirPattern = "%s/tmp/%s/%s" + TmpDirPattern = "%s/tmp/%s" + TmpBinDirPattern = "%s/tmp/%s/%s" DefaultConfig = "config.json" ConfigPattern = "%s/%s" CommandEnv = "COMMAND" @@ -62,9 +63,12 @@ func (d *Definition) FormulaPath(home string) string { return fmt.Sprintf(PathPattern, home, d.Path) } -// TmpWorkDirPath builds the tmp path to run formula -func (d *Definition) TmpWorkDirPath(home, uuidHash string) string { - return fmt.Sprintf(TmpWorkDirPattern, home, uuidHash, d.Path) +// TmpWorkDirPath builds the tmp paths to run formula, first parameter is tmpDir created +// second parameter is tmpBinDir +func (d *Definition) TmpWorkDirPath(home, uuidHash string) (string, string) { + tmpDir := fmt.Sprintf(TmpDirPattern, home, uuidHash) + tmpBinDir := fmt.Sprintf(TmpBinDirPattern, home, uuidHash, d.Path) + return tmpDir, tmpBinDir } // BinName builds the bin name from definition params diff --git a/pkg/formula/runner.go b/pkg/formula/runner.go index 30974fc3a..696dfe72c 100644 --- a/pkg/formula/runner.go +++ b/pkg/formula/runner.go @@ -52,26 +52,49 @@ func NewRunner( ib} } -// Run default implementation of function Manager.Run -func (d DefaultRunner) Run(def Definition) error { +func (d DefaultRunner) loadConfig(def Definition) (Config, error) { fPath := def.FormulaPath(d.ritchieHome) - - var config *Config + var config Config cName := def.ConfigName() cPath := def.ConfigPath(fPath, cName) if !fileutil.Exists(cPath) { if err := d.downloadConfig(def.ConfigUrl(cName), fPath, cName); err != nil { - return err + return Config{}, err } } configFile, err := ioutil.ReadFile(cPath) if err != nil { - return err + return Config{}, err + } + + if err := json.Unmarshal(configFile, &config); err != nil { + return Config{}, err + } + return config, nil +} + +func (d DefaultRunner) createWorkDir(def Definition) (string, string, error) { + fPath := def.FormulaPath(d.ritchieHome) + u := uuid.New().String() + tDir, tBDir := def.TmpWorkDirPath(d.ritchieHome, u) + + if err := fileutil.CreateDirIfNotExists(tBDir, 0755); err != nil { + return "", "", err } - config = &Config{} - if err := json.Unmarshal(configFile, config); err != nil { + if err := fileutil.CopyDirectory(def.BinPath(fPath), tBDir); err != nil { + return "", "", err + } + return tDir, tBDir, nil +} + +// Run default implementation of function Manager.Run +func (d DefaultRunner) Run(def Definition) error { + cPwd, _ := os.Getwd() + fPath := def.FormulaPath(d.ritchieHome) + config, err := d.loadConfig(def) + if err != nil { return err } @@ -88,26 +111,20 @@ func (d DefaultRunner) Run(def Definition) error { return err } } - - //TMP for execution - cPwd, _ := os.Getwd() - fmt.Println("Current pwd: ", cPwd) - u := uuid.New().String() - tdPath := def.TmpWorkDirPath(d.ritchieHome, u) - - fileutil.CreateDirIfNotExists(tdPath, 0755) - - fileutil.CopyDirectory(bPath, tdPath) //Diff - - os.Chdir(tdPath) - bFilePath = def.BinFilePath(tdPath, bName) + tDir, tBDir, err := d.createWorkDir(def) + if err != nil { + return err + } + defer fileutil.RemoveDir(tDir) + os.Chdir(tBDir) + bFilePath = def.BinFilePath(tBDir, bName) cmd := exec.Command(bFilePath) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr - if err := d.inputs(cmd, fPath, config); err != nil { + if err := d.inputs(cmd, fPath, &config); err != nil { return err } @@ -119,10 +136,13 @@ func (d DefaultRunner) Run(def Definition) error { return err } - //realizo o diff - //Copio a diferenca para o pwd - //deleto o temp dir - + df, err := fileutil.ListNewFiles(bPath, tBDir) + if err != nil { + return err + } + if err = fileutil.MoveFiles(tBDir, cPwd, df); err != nil { + return err + } return nil } From 60be9336a190afec6c29656f86d9ad59119c9d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Guimar=C3=A3es?= Date: Fri, 17 Apr 2020 09:10:38 -0300 Subject: [PATCH 03/12] created workdir --- pkg/formula/runner.go | 74 +++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/pkg/formula/runner.go b/pkg/formula/runner.go index 696dfe72c..0c1d6ffa6 100644 --- a/pkg/formula/runner.go +++ b/pkg/formula/runner.go @@ -52,43 +52,6 @@ func NewRunner( ib} } -func (d DefaultRunner) loadConfig(def Definition) (Config, error) { - fPath := def.FormulaPath(d.ritchieHome) - var config Config - cName := def.ConfigName() - cPath := def.ConfigPath(fPath, cName) - if !fileutil.Exists(cPath) { - if err := d.downloadConfig(def.ConfigUrl(cName), fPath, cName); err != nil { - return Config{}, err - } - } - - configFile, err := ioutil.ReadFile(cPath) - if err != nil { - return Config{}, err - } - - if err := json.Unmarshal(configFile, &config); err != nil { - return Config{}, err - } - return config, nil -} - -func (d DefaultRunner) createWorkDir(def Definition) (string, string, error) { - fPath := def.FormulaPath(d.ritchieHome) - u := uuid.New().String() - tDir, tBDir := def.TmpWorkDirPath(d.ritchieHome, u) - - if err := fileutil.CreateDirIfNotExists(tBDir, 0755); err != nil { - return "", "", err - } - - if err := fileutil.CopyDirectory(def.BinPath(fPath), tBDir); err != nil { - return "", "", err - } - return tDir, tBDir, nil -} - // Run default implementation of function Manager.Run func (d DefaultRunner) Run(def Definition) error { cPwd, _ := os.Getwd() @@ -196,6 +159,43 @@ func (d DefaultRunner) inputs(cmd *exec.Cmd, formulaPath string, config *Config) return nil } +func (d DefaultRunner) loadConfig(def Definition) (Config, error) { + fPath := def.FormulaPath(d.ritchieHome) + var config Config + cName := def.ConfigName() + cPath := def.ConfigPath(fPath, cName) + if !fileutil.Exists(cPath) { + if err := d.downloadConfig(def.ConfigUrl(cName), fPath, cName); err != nil { + return Config{}, err + } + } + + configFile, err := ioutil.ReadFile(cPath) + if err != nil { + return Config{}, err + } + + if err := json.Unmarshal(configFile, &config); err != nil { + return Config{}, err + } + return config, nil +} + +func (d DefaultRunner) createWorkDir(def Definition) (string, string, error) { + fPath := def.FormulaPath(d.ritchieHome) + u := uuid.New().String() + tDir, tBDir := def.TmpWorkDirPath(d.ritchieHome, u) + + if err := fileutil.CreateDirIfNotExists(tBDir, 0755); err != nil { + return "", "", err + } + + if err := fileutil.CopyDirectory(def.BinPath(fPath), tBDir); err != nil { + return "", "", err + } + return tDir, tBDir, nil +} + func (d DefaultRunner) persistCache(formulaPath, inputVal string, input Input, items []string) { cachePath := fmt.Sprintf(CachePattern, formulaPath, strings.ToUpper(input.Name)) if input.Cache.Active { From 671a47592a35756d46cd1e291efacd98d200410b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Guimar=C3=A3es?= Date: Wed, 22 Apr 2020 16:05:14 -0300 Subject: [PATCH 04/12] new pattern download file --- pkg/api/api.go | 1 + pkg/cmd/formulas.go | 4 ++++ pkg/formula/formula.go | 16 ++++++++++++++-- pkg/formula/runner.go | 8 ++++---- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/pkg/api/api.go b/pkg/api/api.go index dfb00a0bb..848610d40 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -64,6 +64,7 @@ type Command struct { type Formula struct { Path string `json:"path"` Bin string `json:"bin"` + Bundle string `json:"bundle"` Config string `json:"config"` RepoURL string `json:"repoUrl"` } diff --git a/pkg/cmd/formulas.go b/pkg/cmd/formulas.go index 750429ad8..833590871 100644 --- a/pkg/cmd/formulas.go +++ b/pkg/cmd/formulas.go @@ -12,6 +12,7 @@ import ( const ( fPath = "fPath" fBin = "fBin" + fBundle = "fBundle" fConfig = "fConfig" fRepoURL = "fRepoURL" subcmd = " SUBCOMMAND" @@ -65,6 +66,7 @@ func (f FormulaCommand) newFormulaCmd(cmd api.Command) *cobra.Command { annotations := make(map[string]string) annotations[fPath] = frm.Path annotations[fBin] = frm.Bin + annotations[fBundle] = frm.Bundle annotations[fConfig] = frm.Config annotations[fRepoURL] = frm.RepoURL @@ -81,11 +83,13 @@ func execFormulaFunc(formulaRunner formula.Runner) func(cmd *cobra.Command, args return func(cmd *cobra.Command, args []string) error { fPath := cmd.Annotations[fPath] fBin := cmd.Annotations[fBin] + fBundle := cmd.Annotations[fBundle] fConf := cmd.Annotations[fConfig] fRepoURL := cmd.Annotations[fRepoURL] frm := formula.Definition{ Path: fPath, Bin: fBin, + Bundle: fBundle, Config: fConf, RepoUrl: fRepoURL, } diff --git a/pkg/formula/formula.go b/pkg/formula/formula.go index 2ac015487..5d5272a92 100644 --- a/pkg/formula/formula.go +++ b/pkg/formula/formula.go @@ -54,6 +54,7 @@ type Cache struct { type Definition struct { Path string Bin string + Bundle string Config string RepoUrl string } @@ -86,6 +87,17 @@ func (d *Definition) BinName() string { return d.Bin } +// BinName builds the bin name from definition params +func (d *Definition) BundleName() string { + if strings.Contains(d.Bundle, "${so}") { + so := runtime.GOOS + bundleSO := strings.ReplaceAll(d.Bin, "${so}", so) + + return bundleSO + } + return d.Bundle +} + // BinPath builds the bin path from formula path func (d *Definition) BinPath(formula string) string { return fmt.Sprintf(BinPathPattern, formula) @@ -97,8 +109,8 @@ func (d *Definition) BinFilePath(binPath, binName string) string { } // BinUrl builds the bin url -func (d *Definition) BinUrl() string { - return fmt.Sprintf("%s/bin/%s.zip", d.RepoUrl, d.BinName()) +func (d *Definition) BundleUrl() string { + return fmt.Sprintf("%s/%s/%s", d.RepoUrl, d.Path, d.BundleName()) } // ConfigName resolver de config name diff --git a/pkg/formula/runner.go b/pkg/formula/runner.go index 0c1d6ffa6..42f7f7a4c 100644 --- a/pkg/formula/runner.go +++ b/pkg/formula/runner.go @@ -65,12 +65,12 @@ func (d DefaultRunner) Run(def Definition) error { bPath := def.BinPath(fPath) bFilePath := def.BinFilePath(bPath, bName) if !fileutil.Exists(bFilePath) { - zipFile, err := d.downloadFormulaBin(def.BinUrl(), bPath, bName) + zipFile, err := d.downloadFormulaBundle(def.BundleUrl(), fPath, def.BundleName()) if err != nil { return err } - if err := d.unzipFile(zipFile, bPath); err != nil { + if err := d.unzipFile(zipFile, fPath); err != nil { return err } } @@ -280,7 +280,7 @@ func (d DefaultRunner) resolveIfReserved(input Input) (string, error) { return "", nil } -func (d DefaultRunner) downloadFormulaBin(url, destPath, binName string) (string, error) { +func (d DefaultRunner) downloadFormulaBundle(url, destPath, zipName string) (string, error) { log.Println("Download formula...") resp, err := http.Get(url) @@ -302,7 +302,7 @@ func (d DefaultRunner) downloadFormulaBin(url, destPath, binName string) (string return "", errors.New("unknown error when downloading your formula") } - file := fmt.Sprintf("%s/%s.zip", destPath, binName) + file := fmt.Sprintf("%s/%s", destPath, zipName) if err := fileutil.CreateDirIfNotExists(destPath, 0755); err != nil { return "", err From 8df9f4e7f02af6fc6cf4c210f41a63577ef9d9c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Guimar=C3=A3es?= Date: Fri, 24 Apr 2020 11:26:42 -0300 Subject: [PATCH 05/12] adjust main --- cmd/team/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/team/main.go b/cmd/team/main.go index b79604734..bbeff96a9 100644 --- a/cmd/team/main.go +++ b/cmd/team/main.go @@ -25,7 +25,7 @@ import ( ) func main() { - if cmd.ServerURL == "https://ritchie-server.itiaws.dev" { + if cmd.ServerURL == "" { panic("The env cmd.ServerURL is required") } From 5c3fd6672796cb6d50a5b35acdb2831b66b423ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Guimar=C3=A3es?= Date: Fri, 24 Apr 2020 14:28:29 -0300 Subject: [PATCH 06/12] bundle name --- pkg/formula/formula.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/formula/formula.go b/pkg/formula/formula.go index 5d5272a92..145b8e7b9 100644 --- a/pkg/formula/formula.go +++ b/pkg/formula/formula.go @@ -88,10 +88,10 @@ func (d *Definition) BinName() string { } // BinName builds the bin name from definition params -func (d *Definition) BundleName() string { +func (d *Definition) BundleName() string { if strings.Contains(d.Bundle, "${so}") { so := runtime.GOOS - bundleSO := strings.ReplaceAll(d.Bin, "${so}", so) + bundleSO := strings.ReplaceAll(d.Bundle, "${so}", so) return bundleSO } @@ -128,7 +128,7 @@ func (d *Definition) ConfigPath(formula, configName string) string { // ConfigUrl builds the config url func (d *Definition) ConfigUrl(configName string) string { - return fmt.Sprintf("%s/%s", d.RepoUrl, configName) + return fmt.Sprintf("%s/%s/%s", d.RepoUrl, d.Path, configName) } type Runner interface { From 5165bfabfe16fcf46aa9406be3ad2097190ed607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ern=C3=A9lio?= Date: Sun, 26 Apr 2020 13:13:05 -0300 Subject: [PATCH 07/12] Edit Makefile for feature/any-languages --- pkg/formula/tpl/tplgo/tpl_go.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/pkg/formula/tpl/tplgo/tpl_go.go b/pkg/formula/tpl/tplgo/tpl_go.go index 8b76a989a..4a58bf29a 100644 --- a/pkg/formula/tpl/tplgo/tpl_go.go +++ b/pkg/formula/tpl/tplgo/tpl_go.go @@ -108,28 +108,27 @@ func main() { }.Run() }` TemplateMakefile = `# Go parameters +BINARY_NAME={{name}} GOCMD=go GOBUILD=$(GOCMD) build -BINARY_NAME={{name}} +GOTEST=$(GOCMD) test CMD_PATH=./main.go -DIST=../bin -DIST_MAC=$(DIST)/$(BINARY_NAME)-darwin -DIST_LINUX=$(DIST)/$(BINARY_NAME)-linux -DIST_WIN=$(DIST)/$(BINARY_NAME)-windows.exe - -FORM_PATH={{form-path}} -PWD_INITIAL=$(shell pwd) +DIST=../dist +DIST_MAC_DIR=$(DIST)/darwin/bin +BIN_MAC=$(BINARY_NAME)-darwin +DIST_LINUX_DIR=$(DIST)/linux/bin +BIN_LINUX=$(BINARY_NAME)-linux build: - mkdir -p $(DIST) + mkdir -p $(DIST_MAC_DIR) $(DIST_LINUX_DIR) $(DIST_WIN_DIR) export MODULE=$(GO111MODULE=on go list -m) #LINUX - GOOS=linux GOARCH=amd64 $(GOBUILD) -tags release -ldflags '-X $(MODULE)/cmd.Version=$(VERSION) -X $(MODULE)/cmd.BuildDate=$(DATE)' -o ./$(DIST_LINUX) -v $(CMD_PATH) + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -tags release -ldflags '-X $(MODULE)/cmd.Version=$(VERSION) -X $(MODULE)/cmd.BuildDate=$(DATE)' -o '$(DIST_LINUX_DIR)/$(BIN_LINUX)' -v $(CMD_PATH) #MAC - GOOS=darwin GOARCH=amd64 $(GOBUILD) -tags release -ldflags '-X $(MODULE)/cmd.Version=$(VERSION) -X $(MODULE)/cmd.BuildDate=$(DATE)' -o ./$(DIST_MAC) -v $(CMD_PATH) - #WINDOWS 64 - GOOS=windows GOARCH=amd64 $(GOBUILD) -tags release -ldflags '-X $(MODULE)/cmd.Version=$(VERSION) -X $(MODULE)/cmd.BuildDate=$(DATE)' -o ./$(DIST_WIN) -v $(CMD_PATH) -` + GOOS=darwin GOARCH=amd64 $(GOBUILD) -tags release -ldflags '-X $(MODULE)/cmd.Version=$(VERSION) -X $(MODULE)/cmd.BuildDate=$(DATE)' -o '$(DIST_MAC_DIR)/$(BIN_MAC)' -v $(CMD_PATH) + +test: + $(GOTEST) -short ` + "`go list ./... | grep -v vendor/`" TemplateMakefileMain = `#Makefiles {{formName}}={{formPath}} FORMULAS=$({{formName}}) From b7b2d22927574f919837aadefa30903552481b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ern=C3=A9lio?= Date: Sun, 26 Apr 2020 13:15:11 -0300 Subject: [PATCH 08/12] Remove dot in log --- pkg/formula/creator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/formula/creator.go b/pkg/formula/creator.go index af20cd990..5bf23b986 100644 --- a/pkg/formula/creator.go +++ b/pkg/formula/creator.go @@ -47,7 +47,7 @@ func (c CreateManager) Create(fCmd string) error { return err } log.Println("Formula successfully created!") - log.Printf("Your formula is in %s.", c.formPath) + log.Printf("Your formula is in %s", c.formPath) return nil } From e8a382f8ca32babc5e57cc691d3c0d0f0b331fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ern=C3=A9lio?= Date: Sun, 26 Apr 2020 13:34:12 -0300 Subject: [PATCH 09/12] Edit script files --- pkg/formula/creator.go | 1 + pkg/formula/tpl/tplgo/tpl_go.go | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/pkg/formula/creator.go b/pkg/formula/creator.go index 5bf23b986..a1e1ce5c4 100644 --- a/pkg/formula/creator.go +++ b/pkg/formula/creator.go @@ -269,6 +269,7 @@ func updateTree(fCmd string, t Tree, i int) Tree { Formula: api.Formula{ Path: pathValue, Bin: fn + "-${so}", + Bundle: "${so}.zip", Config: "config.json", }, Parent: parent, diff --git a/pkg/formula/tpl/tplgo/tpl_go.go b/pkg/formula/tpl/tplgo/tpl_go.go index 4a58bf29a..7ca9ca57a 100644 --- a/pkg/formula/tpl/tplgo/tpl_go.go +++ b/pkg/formula/tpl/tplgo/tpl_go.go @@ -49,23 +49,26 @@ copy_config_files() { } copy_formula_bin() { - cp -rf "$formula"/bin formulas/"$formula" + cp -rf "$formula"/dist formulas/"$formula" } rm_formula_bin() { - rm -rf "$formula"/bin + rm -rf "$formula"/dist } create_formula_checksum() { - find "${formula}"/bin -type f -exec md5sum {} \; | sort -k 2 | md5sum | cut -f1 -d ' ' > formulas/"${formula}.md5" + find "${formula}"/dist -type f -exec md5sum {} \; | sort -k 2 | md5sum | cut -f1 -d ' ' > formulas/"${formula}.md5" } ` + "\ncompact_formula_bin_and_remove_them() {\n" + - "for bin_dir in `find formulas \"$formula\" -type d -name \"bin\"` ; do\n" + + "for bin_dir in `find formulas/\"$formula\" -type d -name \"dist\"`; do\n" + "for binary in `ls -1 $bin_dir`; do\n" + - "zip -j \"${bin_dir}/${binary}.zip\" \"${bin_dir}/${binary}\"\n" + - "rm \"${bin_dir}/${binary}\"\n" + - `done; + "cd ${bin_dir}/${binary}\n" + + "zip -r \"${binary}.zip\" \"bin\"\n" + + "mv \"${binary}\".zip ../../\n" + + `cd - || exit + done; + rm -rf "${bin_dir}" done } @@ -89,6 +92,7 @@ init go 1.14 require github.com/fatih/color v1.9.0` + TemplateMain = `package main import ( @@ -107,6 +111,7 @@ func main() { Boolean: input3, }.Run() }` + TemplateMakefile = `# Go parameters BINARY_NAME={{name}} GOCMD=go @@ -129,6 +134,7 @@ build: test: $(GOTEST) -short ` + "`go list ./... | grep -v vendor/`" + TemplateMakefileMain = `#Makefiles {{formName}}={{formPath}} FORMULAS=$({{formName}}) @@ -186,6 +192,7 @@ func(in Input)Run() { color.Red(fmt.Sprintf("You receive %s in list.", in.List )) color.Yellow(fmt.Sprintf("You receive %s in boolean.", in.Boolean )) }` + TemplateUnzipBinConfigs = `#!/bin/sh find formulas -name "*.zip" | while read filename; do unzip -o -d "` + "`dirname \"$filename\"`\" \"$filename\"; rm -f \"$filename\"; done;" ) From 7173b3ed5f19f3360af637c6d4631e2f6f243636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ern=C3=A9lio?= Date: Sun, 26 Apr 2020 13:47:19 -0300 Subject: [PATCH 10/12] update codeowners --- CODEOWNERS | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index c6bf54a23..b33f2404b 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,2 +1,2 @@ CODEOWNERS -* @sandokandias @marcosgmgm @kaduartur @erneliojuniorzup @viniciusramosdefaria @guillaumefalourd @rodrigomedeirosf +* @sandokandias @marcosgmgm @kaduartur @ernelio @viniciusramosdefaria @guillaumefalourd @rodrigomedeirosf diff --git a/README.md b/README.md index 2bfe141bc..c91ebfd30 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,6 @@ If a copy of the MPL was not distributed with this file, you can obtain one at h * [@marcosgmgm](https://github.com/marcosgmgm) * [@viniciusramosdefaria](https://github.com/viniciusramosdefaria) * [@kaduartur](https://github.com/kaduartur) -* [@erneliojuniorzup](https://github.com/erneliojuniorzup) +* [@ernelio](https://github.com/ernelio) * [@guillaumefalourd](https://github.com/guillaumefalourd) * [@rodrigomedeirosf](https://github.com/rodrigomedeirosf) From 4a4760177b6dc35dd0848367de86d66b0f93df09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Guimar=C3=A3es?= Date: Mon, 27 Apr 2020 14:15:57 -0300 Subject: [PATCH 11/12] merge master --- go.mod | 2 +- pkg/formula/runner.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 1959ad383..6d0a66f3e 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/fatih/color v1.9.0 // indirect github.com/gofrs/flock v0.7.1 - github.com/google/uuid v1.1.1 // indirect + github.com/google/uuid v1.1.1 github.com/gosuri/uitable v0.0.4 github.com/manifoldco/promptui v0.7.0 github.com/mattn/go-runewidth v0.0.9 // indirect diff --git a/pkg/formula/runner.go b/pkg/formula/runner.go index 423f827bc..24a8bd099 100644 --- a/pkg/formula/runner.go +++ b/pkg/formula/runner.go @@ -381,3 +381,4 @@ func (d DefaultRunner) unzipFile(filename, destPath string) error { log.Println("Done.") return nil } + From e82dc0d181001bc846d158e92139d12f1dc8707a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Guimar=C3=A3es?= Date: Mon, 27 Apr 2020 14:39:53 -0300 Subject: [PATCH 12/12] change template create formula --- pkg/formula/tpl/tplgo/tpl_go.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/formula/tpl/tplgo/tpl_go.go b/pkg/formula/tpl/tplgo/tpl_go.go index bc6b63c1f..bc5207069 100644 --- a/pkg/formula/tpl/tplgo/tpl_go.go +++ b/pkg/formula/tpl/tplgo/tpl_go.go @@ -123,6 +123,8 @@ DIST_MAC_DIR=$(DIST)/darwin/bin BIN_MAC=$(BINARY_NAME)-darwin DIST_LINUX_DIR=$(DIST)/linux/bin BIN_LINUX=$(BINARY_NAME)-linux +DIST_WIN_DIR=$(DIST)/windows/bin +BIN_WIN=$(BINARY_NAME)-windows.exe build: mkdir -p $(DIST_MAC_DIR) $(DIST_LINUX_DIR) $(DIST_WIN_DIR) @@ -131,6 +133,8 @@ build: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -tags release -ldflags '-X $(MODULE)/cmd.Version=$(VERSION) -X $(MODULE)/cmd.BuildDate=$(DATE)' -o '$(DIST_LINUX_DIR)/$(BIN_LINUX)' -v $(CMD_PATH) #MAC GOOS=darwin GOARCH=amd64 $(GOBUILD) -tags release -ldflags '-X $(MODULE)/cmd.Version=$(VERSION) -X $(MODULE)/cmd.BuildDate=$(DATE)' -o '$(DIST_MAC_DIR)/$(BIN_MAC)' -v $(CMD_PATH) + #WINDOWS 64 + GOOS=windows GOARCH=amd64 $(GOBUILD) -tags release -ldflags '-X $(MODULE)/cmd.Version=$(VERSION) -X $(MODULE)/cmd.BuildDate=$(DATE)' -o '$(DIST_WIN_DIR)/$(BIN_WIN)' -v $(CMD_PATH) test: $(GOTEST) -short ` + "`go list ./... | grep -v vendor/`"