├── .gitignore ├── Dockerfile ├── Jenkinsfile ├── LICENSE ├── README.md ├── artifact ├── artifactDir.go ├── extExists.go ├── nameArtifact.go └── zipDir.go ├── cmd ├── builder.go ├── config.go ├── docker.go └── init.go ├── compile ├── c#.go ├── c.go ├── go.go ├── java.go ├── npm.go ├── python.go ├── ruby.go └── rust.go ├── derive └── derive.go ├── directory ├── builder.go ├── hidden.go ├── logs.go ├── parent.go └── workspace.go ├── go.mod ├── go.sum ├── gui ├── CLogo.png ├── CSharpLogo.png ├── GoLogo.png ├── JavaLogo.png ├── NodeLogo.png ├── PythonLogo.png ├── RubyLogo.png ├── RustLogo.png ├── gui.css ├── gui.go ├── gui.js ├── gui_index.html └── logo.png ├── main.go ├── spinner └── spinner.go ├── utils ├── checkArgs.go ├── cloneRepo.go ├── cloneRepoFiles.go ├── configDerive.go ├── copyDir.go ├── docker.go ├── getName.go ├── getRepoURL.go ├── help.go ├── log │ └── log.go ├── makeHidden.go ├── metadata.go └── pushBuildData.go └── yaml ├── createBuilderYaml.go ├── setConfigEnvs.go └── yamlParser.go /.gitignore: -------------------------------------------------------------------------------- 1 | Builder 2 | Builder.exe -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.16-alpine AS build 2 | ENV APP_USER app 3 | ENV APP_HOME /go/src/builder 4 | ARG GROUP_ID 5 | ARG USER_ID 6 | RUN addgroup -g $GROUP_ID $APP_USER 7 | RUN adduser -S -G $APP_USER --uid $USER_ID $APP_USER 8 | RUN mkdir -p $APP_HOME && chown -R $APP_USER:$APP_USER $APP_HOME 9 | USER app 10 | WORKDIR $APP_HOME 11 | COPY . . 12 | RUN CGO_ENABLED=0 go build -o builder 13 | 14 | # enter [docker build --build-arg USER_ID=$(id -u) --build-arg GROUP_ID(id -g) -t builder .] 15 | # to build image 16 | 17 | # enter [docker run -it builder sh] to run container 18 | # enter [docker run -it --rm -v $PWD:/go/src/builder builder] to run container and 19 | # mount current directory as volume to access data on computer inside container 20 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent { 3 | docker { image golang:1.16-alpine } 4 | } 5 | stages { 6 | stage('Test') { 7 | steps { 8 | sh 'go --version' 9 | } 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /artifact/artifactDir.go: -------------------------------------------------------------------------------- 1 | package artifact 2 | 3 | import ( 4 | "Builder/spinner" 5 | "os" 6 | "strconv" 7 | "time" 8 | ) 9 | 10 | func ArtifactDir() { 11 | var dirPath string 12 | // if os.Getenv("BUILDER_COMMAND") == "true" { 13 | // path, _ := os.Getwd() 14 | // if strings.Contains(path, "workspace") { 15 | // dirPath = strings.TrimRight(path, "\\workspace") 16 | // } else if strings.Contains(path, "workspace") && strings.Contains(path, "temp") { 17 | // dirPath = strings.TrimRight(path, "\\temp") 18 | // } 19 | // } else { 20 | 21 | dirPath = os.Getenv("BUILDER_PARENT_DIR") 22 | dirName := os.Getenv("BUILDER_DIR_NAME") 23 | // } 24 | startTime := os.Getenv("BUILD_START_TIME") 25 | 26 | parsedStartTime, _ := time.Parse(time.RFC850, startTime) 27 | timeBuildStarted := parsedStartTime.Unix() 28 | artifactStamp := dirName + "_artifact_" + strconv.FormatInt(timeBuildStarted, 10) 29 | os.Setenv("BUILDER_ARTIFACT_STAMP", artifactStamp) 30 | artifactDir := dirPath + "/" + artifactStamp 31 | 32 | err := os.Mkdir(artifactDir, 0755) 33 | //should return nil once directory is made, if not, throw err 34 | if err != nil { 35 | spinner.LogMessage("failed to make artifact directory", "fatal") 36 | } 37 | 38 | //check workspace env exists, if not, create it 39 | _, present := os.LookupEnv("BUILDER_ARTIFACT_DIR") 40 | if !present { 41 | os.Setenv("BUILDER_ARTIFACT_DIR", artifactDir) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /artifact/extExists.go: -------------------------------------------------------------------------------- 1 | package artifact 2 | 3 | import ( 4 | "Builder/spinner" 5 | "Builder/utils" 6 | "fmt" 7 | "os" 8 | "path/filepath" 9 | "strings" 10 | ) 11 | 12 | // find file with extension and return file name 13 | func ExtExistsFunction(dirPath string, ext string) (bool, string) { 14 | found := false 15 | d, err := os.Open(dirPath) 16 | if err != nil { 17 | fmt.Println(err) 18 | spinner.LogMessage("could not find dirpath "+dirPath+": "+err.Error(), "fatal") 19 | os.Exit(1) 20 | } 21 | defer d.Close() 22 | 23 | files, err := d.Readdir(-1) 24 | if err != nil { 25 | fmt.Println(err) 26 | spinner.LogMessage("could not read directory: "+err.Error(), "fatal") 27 | os.Exit(1) 28 | } 29 | var fileName string 30 | 31 | for _, file := range files { 32 | if file.Mode().IsRegular() { 33 | if ext != "executable" { 34 | if filepath.Ext(file.Name()) == ext { 35 | fileName = file.Name() 36 | found = true 37 | } 38 | } else { 39 | if file.Mode()&0111 != 0 && file.Name() == strings.TrimSuffix(utils.GetName(), ".git") { 40 | fileName = file.Name() 41 | found = true 42 | } 43 | } 44 | 45 | } 46 | } 47 | return found, fileName 48 | } 49 | -------------------------------------------------------------------------------- /artifact/nameArtifact.go: -------------------------------------------------------------------------------- 1 | package artifact 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "strconv" 7 | "strings" 8 | "time" 9 | ) 10 | 11 | // rename artifact with Unix timestamp 12 | func NameArtifact(fullPath string, extName string) string { 13 | //seperate extName by last ".", return that ext (jar, exe, etc) 14 | newExtName := extName[strings.LastIndex(extName, ".")+1:] 15 | 16 | //trim off ".jar", ".exe", etc to add timestamp 17 | res := strings.Split(extName, "."+newExtName) 18 | parsedStartTime, _ := time.Parse(time.RFC850, os.Getenv("BUILD_START_TIME")) 19 | timeBuildStarted := parsedStartTime.Unix() 20 | 21 | //join it all back together 22 | artifactName := res[0] + "_" + strconv.FormatInt(timeBuildStarted, 10) + "." + newExtName 23 | 24 | err := os.Rename(fullPath+extName, fullPath+artifactName) 25 | if err != nil { 26 | fmt.Println(err) 27 | } 28 | 29 | return artifactName 30 | } 31 | -------------------------------------------------------------------------------- /artifact/zipDir.go: -------------------------------------------------------------------------------- 1 | package artifact 2 | 3 | import ( 4 | "Builder/spinner" 5 | "archive/tar" 6 | "archive/zip" 7 | "compress/gzip" 8 | "fmt" 9 | "io/ioutil" 10 | "os" 11 | "runtime" 12 | ) 13 | 14 | // Npm creates zip from files passed in as arg 15 | func ZipArtifactDir() { 16 | // parentDir := os.Getenv("BUILDER_PARENT_DIR") 17 | artifactDir := os.Getenv("BUILDER_ARTIFACT_DIR") 18 | 19 | if runtime.GOOS == "windows" { 20 | artifactZip := artifactDir + ".zip" 21 | 22 | // CreateZip temp dir. 23 | outFile, err := os.Create(artifactZip) 24 | if err != nil { 25 | spinner.LogMessage("failed to create artifact directory: "+err.Error(), "fatal") 26 | } 27 | 28 | defer outFile.Close() 29 | 30 | // Create a new zip archive. 31 | w := zip.NewWriter(outFile) 32 | 33 | // Add files from artifact dir to the artifact zip. 34 | addFilesZip(w, artifactDir+"/", "") 35 | 36 | err = w.Close() 37 | if err != nil { 38 | spinner.LogMessage("failed to create artifact directory: "+err.Error(), "fatal") 39 | } 40 | } else { 41 | 42 | artifactTar := artifactDir + ".tar.gz" 43 | 44 | outFile, err := os.Create(artifactTar) 45 | if err != nil { 46 | spinner.LogMessage("failed to create artifact directory: "+err.Error(), "fatal") 47 | } 48 | 49 | defer outFile.Close() 50 | 51 | gw := gzip.NewWriter(outFile) 52 | defer gw.Close() 53 | tw := tar.NewWriter(gw) 54 | defer tw.Close() 55 | 56 | // Add files from artifact dir to the artifact tar.gz. 57 | addFilesTar(tw, artifactDir+"/", "") 58 | 59 | err = tw.Close() 60 | if err != nil { 61 | spinner.LogMessage("failed to create artifact: "+err.Error(), "fatal") 62 | } 63 | } 64 | 65 | } 66 | 67 | // recursively add files 68 | func addFilesZip(w *zip.Writer, basePath, baseInZip string) { 69 | // Open the Directory 70 | files, err := ioutil.ReadDir(basePath) 71 | if err != nil { 72 | spinner.LogMessage("failed to read zip directory: "+err.Error(), "fatal") 73 | } 74 | 75 | for _, file := range files { 76 | if !file.IsDir() { 77 | dat, err := ioutil.ReadFile(basePath + file.Name()) 78 | if err != nil { 79 | fmt.Println(err) 80 | } 81 | 82 | // Add some files to the archive. 83 | f, err := w.Create(baseInZip + file.Name()) 84 | if err != nil { 85 | spinner.LogMessage("failed to create zip: "+err.Error(), "error") 86 | } 87 | _, err = f.Write(dat) 88 | if err != nil { 89 | spinner.LogMessage("failed to add files to zip: "+err.Error(), "error") 90 | } 91 | } else if file.IsDir() { 92 | // Recurse 93 | newBase := basePath + file.Name() + "/" 94 | addFilesZip(w, newBase, baseInZip+file.Name()+"/") 95 | } 96 | } 97 | } 98 | 99 | func addFilesTar(w *tar.Writer, basePath, baseInZip string) { 100 | // Open the Directory 101 | files, err := ioutil.ReadDir(basePath) 102 | if err != nil { 103 | fmt.Println(err) 104 | } 105 | 106 | for _, file := range files { 107 | if !file.IsDir() { 108 | dat, err := ioutil.ReadFile(basePath + file.Name()) 109 | if err != nil { 110 | fmt.Println(err) 111 | } 112 | 113 | header, err := tar.FileInfoHeader(file, file.Name()) 114 | if err != nil { 115 | fmt.Println(err) 116 | } 117 | 118 | header.Name = baseInZip + file.Name() 119 | 120 | // Add some files to the archive. 121 | err = w.WriteHeader(header) 122 | if err != nil { 123 | fmt.Println(err) 124 | } 125 | _, err = w.Write(dat) 126 | if err != nil { 127 | fmt.Println(err) 128 | } 129 | } else if file.IsDir() { 130 | // Recurse 131 | newBase := basePath + file.Name() + "/" 132 | addFilesTar(w, newBase, baseInZip+file.Name()+"/") 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /cmd/builder.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "Builder/derive" 5 | "Builder/directory" 6 | "Builder/spinner" 7 | "Builder/utils" 8 | "Builder/yaml" 9 | "net/url" 10 | "os" 11 | ) 12 | 13 | func Builder() { 14 | os.Setenv("BUILDER_COMMAND", "true") 15 | path, _ := os.Getwd() 16 | 17 | // Start loading spinner 18 | spinner.Spinner.Start() 19 | 20 | //checks if yaml file exists in path 21 | if _, err := os.Stat(path + "/" + "builder.yaml"); err == nil { 22 | //parse builder.yaml 23 | yaml.YamlParser(path + "/" + "builder.yaml") 24 | 25 | // Check if push command provided and save properties 26 | args := os.Args[1:] 27 | for i, v := range args { 28 | if v == "push" { 29 | if len(args) <= i+1 { 30 | if os.Getenv("BUILDER_PUSH_URL") == "" { 31 | spinner.LogMessage("No Push Url Provided", "fatal") 32 | } 33 | } else { 34 | if args[i+1] == "--save" { 35 | os.Setenv("BUILDER_PUSH_AUTO", "true") 36 | 37 | if len(args) <= i+2 { 38 | if os.Getenv("BUILDER_PUSH_URL") == "" { 39 | spinner.LogMessage("No Push Url Provided", "fatal") 40 | } 41 | } else { 42 | pushURL := args[i+2] 43 | _, err := url.Parse(pushURL) 44 | if err != nil { 45 | spinner.LogMessage("Push URL provided is not a valid url: "+err.Error(), "fatal") 46 | } 47 | os.Setenv("BUILDER_PUSH_URL", pushURL) 48 | } 49 | } else { 50 | pushURL := args[i+1] 51 | _, err := url.ParseRequestURI(pushURL) 52 | if err != nil { 53 | spinner.LogMessage("Push URL provided is not a valid url: "+err.Error(), "fatal") 54 | } 55 | os.Setenv("BUILDER_PUSH_URL", pushURL) 56 | 57 | if len(args) > i+2 { 58 | if args[i+2] == "--save" { 59 | os.Setenv("BUILDER_PUSH_AUTO", "true") 60 | } 61 | } 62 | } 63 | } 64 | } 65 | } 66 | 67 | // Set repo path 68 | os.Setenv("BUILDER_REPO_DIR", path) 69 | 70 | // Create directories 71 | directory.MakeDirs() 72 | spinner.LogMessage("Directories successfully created.", "info") 73 | 74 | // clone files from current dir into hidden 75 | currentDir, _ := os.Getwd() 76 | hiddenDir := os.Getenv("BUILDER_HIDDEN_DIR") 77 | utils.CloneRepoFiles(currentDir, hiddenDir) 78 | spinner.LogMessage("Files copied to hidden dir successfully.", "info") 79 | 80 | //creates a new artifact 81 | derive.ProjectType() 82 | 83 | //Get build metadata (deprecated, func moved inside compiler) 84 | spinner.LogMessage("Metadata created successfully.", "info") 85 | 86 | // Store build metadata to hidden builder dir 87 | utils.StoreBuildMetadataLocally() 88 | 89 | // If provided, push build data to provided url 90 | if os.Getenv("BUILDER_PUSH_AUTO") == "true" { 91 | if os.Getenv("BUILDER_PUSH_URL") != "" { 92 | utils.PushBuildData() 93 | } else { 94 | spinner.LogMessage("Build is set to auto-push but was not provided a url.", "fatal") 95 | } 96 | } else { // if push property was provided to command, push build data to provided url 97 | args := os.Args 98 | for _, v := range args { 99 | if v == "push" { 100 | if os.Getenv("BUILDER_PUSH_URL") != "" { 101 | utils.PushBuildData() 102 | } else { 103 | spinner.LogMessage("Push Url Not Provided.", "fatal") 104 | } 105 | } 106 | } 107 | } 108 | 109 | //Check for Dockerfile, then build image 110 | utils.Docker() 111 | 112 | //makes hidden dir read-only 113 | utils.MakeHidden() 114 | spinner.LogMessage("Hidden Dir is now read-only.", "info") 115 | 116 | // Stop loading spinner 117 | spinner.Spinner.Stop() 118 | } else { 119 | utils.Help() 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /cmd/config.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "Builder/derive" 5 | "Builder/directory" 6 | "Builder/spinner" 7 | "Builder/utils" 8 | "Builder/yaml" 9 | 10 | "os" 11 | ) 12 | 13 | func Config() { 14 | //check args normally, 15 | utils.CheckArgs() 16 | 17 | // Start loading spinner 18 | spinner.Spinner.Start() 19 | 20 | //clone repo into temp dir to pull builder.yaml info 21 | utils.CloneRepo("./tempRepo") 22 | 23 | //set yaml info as env vars 24 | yaml.YamlParser("./tempRepo/builder.yaml") 25 | 26 | // clone repo into folder named after project name and keep track of its path 27 | projectName := utils.GetName() 28 | if os.Getenv("BUILDER_DIR_PATH") != "" { // User wants this repo built elsewhere 29 | utils.CloneRepo(os.Getenv("BUILDER_DIR_PATH") + "/" + projectName) 30 | os.Setenv("BUILDER_REPO_DIR", os.Getenv("BUILDER_DIR_PATH")+"/"+projectName) 31 | } else { 32 | utils.CloneRepo("./" + projectName) 33 | os.Setenv("BUILDER_REPO_DIR", "./"+projectName) 34 | } 35 | spinner.LogMessage("Repo cloned successfully.", "info") 36 | 37 | // make dirs 38 | directory.MakeDirs() 39 | spinner.LogMessage("Directories successfully created.", "info") 40 | 41 | // copy repo files we just cloned to hidden dir 42 | repoDir := os.Getenv("BUILDER_REPO_DIR") 43 | hiddenDir := os.Getenv("BUILDER_HIDDEN_DIR") 44 | utils.CloneRepoFiles(repoDir, hiddenDir) 45 | 46 | // compile logic to derive project type 47 | derive.ProjectType() 48 | 49 | //Get build metadata (deprecated, func moved inside compiler) 50 | // utils.Metadata() 51 | spinner.LogMessage("Metadata created successfully.", "info") 52 | 53 | // Store build metadata to hidden builder dir 54 | utils.StoreBuildMetadataLocally() 55 | 56 | //Check for Dockerfile, then build image 57 | utils.Docker() 58 | 59 | //makes hidden dir read-only 60 | utils.MakeHidden() 61 | spinner.LogMessage("Hidden Dir is now read-only.", "info") 62 | 63 | // Stop loading spinner 64 | spinner.Spinner.Stop() 65 | } 66 | -------------------------------------------------------------------------------- /cmd/init.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "Builder/derive" 5 | "Builder/directory" 6 | "Builder/spinner" 7 | "Builder/utils" 8 | 9 | "os" 10 | ) 11 | 12 | func Init() { 13 | //check argument syntax, exit if incorrect 14 | utils.CheckArgs() 15 | 16 | // Start loading spinner 17 | spinner.Spinner.Start() 18 | 19 | // clone repo into folder named after project name and keep track of its path 20 | projectName := utils.GetName() 21 | os.Setenv("BUILDER_REPO_DIR", "./"+projectName) 22 | utils.CloneRepo("./" + projectName) 23 | spinner.LogMessage("Repo cloned successfully.", "info") 24 | 25 | // make dirs 26 | directory.MakeDirs() 27 | spinner.LogMessage("Directories successfully created.", "info") 28 | 29 | // copy repo files we just cloned to hidden dir 30 | repoDir := os.Getenv("BUILDER_REPO_DIR") 31 | hiddenDir := os.Getenv("BUILDER_HIDDEN_DIR") 32 | utils.CloneRepoFiles(repoDir, hiddenDir) 33 | 34 | // compile logic to derive project type 35 | derive.ProjectType() 36 | 37 | //Get build metadata (deprecated, func moved inside compiler) 38 | // utils.Metadata() 39 | spinner.LogMessage("Metadata created successfully.", "info") 40 | 41 | // Store build metadata to hidden builder dir 42 | utils.StoreBuildMetadataLocally() 43 | 44 | //Check for Dockerfile, then build image 45 | utils.Docker() 46 | 47 | //makes hidden dir read-only 48 | utils.MakeHidden() 49 | spinner.LogMessage("Hidden Dir is now read-only.", "info") 50 | 51 | // Stop loading spinner 52 | spinner.Spinner.Stop() 53 | } 54 | -------------------------------------------------------------------------------- /compile/c#.go: -------------------------------------------------------------------------------- 1 | package compile 2 | 3 | import ( 4 | "Builder/artifact" 5 | "Builder/directory" 6 | "Builder/spinner" 7 | "Builder/utils" 8 | "Builder/utils/log" 9 | "Builder/yaml" 10 | "bufio" 11 | "fmt" 12 | "os" 13 | "os/exec" 14 | "path/filepath" 15 | "runtime" 16 | "strings" 17 | "time" 18 | 19 | cp "github.com/otiai10/copy" 20 | ) 21 | 22 | func CSharp(filePath string) { 23 | fmt.Println("C# filePath: " + filePath) 24 | //Set default project type env for builder.yaml creation 25 | projectType := os.Getenv("BUILDER_PROJECT_TYPE") 26 | if projectType == "" { 27 | os.Setenv("BUILDER_PROJECT_TYPE", "c#") 28 | } 29 | 30 | //Set up local logger 31 | localPath, _ := os.LookupEnv("BUILDER_LOGS_DIR") 32 | locallogger, closeLocalLogger = log.NewLogger("logs", localPath) 33 | 34 | //define dir path for command to run in 35 | var fullPath string 36 | configPath := os.Getenv("BUILDER_DIR_PATH") 37 | //if user defined path in builder.yaml, full path is included already, else add curren dir + local path 38 | if os.Getenv("BUILDER_COMMAND") == "true" { 39 | // ex: C:/Users/Name/Projects/helloworld_19293/workspace/dir 40 | fullPath = filePath 41 | } else if configPath != "" { 42 | // ex: C:/Users/Name/Projects/helloworld_19293/workspace/dir 43 | fullPath = filePath 44 | } else { 45 | path, _ := os.Getwd() 46 | //combine local path to newly created tempWorkspace, 47 | //gets rid of "." in path name 48 | // ex: C:/Users/Name/Projects + /helloworld_19293/workspace/dir 49 | fullPath = path + filePath[strings.Index(filePath, ".")+1:] 50 | os.Setenv("BUILDER_DIR_PATH", path) 51 | } 52 | 53 | //install dependencies/build, 54 | // if yaml build type exists install accordingly, if buildCmd exists, 55 | buildTool := strings.ToLower(os.Getenv("BUILDER_BUILD_TOOL")) 56 | buildCmd := os.Getenv("BUILDER_BUILD_COMMAND") 57 | 58 | var cmd *exec.Cmd 59 | if buildCmd != "" { 60 | //user specified cmd 61 | buildCmdArray := strings.Fields(buildCmd) 62 | cmd = exec.Command(buildCmdArray[0], buildCmdArray[1:]...) 63 | cmd.Dir = fullPath // or whatever directory it's in 64 | } else if buildTool == "dotnet" { 65 | cmd = exec.Command("dotnet", "build", fullPath) 66 | cmd.Dir = fullPath // or whatever directory it's in 67 | os.Setenv("BUILDER_BUILD_COMMAND", "dotnet build "+fullPath) 68 | } else { 69 | //default 70 | cmd = exec.Command("dotnet", "build", fullPath) 71 | // cmd.Dir = fullPath // or whatever directory it's in 72 | os.Setenv("BUILDER_BUILD_TOOL", "dotnet") 73 | os.Setenv("BUILDER_BUILD_COMMAND", "dotnet build "+fullPath) 74 | os.Setenv("BUILDER_BUILD_FILE", fullPath[strings.LastIndex(fullPath, "/")+1:]) 75 | } 76 | 77 | //run cmd, check for err, log cmd 78 | spinner.LogMessage("running command: "+cmd.String(), "info") 79 | 80 | stdout, pipeErr := cmd.StdoutPipe() 81 | if pipeErr != nil { 82 | spinner.LogMessage(pipeErr.Error(), "fatal") 83 | } 84 | 85 | cmd.Stderr = cmd.Stdout 86 | 87 | // Make a new channel which will be used to ensure we get all output 88 | done := make(chan struct{}) 89 | 90 | scanner := bufio.NewScanner(stdout) 91 | 92 | // Use the scanner to scan the output line by line and log it 93 | // It's running in a goroutine so that it doesn't block 94 | go func() { 95 | // Read line by line and process it 96 | for scanner.Scan() { 97 | line := scanner.Text() 98 | spinner.Spinner.Stop() 99 | locallogger.Info(line) 100 | spinner.Spinner.Start() 101 | } 102 | 103 | // We're all done, unblock the channel 104 | done <- struct{}{} 105 | 106 | }() 107 | 108 | os.Setenv("BUILD_START_TIME", time.Now().Format(time.RFC850)) 109 | 110 | if err := cmd.Start(); err != nil { 111 | spinner.LogMessage(err.Error(), "fatal") 112 | } 113 | 114 | // Wait for all output to be processed 115 | <-done 116 | 117 | // Wait for cmd to finish 118 | if err := cmd.Wait(); err != nil { 119 | spinner.LogMessage(err.Error(), "fatal") 120 | } 121 | 122 | os.Setenv("BUILD_END_TIME", time.Now().Format(time.RFC850)) 123 | 124 | // Close log file 125 | closeLocalLogger() 126 | 127 | // Update parent dir name to include start time and send back new full path 128 | fullPath = directory.UpdateParentDirName(fullPath) 129 | 130 | if os.Args[1] == "init" || os.Args[1] == "config" { 131 | repoPath := "./" + strings.TrimSuffix(utils.GetName(), ".git") 132 | 133 | if configPath != "" { 134 | repoPath = configPath + "/" + strings.TrimSuffix(utils.GetName(), ".git") 135 | } 136 | 137 | yaml.CreateBuilderYaml(repoPath) 138 | } else { 139 | yaml.CreateBuilderYaml(fullPath) 140 | } 141 | 142 | packageCSharpArtifact(fullPath) 143 | 144 | spinner.LogMessage("csharp project compiled successfully.", "info") 145 | } 146 | 147 | func packageCSharpArtifact(fullPath string) { 148 | archiveExt := "" 149 | 150 | if runtime.GOOS == "windows" { 151 | archiveExt = ".zip" 152 | } else { 153 | archiveExt = ".tar.gz" 154 | } 155 | 156 | artifact.ArtifactDir() 157 | artifactDir := os.Getenv("BUILDER_ARTIFACT_DIR") 158 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 159 | 160 | //find artifact by extension 161 | artifactsArray, _ := WalkMatch(fullPath, "*.dll") 162 | os.Setenv("BUILDER_ARTIFACT_NAMES", strings.Join([]string(artifactsArray), ",")) 163 | 164 | var artifactNames []string 165 | 166 | //copy artifact(s), then remove artifact(s) from workspace 167 | for i := 0; i < len(artifactsArray); i++ { 168 | artifactNames = append(artifactNames, filepath.Base(artifactsArray[i])) 169 | 170 | err := cp.Copy(artifactsArray[i], artifactDir+"/"+artifactNames[i]) 171 | if err != nil { 172 | spinner.LogMessage(err.Error(), "warn") 173 | } 174 | 175 | // If outputpath provided also cp artifacts to that location 176 | if outputPath != "" { 177 | // Check if outputPath exists. If not, create it 178 | if _, err := os.Stat(outputPath); os.IsNotExist(err) { 179 | if err := os.Mkdir(outputPath, 0755); err != nil { 180 | spinner.LogMessage("Could not create output path", "fatal") 181 | } 182 | } 183 | 184 | err := cp.Copy(artifactsArray[i], outputPath+"/"+artifactNames[i]) 185 | if err != nil { 186 | spinner.LogMessage(err.Error(), "warn") 187 | } 188 | 189 | spinner.LogMessage("Artifact(s) copied to output path provided", "info") 190 | } 191 | 192 | errRemove := os.Remove(artifactsArray[i]) 193 | if errRemove != nil { 194 | spinner.LogMessage(errRemove.Error(), "warn") 195 | } 196 | } 197 | 198 | os.Setenv("BUILDER_ARTIFACT_NAMES", strings.Join([]string(artifactNames), ",")) 199 | 200 | //create metadata, then copy contents to zip dir 201 | utils.Metadata(artifactDir) 202 | 203 | if os.Getenv("ARTIFACT_ZIP_ENABLED") == "true" { 204 | //zip artifact 205 | artifact.ZipArtifactDir() 206 | 207 | //remove uncompressed artifacts 208 | for i := 0; i < len(artifactsArray); i++ { 209 | err := os.Remove(artifactDir + "/" + filepath.Base(artifactsArray[i])) 210 | if err != nil { 211 | spinner.LogMessage(err.Error(), "warn") 212 | } 213 | } 214 | 215 | // send artifact to user specified path or send to artifact directory 216 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 217 | if outputPath != "" { 218 | err := cp.Copy(artifactDir+archiveExt, outputPath+"/"+filepath.Base(artifactDir)+archiveExt) 219 | if err != nil { 220 | spinner.LogMessage(err.Error(), "warn") 221 | } 222 | } else { 223 | err := cp.Copy(artifactDir+archiveExt, artifactDir+"/"+filepath.Base(artifactDir)+archiveExt) 224 | if err != nil { 225 | spinner.LogMessage(err.Error(), "warn") 226 | } 227 | } 228 | 229 | errRemove := os.Remove(artifactDir + archiveExt) 230 | if errRemove != nil { 231 | spinner.LogMessage(errRemove.Error(), "warn") 232 | } 233 | } 234 | } 235 | 236 | func WalkMatch(root, pattern string) ([]string, error) { 237 | var matches []string 238 | err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { 239 | if err != nil { 240 | return err 241 | } 242 | if info.IsDir() { 243 | return nil 244 | } 245 | if matched, err := filepath.Match(pattern, filepath.Base(path)); err != nil { 246 | return err 247 | } else if matched { 248 | matches = append(matches, path) 249 | } 250 | return nil 251 | }) 252 | if err != nil { 253 | return nil, err 254 | } 255 | return matches, nil 256 | } 257 | -------------------------------------------------------------------------------- /compile/c.go: -------------------------------------------------------------------------------- 1 | package compile 2 | 3 | import ( 4 | "Builder/artifact" 5 | "Builder/directory" 6 | "Builder/spinner" 7 | "Builder/utils" 8 | "Builder/utils/log" 9 | "Builder/yaml" 10 | "bufio" 11 | "os" 12 | "os/exec" 13 | "path/filepath" 14 | "runtime" 15 | "strings" 16 | "time" 17 | 18 | cp "github.com/otiai10/copy" 19 | ) 20 | 21 | var closeLocalLogger func() 22 | 23 | // C/C++ does ... 24 | func C(filePath string) { 25 | //Set default project type env for builder.yaml creation 26 | projectType := os.Getenv("BUILDER_PROJECT_TYPE") 27 | if projectType == "" { 28 | os.Setenv("BUILDER_PROJECT_TYPE", "c") 29 | } 30 | 31 | //Set up local logger 32 | localPath, _ := os.LookupEnv("BUILDER_LOGS_DIR") 33 | locallogger, closeLocalLogger = log.NewLogger("logs", localPath) 34 | 35 | //define dir path for command to run in 36 | var fullPath string 37 | configPath := os.Getenv("BUILDER_DIR_PATH") 38 | 39 | if os.Getenv("BUILDER_COMMAND") == "true" { 40 | // ex: C:/Users/Name/Projects/helloworld_19293/workspace/dir 41 | fullPath = filePath 42 | } else if configPath != "" { //if user defined path in builder.yaml, full path is included already, else add curren dir + local path 43 | // ex: C:/Users/Name/Projects/helloworld_19293/workspace/dir 44 | fullPath = filePath 45 | } else { 46 | path, _ := os.Getwd() 47 | //combine local path to newly created tempWorkspace, 48 | //gets rid of "." in path name 49 | // ex: C:/Users/Name/Projects + /helloworld_19293/workspace/dir 50 | fullPath = path + filePath[strings.Index(filePath, ".")+1:] 51 | os.Setenv("BUILDER_DIR_PATH", path) 52 | } 53 | 54 | //install dependencies/build, if yaml build type exists install accordingly 55 | buildTool := strings.ToLower(os.Getenv("BUILDER_BUILD_TOOL")) 56 | //find 'Makefile' to be built 57 | buildFile := strings.ToLower(os.Getenv("BUILDER_BUILD_FILE")) 58 | preBuildCmd := os.Getenv("BUILDER_PREBUILD_COMMAND") 59 | configCmd := os.Getenv("BUILDER_CONFIG_COMMAND") 60 | buildCmd := os.Getenv("BUILDER_BUILD_COMMAND") 61 | 62 | var cmd *exec.Cmd 63 | 64 | // If a pre-build command is provided execute it 65 | if preBuildCmd != "" { 66 | //user specified cmd 67 | preBuildCmdArray := strings.Fields(preBuildCmd) 68 | cmd = exec.Command(preBuildCmdArray[0], preBuildCmdArray[1:]...) 69 | cmd.Dir = fullPath // or whatever directory it's in 70 | 71 | //run pre-build cmd, check for err, log pre-build cmd 72 | spinner.LogMessage("running command: "+cmd.String(), "info") 73 | 74 | preBuildStdout, pipeErr := cmd.StdoutPipe() 75 | if pipeErr != nil { 76 | spinner.LogMessage(pipeErr.Error(), "fatal") 77 | } 78 | 79 | cmd.Stderr = cmd.Stdout 80 | 81 | // Make a new channel which will be used to ensure we get all output 82 | preBuildDone := make(chan struct{}) 83 | 84 | preBuildScanner := bufio.NewScanner(preBuildStdout) 85 | 86 | // Use the scanner to scan the output line by line and log it 87 | // It's running in a goroutine so that it doesn't block 88 | go func() { 89 | // Read line by line and process it 90 | for preBuildScanner.Scan() { 91 | line := preBuildScanner.Text() 92 | // Have to stop spinner or it will get printed with log to console 93 | spinner.Spinner.Stop() 94 | locallogger.Info(line) 95 | spinner.Spinner.Start() 96 | } 97 | 98 | // We're all done, unblock the channel 99 | preBuildDone <- struct{}{} 100 | 101 | }() 102 | 103 | if err := cmd.Start(); err != nil { 104 | spinner.LogMessage(err.Error(), "fatal") 105 | } 106 | 107 | // Wait for all output to be processed 108 | <-preBuildDone 109 | 110 | // Wait for cmd to finish 111 | if err := cmd.Wait(); err != nil { 112 | spinner.LogMessage(err.Error(), "fatal") 113 | } 114 | } 115 | 116 | // If a configure command is provided execute it 117 | if configCmd != "" { 118 | //user specified cmd 119 | configCmdArray := strings.Fields(configCmd) 120 | cmd = exec.Command(configCmdArray[0], configCmdArray[1:]...) 121 | cmd.Dir = fullPath // or whatever directory it's in 122 | 123 | //run config cmd, check for err, log config cmd 124 | spinner.LogMessage("running command: "+cmd.String(), "info") 125 | 126 | configStdout, pipeErr := cmd.StdoutPipe() 127 | if pipeErr != nil { 128 | spinner.LogMessage(pipeErr.Error(), "fatal") 129 | } 130 | 131 | cmd.Stderr = cmd.Stdout 132 | 133 | // Make a new channel which will be used to ensure we get all output 134 | configDone := make(chan struct{}) 135 | 136 | configScanner := bufio.NewScanner(configStdout) 137 | 138 | // Use the scanner to scan the output line by line and log it 139 | // It's running in a goroutine so that it doesn't block 140 | go func() { 141 | // Read line by line and process it 142 | for configScanner.Scan() { 143 | line := configScanner.Text() 144 | // Have to stop spinner or it will get printed with log to console 145 | spinner.Spinner.Stop() 146 | locallogger.Info(line) 147 | spinner.Spinner.Start() 148 | } 149 | 150 | // We're all done, unblock the channel 151 | configDone <- struct{}{} 152 | 153 | }() 154 | 155 | if err := cmd.Start(); err != nil { 156 | spinner.LogMessage(err.Error(), "fatal") 157 | } 158 | 159 | // Wait for all output to be processed 160 | <-configDone 161 | 162 | // Wait for cmd to finish 163 | if err := cmd.Wait(); err != nil { 164 | spinner.LogMessage(err.Error(), "fatal") 165 | } 166 | } 167 | 168 | // Build command 169 | if buildCmd != "" { 170 | //user specified cmd 171 | buildCmdArray := strings.Fields(buildCmd) 172 | cmd = exec.Command(buildCmdArray[0], buildCmdArray[1:]...) 173 | cmd.Dir = fullPath // or whatever directory it's in 174 | } else if buildFile != "" { // using buildTool that includes 'make' by default 175 | //default with build file provided 176 | cmd = exec.Command("make", "-f", buildFile) 177 | cmd.Dir = fullPath // or whatever directory it's in 178 | os.Setenv("BUILDER_BUILD_COMMAND", "make -f "+buildFile) 179 | } else { // using buildTool that includes 'make' by default 180 | //default 181 | cmd = exec.Command("make") 182 | cmd.Dir = fullPath // or whatever directory it's in 183 | if buildTool == "" { // If buildTool hasn't been set yet, set it 184 | os.Setenv("BUILDER_BUILD_TOOL", "Make") 185 | } 186 | os.Setenv("BUILDER_BUILD_COMMAND", "make") 187 | } 188 | 189 | //run cmd, check for err, log cmd 190 | spinner.LogMessage("running command: "+cmd.String(), "info") 191 | 192 | stdout, pipeErr := cmd.StdoutPipe() 193 | if pipeErr != nil { 194 | spinner.LogMessage(pipeErr.Error(), "fatal") 195 | } 196 | 197 | cmd.Stderr = cmd.Stdout 198 | 199 | // Make a new channel which will be used to ensure we get all output 200 | done := make(chan struct{}) 201 | 202 | scanner := bufio.NewScanner(stdout) 203 | 204 | // Use the scanner to scan the output line by line and log it 205 | // It's running in a goroutine so that it doesn't block 206 | go func() { 207 | // Read line by line and process it 208 | for scanner.Scan() { 209 | line := scanner.Text() 210 | // Have to stop spinner or it will get printed with log to console 211 | spinner.Spinner.Stop() 212 | locallogger.Info(line) 213 | spinner.Spinner.Start() 214 | } 215 | 216 | // We're all done, unblock the channel 217 | done <- struct{}{} 218 | 219 | }() 220 | 221 | os.Setenv("BUILD_START_TIME", time.Now().Format(time.RFC850)) 222 | 223 | if err := cmd.Start(); err != nil { 224 | spinner.LogMessage(err.Error(), "fatal") 225 | } 226 | 227 | // Wait for all output to be processed 228 | <-done 229 | 230 | // Wait for cmd to finish 231 | if err := cmd.Wait(); err != nil { 232 | spinner.LogMessage(err.Error(), "fatal") 233 | } 234 | 235 | os.Setenv("BUILD_END_TIME", time.Now().Format(time.RFC850)) 236 | 237 | // Close log file 238 | closeLocalLogger() 239 | 240 | // Update parent dir name to include start time and send back new full path 241 | fullPath = directory.UpdateParentDirName(fullPath) 242 | 243 | //creates default builder.yaml if it doesn't exist 244 | if os.Args[1] == "init" || os.Args[1] == "config" { 245 | repoPath := "./" + strings.TrimSuffix(utils.GetName(), ".git") 246 | 247 | if configPath != "" { 248 | repoPath = configPath + "/" + strings.TrimSuffix(utils.GetName(), ".git") 249 | } 250 | 251 | yaml.CreateBuilderYaml(repoPath) 252 | } else { 253 | yaml.CreateBuilderYaml(fullPath) 254 | } 255 | 256 | packageCArtifact(fullPath) 257 | 258 | spinner.LogMessage("C/C++ project compiled successfully.", "info") 259 | } 260 | 261 | func packageCArtifact(fullPath string) { 262 | archiveExt := "" 263 | 264 | if runtime.GOOS == "windows" { 265 | archiveExt = ".zip" 266 | } else { 267 | archiveExt = ".tar.gz" 268 | } 269 | 270 | artifact.ArtifactDir() 271 | artifactDir := os.Getenv("BUILDER_ARTIFACT_DIR") 272 | artifactList := os.Getenv("BUILDER_ARTIFACT_LIST") 273 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 274 | var artifactArray []string 275 | 276 | // If we were given an artifacts list, handle it 277 | if artifactList != "" { 278 | artifactArray = strings.Split(artifactList, ",") 279 | os.Setenv("BUILDER_ARTIFACT_NAMES", artifactList) 280 | 281 | //copy artifact(s), then remove artifact(s) from workspace 282 | for _, artifact := range artifactArray { 283 | err := cp.Copy(fullPath+"/"+artifact, artifactDir+"/"+artifact) 284 | if err != nil { 285 | spinner.LogMessage(err.Error(), "warn") 286 | } 287 | 288 | // If outputpath provided also cp artifacts to that location 289 | if outputPath != "" { 290 | // Check if outputPath exists. If not, create it 291 | if _, err := os.Stat(outputPath); os.IsNotExist(err) { 292 | if err := os.Mkdir(outputPath, 0755); err != nil { 293 | spinner.LogMessage("Could not create output path", "fatal") 294 | } 295 | } 296 | // exec.Command("cp", fullPath+"/"+artifact, outputPath).Run() 297 | err := cp.Copy(fullPath+"/"+artifact, outputPath+"/"+artifact) 298 | if err != nil { 299 | spinner.LogMessage(err.Error(), "warn") 300 | } 301 | 302 | spinner.LogMessage("Artifact(s) copied to output path provided", "info") 303 | } 304 | 305 | // exec.Command("rm", fullPath+"/"+artifact).Run() 306 | errRemove := os.Remove(fullPath + "/" + artifact) 307 | if errRemove != nil { 308 | spinner.LogMessage(errRemove.Error(), "warn") 309 | } 310 | } 311 | 312 | } else { 313 | var artifactExt string 314 | buildTool := strings.ToLower(os.Getenv("BUILDER_BUILD_TOOL")) 315 | //Determine artifact extension 316 | switch buildTool { 317 | case "make-rpm": 318 | artifactExt = "*.rpm" 319 | case "make-deb": 320 | artifactExt = "*.deb" 321 | case "make-tar": 322 | artifactExt = "*.tar.gz" 323 | case "make-lib": 324 | archiveExt = "*.lib" 325 | case "make-dll": 326 | archiveExt = "*.dll" 327 | default: 328 | artifactExt = "*.exe" 329 | } 330 | 331 | //find artifact(s) by extension 332 | // WalkMatch function defined in compile/c#.go 333 | artifactArray, _ = WalkMatch(fullPath, artifactExt) 334 | if len(artifactArray) == 0 { 335 | spinner.LogMessage("Could not find artifact(s). Please specify the name(s) in the artifactlist of the builder.yaml", "fatal") 336 | } 337 | 338 | var artifactNames []string 339 | 340 | //copy artifact(s), then remove artifact(s) from workspace 341 | for i := 0; i < len(artifactArray); i++ { 342 | artifactNames = append(artifactNames, filepath.Base(artifactArray[i])) 343 | 344 | err := cp.Copy(artifactArray[i], artifactDir+"/"+artifactNames[i]) 345 | if err != nil { 346 | spinner.LogMessage(err.Error(), "warn") 347 | } 348 | 349 | // If outputpath provided also cp artifacts to that location 350 | if outputPath != "" { 351 | // Check if outputPath exists. If not, create it 352 | if _, err := os.Stat(outputPath); os.IsNotExist(err) { 353 | if err := os.Mkdir(outputPath, 0755); err != nil { 354 | spinner.LogMessage("Could not create output path", "fatal") 355 | } 356 | } 357 | 358 | err := cp.Copy(artifactArray[i], outputPath+"/"+artifactNames[i]) 359 | if err != nil { 360 | spinner.LogMessage(err.Error(), "warn") 361 | } 362 | 363 | spinner.LogMessage("Artifact(s) copied to output path provided", "info") 364 | } 365 | 366 | errRemove := os.Remove(artifactArray[i]) 367 | if errRemove != nil { 368 | spinner.LogMessage(errRemove.Error(), "warn") 369 | } 370 | } 371 | 372 | os.Setenv("BUILDER_ARTIFACT_NAMES", strings.Join([]string(artifactNames), ",")) 373 | } 374 | 375 | //create metadata, then copy contents to zip dir 376 | utils.Metadata(artifactDir) 377 | 378 | if os.Getenv("ARTIFACT_ZIP_ENABLED") == "true" { 379 | //zip artifact 380 | artifact.ZipArtifactDir() 381 | 382 | //remove uncompressed artifacts 383 | for i := 0; i < len(artifactArray); i++ { 384 | err := os.Remove(artifactDir + "/" + filepath.Base(artifactArray[i])) 385 | if err != nil { 386 | spinner.LogMessage(err.Error(), "warn") 387 | } 388 | } 389 | 390 | // send artifact to user specified path or send to artifact directory 391 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 392 | if outputPath != "" { 393 | err := cp.Copy(artifactDir+archiveExt, outputPath+"/"+filepath.Base(artifactDir)+archiveExt) 394 | if err != nil { 395 | spinner.LogMessage(err.Error(), "warn") 396 | } 397 | } else { 398 | err := cp.Copy(artifactDir+archiveExt, artifactDir+"/"+filepath.Base(artifactDir)+archiveExt) 399 | if err != nil { 400 | spinner.LogMessage(err.Error(), "warn") 401 | } 402 | } 403 | 404 | errRemove := os.Remove(artifactDir + archiveExt) 405 | if errRemove != nil { 406 | spinner.LogMessage(errRemove.Error(), "warn") 407 | } 408 | } 409 | } 410 | -------------------------------------------------------------------------------- /compile/go.go: -------------------------------------------------------------------------------- 1 | // takes in code as arg from go 2 | //run go build on code given 3 | 4 | package compile 5 | 6 | import ( 7 | "Builder/artifact" 8 | "Builder/directory" 9 | "Builder/spinner" 10 | "Builder/utils" 11 | "Builder/utils/log" 12 | "Builder/yaml" 13 | "bufio" 14 | "os" 15 | "os/exec" 16 | "path/filepath" 17 | "runtime" 18 | "strings" 19 | "time" 20 | 21 | cp "github.com/otiai10/copy" 22 | "go.uber.org/zap" 23 | ) 24 | 25 | var locallogger *zap.Logger 26 | 27 | // Go creates exe from file passed in as arg 28 | func Go(filePath string) { 29 | 30 | //Set default project type env for builder.yaml creation 31 | projectType := os.Getenv("BUILDER_PROJECT_TYPE") 32 | if projectType == "" { 33 | os.Setenv("BUILDER_PROJECT_TYPE", "go") 34 | } 35 | 36 | //Set up local logger 37 | localPath, _ := os.LookupEnv("BUILDER_LOGS_DIR") 38 | locallogger, closeLocalLogger = log.NewLogger("logs", localPath) 39 | 40 | //define dir path for command to run in 41 | var fullPath string 42 | configPath := os.Getenv("BUILDER_DIR_PATH") 43 | //if user defined path in builder.yaml, full path is included already, else add curren dir + local path 44 | if os.Getenv("BUILDER_COMMAND") == "true" { 45 | // ex: C:/Users/Name/Projects/helloworld_19293/workspace/dir 46 | fullPath = filePath 47 | } else if configPath != "" { 48 | // ex: C:/Users/Name/Projects/helloworld_19293/workspace/dir 49 | fullPath = filePath 50 | } else { 51 | path, _ := os.Getwd() 52 | //combine local path to newly created tempWorkspace, 53 | //gets rid of "." in path name 54 | // ex: C:/Users/Name/Projects + /helloworld_19293/workspace/dir 55 | fullPath = path + filePath[strings.Index(filePath, ".")+1:] 56 | os.Setenv("BUILDER_DIR_PATH", path) 57 | } 58 | 59 | //////////////////////////////// 60 | // install dependencies/build // 61 | //////////////////////////////// 62 | 63 | //find 'go file' to be built 64 | buildFile := strings.ToLower(os.Getenv("BUILDER_BUILD_FILE")) 65 | buildCmd := os.Getenv("BUILDER_BUILD_COMMAND") 66 | 67 | //buildName = buildfile (get rid of ".go") + Unix timestamp 68 | var cmd *exec.Cmd 69 | if buildCmd != "" { 70 | //user specified cmd 71 | buildCmdArray := strings.Fields(buildCmd) 72 | cmd = exec.Command(buildCmdArray[0], buildCmdArray[1:]...) 73 | cmd.Dir = fullPath // or whatever directory it's in 74 | } else if buildFile != "" { 75 | cmd = exec.Command("go", "build", "-v", "-x", buildFile) 76 | cmd.Dir = fullPath // or whatever directory it's in 77 | os.Setenv("BUILDER_BUILD_COMMAND", "go build -v -x "+buildFile) 78 | } else { 79 | //default 80 | if runtime.GOOS != "windows" { 81 | cmd = exec.Command("go", "build", "-v", "-x", "-o", strings.TrimSuffix(utils.GetName(), ".git")) 82 | cmd.Dir = fullPath // or whatever directory it's in 83 | os.Setenv("BUILDER_BUILD_COMMAND", "go build -v -x -o "+strings.TrimSuffix(utils.GetName(), ".git")) 84 | } else { 85 | cmd = exec.Command("go", "build", "-v", "-x", "-o", strings.TrimSuffix(utils.GetName(), ".git")+".exe") 86 | cmd.Dir = fullPath // or whatever directory it's in 87 | os.Setenv("BUILDER_BUILD_COMMAND", "go build -v -x -o "+strings.TrimSuffix(utils.GetName(), ".git")+".exe") 88 | } 89 | } 90 | 91 | //run cmd, check for err, log cmd 92 | spinner.LogMessage("running command: "+cmd.String(), "info") 93 | 94 | stdout, pipeErr := cmd.StdoutPipe() 95 | if pipeErr != nil { 96 | spinner.LogMessage(pipeErr.Error(), "fatal") 97 | } 98 | 99 | cmd.Stderr = cmd.Stdout 100 | 101 | // Make a new channel which will be used to ensure we get all output 102 | done := make(chan struct{}) 103 | 104 | scanner := bufio.NewScanner(stdout) 105 | 106 | // Use the scanner to scan the output line by line and log it 107 | // It's running in a goroutine so that it doesn't block 108 | go func() { 109 | // Read line by line and process it 110 | for scanner.Scan() { 111 | line := scanner.Text() 112 | spinner.Spinner.Stop() 113 | locallogger.Info(line) 114 | spinner.Spinner.Start() 115 | } 116 | 117 | // We're all done, unblock the channel 118 | done <- struct{}{} 119 | 120 | }() 121 | 122 | os.Setenv("BUILD_START_TIME", time.Now().Format(time.RFC850)) 123 | 124 | if err := cmd.Start(); err != nil { 125 | spinner.LogMessage(err.Error(), "fatal") 126 | } 127 | 128 | // Wait for all output to be processed 129 | <-done 130 | 131 | // Wait for cmd to finish 132 | if err := cmd.Wait(); err != nil { 133 | spinner.LogMessage(err.Error(), "fatal") 134 | } 135 | 136 | os.Setenv("BUILD_END_TIME", time.Now().Format(time.RFC850)) 137 | 138 | // Close log file 139 | closeLocalLogger() 140 | 141 | // Update parent dir name to include start time 142 | fullPath = directory.UpdateParentDirName(fullPath) 143 | 144 | if os.Args[1] == "init" || os.Args[1] == "config" { 145 | repoPath := "./" + strings.TrimSuffix(utils.GetName(), ".git") 146 | 147 | if configPath != "" { 148 | repoPath = configPath + "/" + strings.TrimSuffix(utils.GetName(), ".git") 149 | } 150 | 151 | yaml.CreateBuilderYaml(repoPath) 152 | } else { 153 | yaml.CreateBuilderYaml(fullPath) 154 | } 155 | 156 | packageGoArtifact(fullPath) 157 | 158 | spinner.LogMessage("Go project built successfully.", "info") 159 | } 160 | 161 | func packageGoArtifact(fullPath string) { 162 | archiveExt := "" 163 | artifactExt := "" 164 | 165 | if runtime.GOOS == "windows" { 166 | archiveExt = ".zip" 167 | artifactExt = ".exe" 168 | } else { 169 | archiveExt = ".tar.gz" 170 | artifactExt = "executable" 171 | } 172 | 173 | artifact.ArtifactDir() 174 | artifactDir := os.Getenv("BUILDER_ARTIFACT_DIR") 175 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 176 | 177 | //find artifact by extension 178 | _, extName := artifact.ExtExistsFunction(fullPath, artifactExt) 179 | os.Setenv("BUILDER_ARTIFACT_NAMES", extName) 180 | 181 | //copy artifact, then remove artifact in workspace 182 | err := cp.Copy(fullPath+"/"+extName, artifactDir+"/"+extName) 183 | if err != nil { 184 | spinner.LogMessage(err.Error(), "warn") 185 | } 186 | 187 | // If outputpath provided also cp artifacts to that location 188 | if outputPath != "" { 189 | // Check if outputPath exists. If not, create it 190 | if _, err := os.Stat(outputPath); os.IsNotExist(err) { 191 | if err := os.Mkdir(outputPath, 0755); err != nil { 192 | spinner.LogMessage("Could not create output path", "fatal") 193 | } 194 | } 195 | 196 | err := cp.Copy(fullPath+"/"+extName, outputPath+"/"+extName) 197 | if err != nil { 198 | spinner.LogMessage(err.Error(), "warn") 199 | } 200 | 201 | spinner.LogMessage("Artifact(s) copied to output path provided", "info") 202 | } 203 | 204 | errRemove := os.Remove(fullPath + "/" + extName) 205 | if errRemove != nil { 206 | spinner.LogMessage(errRemove.Error(), "warn") 207 | } 208 | 209 | //create metadata 210 | utils.Metadata(artifactDir) 211 | 212 | if os.Getenv("ARTIFACT_ZIP_ENABLED") == "true" { 213 | //zip artifact 214 | artifact.ZipArtifactDir() 215 | 216 | //remove uncompressed artifact 217 | err := os.Remove(artifactDir + "/" + extName) 218 | if err != nil { 219 | spinner.LogMessage(err.Error(), "warn") 220 | } 221 | 222 | // send artifact to user specified path or send to artifact directory 223 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 224 | if outputPath != "" { 225 | err := cp.Copy(artifactDir+archiveExt, outputPath+"/"+filepath.Base(artifactDir)+archiveExt) 226 | if err != nil { 227 | spinner.LogMessage(err.Error(), "warn") 228 | } 229 | } else { 230 | err := cp.Copy(artifactDir+archiveExt, artifactDir+"/"+filepath.Base(artifactDir)+archiveExt) 231 | if err != nil { 232 | spinner.LogMessage(err.Error(), "warn") 233 | } 234 | } 235 | 236 | errRemove := os.Remove(artifactDir + archiveExt) 237 | if errRemove != nil { 238 | spinner.LogMessage(errRemove.Error(), "warn") 239 | } 240 | } 241 | } 242 | -------------------------------------------------------------------------------- /compile/java.go: -------------------------------------------------------------------------------- 1 | package compile 2 | 3 | import ( 4 | "Builder/artifact" 5 | "Builder/directory" 6 | "Builder/spinner" 7 | "Builder/utils" 8 | "Builder/utils/log" 9 | "Builder/yaml" 10 | "bufio" 11 | "os" 12 | "os/exec" 13 | "path/filepath" 14 | "runtime" 15 | "strings" 16 | "time" 17 | 18 | cp "github.com/otiai10/copy" 19 | ) 20 | 21 | // Java does ... 22 | func Java(filePath string) { 23 | //Set default project type env for builder.yaml creation 24 | projectType := os.Getenv("BUILDER_PROJECT_TYPE") 25 | if projectType == "" { 26 | os.Setenv("BUILDER_PROJECT_TYPE", "java") 27 | } 28 | 29 | //Set up local logger 30 | localPath, _ := os.LookupEnv("BUILDER_LOGS_DIR") 31 | locallogger, closeLocalLogger = log.NewLogger("logs", localPath) 32 | 33 | //define dir path for command to run in 34 | var fullPath string 35 | configPath := os.Getenv("BUILDER_DIR_PATH") 36 | //if user defined path in builder.yaml, full path is included already, else add curren dir + local path 37 | if os.Getenv("BUILDER_COMMAND") == "true" { 38 | // ex: C:/Users/Name/Projects/helloworld_19293/workspace/dir 39 | fullPath = filePath 40 | } else if configPath != "" { 41 | // ex: C:/Users/Name/Projects/helloworld_19293/workspace/dir 42 | fullPath = filePath 43 | } else { 44 | path, _ := os.Getwd() 45 | //combine local path to newly created tempWorkspace, 46 | //gets rid of "." in path name 47 | // ex: C:/Users/Name/Projects + /helloworld_19293/workspace/dir 48 | fullPath = path + filePath[strings.Index(filePath, ".")+1:] 49 | os.Setenv("BUILDER_DIR_PATH", path) 50 | 51 | } 52 | 53 | //install dependencies/build, if yaml build type exists install accordingly 54 | buildTool := strings.ToLower(os.Getenv("BUILDER_BUILD_TOOL")) 55 | buildCmd := os.Getenv("BUILDER_BUILD_COMMAND") 56 | 57 | var cmd *exec.Cmd 58 | if buildCmd != "" { 59 | //user specified cmd 60 | buildCmdArray := strings.Fields(buildCmd) 61 | cmd = exec.Command(buildCmdArray[0], buildCmdArray[1:]...) 62 | cmd.Dir = fullPath // or whatever directory it's in 63 | } else if buildTool == "maven" || buildTool == "mvn" { 64 | cmd = exec.Command("mvn", "clean", "install") 65 | cmd.Dir = fullPath // or whatever directory it's in 66 | os.Setenv("BUILDER_BUILD_COMMAND", "mvn clean install") 67 | } else if buildTool == "gradle" { 68 | // default for gradle 69 | cmd = exec.Command("gradle", "build") 70 | cmd.Dir = fullPath // or whatever directory it's in 71 | os.Setenv("BUILDER_BUILD_COMMAND", "gradle build") 72 | } else { 73 | //default 74 | cmd = exec.Command("mvn", "clean", "install") 75 | cmd.Dir = fullPath // or whatever directory it's in 76 | os.Setenv("BUILDER_BUILD_TOOL", "maven") 77 | os.Setenv("BUILDER_BUILD_COMMAND", "mvn clean install") 78 | } 79 | 80 | //run cmd, check for err, log cmd 81 | spinner.LogMessage("running command: "+cmd.String(), "info") 82 | 83 | stdout, pipeErr := cmd.StdoutPipe() 84 | if pipeErr != nil { 85 | spinner.LogMessage(pipeErr.Error(), "fatal") 86 | } 87 | 88 | cmd.Stderr = cmd.Stdout 89 | 90 | // Make a new channel which will be used to ensure we get all output 91 | done := make(chan struct{}) 92 | 93 | scanner := bufio.NewScanner(stdout) 94 | 95 | // Use the scanner to scan the output line by line and log it 96 | // It's running in a goroutine so that it doesn't block 97 | go func() { 98 | // Read line by line and process it 99 | for scanner.Scan() { 100 | line := scanner.Text() 101 | spinner.Spinner.Stop() 102 | locallogger.Info(line) 103 | spinner.Spinner.Start() 104 | } 105 | 106 | // We're all done, unblock the channel 107 | done <- struct{}{} 108 | 109 | }() 110 | 111 | os.Setenv("BUILD_START_TIME", time.Now().Format(time.RFC850)) 112 | 113 | if err := cmd.Start(); err != nil { 114 | spinner.LogMessage(err.Error(), "fatal") 115 | } 116 | 117 | // Wait for all output to be processed 118 | <-done 119 | 120 | // Wait for cmd to finish 121 | if err := cmd.Wait(); err != nil { 122 | spinner.LogMessage(err.Error(), "fatal") 123 | } 124 | 125 | os.Setenv("BUILD_END_TIME", time.Now().Format(time.RFC850)) 126 | 127 | // Close log file 128 | closeLocalLogger() 129 | 130 | // Update parent dir name to include start time and send back new full path 131 | fullPath = directory.UpdateParentDirName(fullPath) 132 | 133 | //creates default builder.yaml if it doesn't exist 134 | if os.Args[1] == "init" || os.Args[1] == "config" { 135 | repoPath := "./" + strings.TrimSuffix(utils.GetName(), ".git") 136 | 137 | if configPath != "" { 138 | repoPath = configPath + "/" + strings.TrimSuffix(utils.GetName(), ".git") 139 | } 140 | 141 | yaml.CreateBuilderYaml(repoPath) 142 | } else { 143 | yaml.CreateBuilderYaml(fullPath) 144 | } 145 | 146 | packageJavaArtifact(fullPath + "/target") 147 | 148 | spinner.LogMessage("Java project compiled successfully.", "info") 149 | } 150 | func packageJavaArtifact(fullPath string) { 151 | archiveExt := "" 152 | 153 | if runtime.GOOS == "windows" { 154 | archiveExt = ".zip" 155 | } else { 156 | archiveExt = ".tar.gz" 157 | } 158 | 159 | artifact.ArtifactDir() 160 | artifactDir := os.Getenv("BUILDER_ARTIFACT_DIR") 161 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 162 | 163 | //find artifact by extension 164 | _, extName := artifact.ExtExistsFunction(fullPath, ".jar") 165 | os.Setenv("BUILDER_ARTIFACT_NAMES", extName) 166 | 167 | //copy artifact, then remove artifact in workspace 168 | err := cp.Copy(fullPath+"/"+extName, artifactDir+"/"+extName) 169 | if err != nil { 170 | spinner.LogMessage(err.Error(), "warn") 171 | } 172 | 173 | // If outputpath provided also cp artifacts to that location 174 | if outputPath != "" { 175 | // Check if outputPath exists. If not, create it 176 | if _, err := os.Stat(outputPath); os.IsNotExist(err) { 177 | if err := os.Mkdir(outputPath, 0755); err != nil { 178 | spinner.LogMessage("Could not create output path", "fatal") 179 | } 180 | } 181 | 182 | err := cp.Copy(fullPath+"/"+extName, outputPath+"/"+extName) 183 | if err != nil { 184 | spinner.LogMessage(err.Error(), "warn") 185 | } 186 | 187 | spinner.LogMessage("Artifact(s) copied to output path provided", "info") 188 | } 189 | 190 | errRemove := os.Remove(fullPath + "/" + extName) 191 | if errRemove != nil { 192 | spinner.LogMessage(errRemove.Error(), "warn") 193 | } 194 | 195 | //create metadata, then copy contents to zip dir 196 | utils.Metadata(artifactDir) 197 | 198 | if os.Getenv("ARTIFACT_ZIP_ENABLED") == "true" { 199 | //zip artifact 200 | artifact.ZipArtifactDir() 201 | 202 | //remove uncompressed artifact 203 | err := os.Remove(artifactDir + "/" + extName) 204 | if err != nil { 205 | spinner.LogMessage(err.Error(), "warn") 206 | } 207 | 208 | // send artifact to user specified path or send to artifact directory 209 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 210 | if outputPath != "" { 211 | err := cp.Copy(artifactDir+archiveExt, outputPath+"/"+filepath.Base(artifactDir)+archiveExt) 212 | if err != nil { 213 | spinner.LogMessage(err.Error(), "warn") 214 | } 215 | } else { 216 | err := cp.Copy(artifactDir+archiveExt, artifactDir+"/"+filepath.Base(artifactDir)+archiveExt) 217 | if err != nil { 218 | spinner.LogMessage(err.Error(), "warn") 219 | } 220 | } 221 | 222 | errRemove := os.Remove(artifactDir + archiveExt) 223 | if errRemove != nil { 224 | spinner.LogMessage(errRemove.Error(), "warn") 225 | } 226 | } 227 | } 228 | -------------------------------------------------------------------------------- /compile/npm.go: -------------------------------------------------------------------------------- 1 | package compile 2 | 3 | import ( 4 | "Builder/artifact" 5 | "Builder/directory" 6 | "Builder/spinner" 7 | "Builder/utils" 8 | "Builder/utils/log" 9 | "Builder/yaml" 10 | "archive/zip" 11 | "bufio" 12 | "fmt" 13 | "os" 14 | "os/exec" 15 | "strconv" 16 | "strings" 17 | "time" 18 | 19 | cp "github.com/otiai10/copy" 20 | ) 21 | 22 | // Npm creates zip from files passed in as arg 23 | func Npm() { 24 | //Set default project type env for builder.yaml creation 25 | projectType := os.Getenv("BUILDER_PROJECT_TYPE") 26 | if projectType == "" { 27 | os.Setenv("BUILDER_PROJECT_TYPE", "node") 28 | } 29 | 30 | //Set up local logger 31 | localPath, _ := os.LookupEnv("BUILDER_LOGS_DIR") 32 | locallogger, closeLocalLogger = log.NewLogger("logs", localPath) 33 | 34 | hiddenDir := os.Getenv("BUILDER_HIDDEN_DIR") 35 | workspaceDir := os.Getenv("BUILDER_WORKSPACE_DIR") 36 | tempWorkspace := workspaceDir + "/temp/" 37 | //make temp dir 38 | os.Mkdir(tempWorkspace, 0755) 39 | 40 | //add hidden dir contents to temp dir, install dependencies 41 | err := cp.Copy(hiddenDir+"/.", tempWorkspace) 42 | if err != nil { 43 | spinner.LogMessage(err.Error(), "warn") 44 | } 45 | 46 | //define dir path for command to run 47 | var fullPath string 48 | configPath := os.Getenv("BUILDER_DIR_PATH") 49 | //if user defined path in builder.yaml, full path is included in tempWorkspace, else add the local path 50 | if os.Getenv("BUILDER_COMMAND") == "true" { 51 | // ex: C:/Users/Name/Projects/helloworld_19293/workspace/dir 52 | fullPath = tempWorkspace 53 | } else if configPath != "" { 54 | fullPath = tempWorkspace 55 | } else { 56 | path, _ := os.Getwd() 57 | //combine local path to newly created tempWorkspace, gets rid of "." in path name 58 | fullPath = path + tempWorkspace[strings.Index(tempWorkspace, ".")+1:] 59 | os.Setenv("BUILDER_DIR_PATH", path) 60 | } 61 | 62 | //install dependencies/build, if yaml build type exists install accordingly 63 | buildTool := strings.ToLower(os.Getenv("BUILDER_BUILD_TOOL")) 64 | buildCmd := os.Getenv("BUILDER_BUILD_COMMAND") 65 | 66 | var cmd *exec.Cmd 67 | if buildCmd != "" { 68 | //user specified cmd 69 | buildCmdArray := strings.Fields(buildCmd) 70 | cmd = exec.Command(buildCmdArray[0], buildCmdArray[1:]...) 71 | cmd.Dir = fullPath // or whatever directory it's in 72 | } else if buildTool == "npm" { 73 | cmd = exec.Command("npm", "install") 74 | cmd.Dir = fullPath // or whatever directory it's in 75 | os.Setenv("BUILDER_BUILD_COMMAND", "npm install") 76 | } else { 77 | //default 78 | cmd = exec.Command("npm", "install") 79 | cmd.Dir = fullPath // or whatever directory it's in 80 | os.Setenv("BUILDER_BUILD_TOOL", "npm") 81 | os.Setenv("BUILDER_BUILD_COMMAND", "npm install") 82 | } 83 | 84 | //run cmd, check for err, log cmd 85 | spinner.LogMessage("running command: "+cmd.String(), "info") 86 | 87 | stdout, pipeErr := cmd.StdoutPipe() 88 | if pipeErr != nil { 89 | spinner.LogMessage(pipeErr.Error(), "fatal") 90 | } 91 | 92 | cmd.Stderr = cmd.Stdout 93 | 94 | // Make a new channel which will be used to ensure we get all output 95 | done := make(chan struct{}) 96 | 97 | scanner := bufio.NewScanner(stdout) 98 | 99 | // Use the scanner to scan the output line by line and log it 100 | // It's running in a goroutine so that it doesn't block 101 | go func() { 102 | // Read line by line and process it 103 | for scanner.Scan() { 104 | line := scanner.Text() 105 | spinner.Spinner.Stop() 106 | locallogger.Info(line) 107 | spinner.Spinner.Start() 108 | } 109 | 110 | // We're all done, unblock the channel 111 | done <- struct{}{} 112 | 113 | }() 114 | 115 | os.Setenv("BUILD_START_TIME", time.Now().Format(time.RFC850)) 116 | 117 | if err := cmd.Start(); err != nil { 118 | spinner.LogMessage(err.Error(), "fatal") 119 | } 120 | 121 | // Wait for all output to be processed 122 | <-done 123 | 124 | // Wait for cmd to finish 125 | if err := cmd.Wait(); err != nil { 126 | spinner.LogMessage(err.Error(), "fatal") 127 | } 128 | 129 | os.Setenv("BUILD_END_TIME", time.Now().Format(time.RFC850)) 130 | 131 | // Close log file 132 | closeLocalLogger() 133 | 134 | // Update parent dir name to include start time and send back new full path 135 | fullPath = directory.UpdateParentDirName(fullPath) 136 | 137 | // Update vars because of parent dir name change 138 | workspaceDir = os.Getenv("BUILDER_WORKSPACE_DIR") 139 | tempWorkspace = workspaceDir + "/temp/" 140 | 141 | if os.Args[1] == "init" || os.Args[1] == "config" { 142 | repoPath := "./" + strings.TrimSuffix(utils.GetName(), ".git") 143 | 144 | if configPath != "" { 145 | repoPath = configPath + "/" + strings.TrimSuffix(utils.GetName(), ".git") 146 | } 147 | 148 | yaml.CreateBuilderYaml(repoPath) 149 | } else { 150 | yaml.CreateBuilderYaml(fullPath) 151 | } 152 | 153 | // CreateZip artifact dir with timestamp 154 | parsedStartTime, _ := time.Parse(time.RFC850, os.Getenv("BUILD_START_TIME")) 155 | timeBuildStarted := parsedStartTime.Unix() 156 | 157 | outFile, err := os.Create(workspaceDir + "/artifact_" + strconv.FormatInt(timeBuildStarted, 10) + ".zip") 158 | if err != nil { 159 | spinner.LogMessage("node-npm failed to get artifact: "+err.Error(), "fatal") 160 | } 161 | 162 | defer outFile.Close() 163 | 164 | // Create a new zip archive. 165 | w := zip.NewWriter(outFile) 166 | 167 | // Add files from temp dir to the archive. 168 | addNpmFiles(w, tempWorkspace, "") 169 | 170 | err = w.Close() 171 | if err != nil { 172 | spinner.LogMessage("node-npm project failed to compile: "+err.Error(), "fatal") 173 | } 174 | 175 | packageNpmArtifact(fullPath) 176 | // artifactPath := os.Getenv("BUILDER_OUTPUT_PATH") 177 | // fmt.Print(artifactPath) 178 | // if artifactPath != "" { 179 | // artifactZip := os.Getenv("BUILDER_ARTIFACT_STAMP") 180 | // fmt.Print(artifactZip) 181 | // exec.Command("cp", "-a", artifactZip+".zip", artifactPath).Run() 182 | // } 183 | spinner.LogMessage("node-npm project compiled successfully", "info") 184 | } 185 | 186 | func packageNpmArtifact(fullPath string) { 187 | // archiveExt := "" 188 | 189 | // if runtime.GOOS == "windows" { 190 | // archiveExt = ".zip" 191 | // } else { 192 | // archiveExt = ".tar.gz" 193 | // } 194 | 195 | artifact.ArtifactDir() 196 | artifactDir := os.Getenv("BUILDER_ARTIFACT_DIR") 197 | workspaceDir := os.Getenv("BUILDER_WORKSPACE_DIR") 198 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 199 | 200 | //find artifact by extension 201 | _, extName := artifact.ExtExistsFunction(workspaceDir, ".zip") 202 | os.Setenv("BUILDER_ARTIFACT_NAMES", extName) 203 | 204 | //copy artifact, then remove artifact in workspace 205 | err := cp.Copy(workspaceDir+"/"+extName, artifactDir+"/"+extName) 206 | if err != nil { 207 | spinner.LogMessage(err.Error(), "warn") 208 | } 209 | 210 | // If outputpath provided also cp artifacts to that location 211 | if outputPath != "" { 212 | // Check if outputPath exists. If not, create it 213 | if _, err := os.Stat(outputPath); os.IsNotExist(err) { 214 | if err := os.Mkdir(outputPath, 0755); err != nil { 215 | spinner.LogMessage("Could not create output path", "fatal") 216 | } 217 | } 218 | 219 | err := cp.Copy(workspaceDir+"/"+extName, outputPath+"/"+extName) 220 | if err != nil { 221 | spinner.LogMessage(err.Error(), "warn") 222 | } 223 | 224 | spinner.LogMessage("Artifact(s) copied to output path provided", "info") 225 | } 226 | 227 | errRemove := os.Remove(workspaceDir + "/" + extName) 228 | if errRemove != nil { 229 | spinner.LogMessage(errRemove.Error(), "warn") 230 | } 231 | 232 | //create metadata, then copy contents to zip dir 233 | utils.Metadata(artifactDir) 234 | 235 | // if os.Getenv("ARTIFACT_ZIP_ENABLED") == "true" { 236 | // //zip artifact 237 | // artifact.ZipArtifactDir() 238 | 239 | // //copy zip into open artifactDir, delete zip in workspace (keeps entire artifact contained) 240 | // exec.Command("cp", "-a", artifactDir+archiveExt, artifactDir).Run() 241 | // exec.Command("rm", artifactDir+archiveExt).Run() 242 | 243 | // // artifactName := artifact.NameArtifact(fullPath, extName) 244 | 245 | // // send artifact to user specified path or send to parent directory 246 | // artifactStamp := os.Getenv("BUILDER_ARTIFACT_STAMP") 247 | // outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 248 | // if outputPath != "" { 249 | // exec.Command("cp", "-a", artifactDir+"/"+artifactStamp+archiveExt, outputPath).Run() 250 | // } else { 251 | // exec.Command("cp", "-a", artifactDir+"/"+artifactStamp+archiveExt, os.Getenv("BUILDER_PARENT_DIR")).Run() 252 | // } 253 | 254 | // //remove artifact directory 255 | // exec.Command("rm", "-r", artifactDir).Run() 256 | // } 257 | } 258 | 259 | // recursively add files 260 | func addNpmFiles(w *zip.Writer, basePath, baseInZip string) { 261 | // If basePath includes old parent folder name, fix it before we start (necessary for symlinks) 262 | // projectName := utils.GetName() 263 | // parsedStartTime, _ := time.Parse(time.RFC850, os.Getenv("BUILD_START_TIME")) 264 | // timeBuildStarted := parsedStartTime.Unix() 265 | // oldParentName := projectName + "_" + projectName 266 | // newParentName := projectName + "_" + strconv.FormatInt(timeBuildStarted, 10) 267 | // if strings.Contains(basePath, oldParentName) { 268 | // basePath = strings.Replace(basePath, oldParentName, newParentName, 1) 269 | // } 270 | 271 | // Open the Directory 272 | files, err := os.ReadDir(basePath) 273 | if err != nil { 274 | fmt.Println("ReadDir err: " + err.Error()) 275 | } 276 | 277 | for _, file := range files { 278 | if !file.IsDir() { 279 | dat, err := os.ReadFile(basePath + file.Name()) 280 | if err != nil { 281 | // Check if file is symlink 282 | linkedFolder, erro := os.Readlink(basePath + file.Name()) 283 | if erro != nil { 284 | // can't read file or symlink 285 | fmt.Println("ReadFile err: " + erro.Error()) 286 | } 287 | 288 | // If symlink, copy all contents from symlinked directory to folder named after symlink 289 | addNpmFiles(w, linkedFolder, baseInZip+file.Name()+"/") 290 | } 291 | 292 | // Add some files to the archive. 293 | f, err := w.Create(baseInZip + file.Name()) 294 | if err != nil { 295 | fmt.Println(err) 296 | } 297 | _, err = f.Write(dat) 298 | if err != nil { 299 | fmt.Println(err) 300 | } 301 | } else if file.IsDir() { 302 | // Recurse 303 | newBase := basePath + file.Name() + "/" 304 | addNpmFiles(w, newBase, baseInZip+file.Name()+"/") 305 | } 306 | } 307 | } 308 | -------------------------------------------------------------------------------- /compile/python.go: -------------------------------------------------------------------------------- 1 | package compile 2 | 3 | import ( 4 | "Builder/artifact" 5 | "Builder/directory" 6 | "Builder/spinner" 7 | "Builder/utils" 8 | "Builder/utils/log" 9 | "Builder/yaml" 10 | "archive/zip" 11 | "bufio" 12 | "fmt" 13 | "io/ioutil" 14 | "os" 15 | "os/exec" 16 | "path/filepath" 17 | "runtime" 18 | "strconv" 19 | "strings" 20 | "time" 21 | 22 | cp "github.com/otiai10/copy" 23 | ) 24 | 25 | // Python creates zip from files passed in as arg 26 | func Python() { 27 | //Set default project type env for builder.yaml creation 28 | projectType := os.Getenv("BUILDER_PROJECT_TYPE") 29 | if projectType == "" { 30 | os.Setenv("BUILDER_PROJECT_TYPE", "python") 31 | } 32 | 33 | //Set up local logger 34 | localPath, _ := os.LookupEnv("BUILDER_LOGS_DIR") 35 | locallogger, closeLocalLogger = log.NewLogger("logs", localPath) 36 | 37 | //copies contents of .hidden to workspace 38 | hiddenDir := os.Getenv("BUILDER_HIDDEN_DIR") 39 | workspaceDir := os.Getenv("BUILDER_WORKSPACE_DIR") 40 | tempWorkspace := workspaceDir + "/temp/" 41 | //make temp dir 42 | os.Mkdir(tempWorkspace, 0755) 43 | 44 | //add hidden dir contents to temp dir, install dependencies 45 | err := cp.Copy(hiddenDir+"/.", tempWorkspace) 46 | if err != nil { 47 | spinner.LogMessage(err.Error(), "warn") 48 | } 49 | 50 | //define dir path for command to run 51 | var fullPath string 52 | configPath := os.Getenv("BUILDER_DIR_PATH") 53 | //if user defined path in builder.yaml, full path is included in tempWorkspace, else add the local path 54 | if os.Getenv("BUILDER_COMMAND") == "true" { 55 | // ex: C:/Users/Name/Projects/helloworld_19293/workspace/dir 56 | fullPath = tempWorkspace 57 | } else if configPath != "" { 58 | fullPath = tempWorkspace 59 | } else { 60 | path, _ := os.Getwd() 61 | //combine local path to newly created tempWorkspace, gets rid of "." in path name 62 | fullPath = path + tempWorkspace[strings.Index(tempWorkspace, ".")+1:] 63 | os.Setenv("BUILDER_DIR_PATH", path) 64 | } 65 | 66 | //install dependencies/build, if yaml build type exists install accordingly 67 | buildTool := strings.ToLower(os.Getenv("BUILDER_BUILD_TOOL")) 68 | buildCmd := os.Getenv("BUILDER_BUILD_COMMAND") 69 | 70 | var cmd *exec.Cmd 71 | if buildCmd != "" { 72 | //user specified cmd 73 | buildCmdArray := strings.Fields(buildCmd) 74 | cmd = exec.Command(buildCmdArray[0], buildCmdArray[1:]...) 75 | cmd.Dir = fullPath // or whatever directory it's in 76 | } else if buildTool == "pip" { 77 | cmd = exec.Command("pip3", "install", "-r", "requirements.txt", "-t", "requirements") 78 | cmd.Dir = fullPath // or whatever directory it's in 79 | os.Setenv("BUILDER_BUILD_COMMAND", "pip3 install -r requirements.txt -t requirements") 80 | } else { 81 | //default 82 | cmd = exec.Command("pip3", "install", "-r", "requirements.txt", "-t", "requirements") 83 | cmd.Dir = fullPath // or whatever directory it's in 84 | os.Setenv("BUILDER_BUILD_TOOL", "pip") 85 | os.Setenv("BUILDER_BUILD_COMMAND", "pip3 install -r requirements.txt -t requirements") 86 | } 87 | 88 | //run cmd, check for err, log cmd 89 | spinner.LogMessage("running command: "+cmd.String(), "info") 90 | 91 | stdout, pipeErr := cmd.StdoutPipe() 92 | if pipeErr != nil { 93 | spinner.LogMessage(pipeErr.Error(), "fatal") 94 | } 95 | 96 | cmd.Stderr = cmd.Stdout 97 | 98 | // Make a new channel which will be used to ensure we get all output 99 | done := make(chan struct{}) 100 | 101 | scanner := bufio.NewScanner(stdout) 102 | 103 | // Use the scanner to scan the output line by line and log it 104 | // It's running in a goroutine so that it doesn't block 105 | go func() { 106 | // Read line by line and process it 107 | for scanner.Scan() { 108 | line := scanner.Text() 109 | spinner.Spinner.Stop() 110 | locallogger.Info(line) 111 | spinner.Spinner.Start() 112 | } 113 | 114 | // We're all done, unblock the channel 115 | done <- struct{}{} 116 | 117 | }() 118 | 119 | os.Setenv("BUILD_START_TIME", time.Now().Format(time.RFC850)) 120 | 121 | if err := cmd.Start(); err != nil { 122 | spinner.LogMessage(err.Error(), "fatal") 123 | } 124 | 125 | // Wait for all output to be processed 126 | <-done 127 | 128 | // Wait for cmd to finish 129 | if err := cmd.Wait(); err != nil { 130 | spinner.LogMessage(err.Error(), "fatal") 131 | } 132 | 133 | os.Setenv("BUILD_END_TIME", time.Now().Format(time.RFC850)) 134 | 135 | // Close log file 136 | closeLocalLogger() 137 | 138 | // Update parent dir name to include start time and send back new full path 139 | fullPath = directory.UpdateParentDirName(fullPath) 140 | 141 | // Update vars because of parent dir name change 142 | workspaceDir = os.Getenv("BUILDER_WORKSPACE_DIR") 143 | tempWorkspace = workspaceDir + "/temp/" 144 | 145 | if os.Args[1] == "init" || os.Args[1] == "config" { 146 | repoPath := "./" + strings.TrimSuffix(utils.GetName(), ".git") 147 | 148 | if configPath != "" { 149 | repoPath = configPath + "/" + strings.TrimSuffix(utils.GetName(), ".git") 150 | } 151 | 152 | yaml.CreateBuilderYaml(repoPath) 153 | } else { 154 | yaml.CreateBuilderYaml(fullPath) 155 | } 156 | 157 | // CreateZip artifact dir with timestamp 158 | parsedStartTime, _ := time.Parse(time.RFC850, os.Getenv("BUILD_START_TIME")) 159 | timeBuildStarted := parsedStartTime.Unix() 160 | 161 | outFile, err := os.Create(workspaceDir + "/artifact_" + strconv.FormatInt(timeBuildStarted, 10) + ".zip") 162 | if err != nil { 163 | spinner.LogMessage("Python failed to get artifact: "+err.Error(), "fatal") 164 | } 165 | 166 | defer outFile.Close() 167 | 168 | // Create a new zip archive. 169 | w := zip.NewWriter(outFile) 170 | 171 | // Add files from temp dir to the archive. 172 | addPythonFiles(w, tempWorkspace, "") 173 | 174 | wErr := w.Close() 175 | if wErr != nil { 176 | spinner.LogMessage("Python project failed to compile: "+wErr.Error(), "fatal") 177 | } 178 | packagePythonArtifact(fullPath) 179 | 180 | // artifactPath := os.Getenv("BUILDER_OUTPUT_PATH") 181 | // if artifactPath != "" { 182 | // exec.Command("cp", "-a", workspaceDir+"/temp.zip", artifactPath).Run() 183 | // } 184 | spinner.LogMessage("Python project compiled successfully.", "info") 185 | } 186 | 187 | func packagePythonArtifact(fullPath string) { 188 | archiveExt := "" 189 | 190 | if runtime.GOOS == "windows" { 191 | archiveExt = ".zip" 192 | } else { 193 | archiveExt = ".tar.gz" 194 | } 195 | 196 | artifact.ArtifactDir() 197 | artifactDir := os.Getenv("BUILDER_ARTIFACT_DIR") 198 | workspaceDir := os.Getenv("BUILDER_WORKSPACE_DIR") 199 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 200 | 201 | //find artifact by extension 202 | _, extName := artifact.ExtExistsFunction(workspaceDir, ".zip") 203 | os.Setenv("BUILDER_ARTIFACT_NAMES", extName) 204 | 205 | //copy artifact, then remove artifact in workspace 206 | err := cp.Copy(workspaceDir+"/"+extName, artifactDir+"/"+extName) 207 | if err != nil { 208 | spinner.LogMessage(err.Error(), "warn") 209 | } 210 | 211 | // If outputpath provided also cp artifacts to that location 212 | if outputPath != "" { 213 | // Check if outputPath exists. If not, create it 214 | if _, err := os.Stat(outputPath); os.IsNotExist(err) { 215 | if err := os.Mkdir(outputPath, 0755); err != nil { 216 | spinner.LogMessage("Could not create output path", "fatal") 217 | } 218 | } 219 | 220 | err := cp.Copy(workspaceDir+"/"+extName, outputPath+"/"+extName) 221 | if err != nil { 222 | spinner.LogMessage(err.Error(), "warn") 223 | } 224 | 225 | spinner.LogMessage("Artifact(s) copied to output path provided", "info") 226 | } 227 | 228 | errRemove := os.Remove(workspaceDir + "/" + extName) 229 | if errRemove != nil { 230 | spinner.LogMessage(errRemove.Error(), "warn") 231 | } 232 | 233 | //create metadata, then copy contents to zip dir 234 | utils.Metadata(artifactDir) 235 | 236 | if os.Getenv("ARTIFACT_ZIP_ENABLED") == "true" { 237 | //zip artifact 238 | artifact.ZipArtifactDir() 239 | 240 | //remove uncompressed artifact 241 | err := os.Remove(artifactDir + "/" + extName) 242 | if err != nil { 243 | spinner.LogMessage(err.Error(), "warn") 244 | } 245 | 246 | // send artifact to user specified path or send to artifact directory 247 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 248 | if outputPath != "" { 249 | err := cp.Copy(artifactDir+archiveExt, outputPath+"/"+filepath.Base(artifactDir)+archiveExt) 250 | if err != nil { 251 | spinner.LogMessage(err.Error(), "warn") 252 | } 253 | } else { 254 | err := cp.Copy(artifactDir+archiveExt, artifactDir+"/"+filepath.Base(artifactDir)+archiveExt) 255 | if err != nil { 256 | spinner.LogMessage(err.Error(), "warn") 257 | } 258 | } 259 | 260 | errRemove := os.Remove(artifactDir + archiveExt) 261 | if errRemove != nil { 262 | spinner.LogMessage(errRemove.Error(), "warn") 263 | } 264 | } 265 | } 266 | 267 | // recursively add files 268 | func addPythonFiles(w *zip.Writer, basePath, baseInZip string) { 269 | // Open the Directory 270 | files, err := ioutil.ReadDir(basePath) 271 | if err != nil { 272 | fmt.Println(err) 273 | } 274 | 275 | for _, file := range files { 276 | if !file.IsDir() { 277 | dat, err := ioutil.ReadFile(basePath + file.Name()) 278 | if err != nil { 279 | fmt.Println(err) 280 | } 281 | 282 | // Add some files to the archive. 283 | f, err := w.Create(baseInZip + file.Name()) 284 | if err != nil { 285 | fmt.Println(err) 286 | } 287 | _, err = f.Write(dat) 288 | if err != nil { 289 | fmt.Println(err) 290 | } 291 | } else if file.IsDir() { 292 | 293 | // Recurse 294 | newBase := basePath + file.Name() + "/" 295 | addPythonFiles(w, newBase, baseInZip+file.Name()+"/") 296 | } 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /compile/ruby.go: -------------------------------------------------------------------------------- 1 | package compile 2 | 3 | import ( 4 | "Builder/artifact" 5 | "Builder/directory" 6 | "Builder/spinner" 7 | "Builder/utils" 8 | "Builder/utils/log" 9 | "Builder/yaml" 10 | "archive/zip" 11 | "bufio" 12 | "fmt" 13 | "io/ioutil" 14 | "os" 15 | "os/exec" 16 | "path/filepath" 17 | "runtime" 18 | "strconv" 19 | "strings" 20 | "time" 21 | 22 | cp "github.com/otiai10/copy" 23 | ) 24 | 25 | // Ruby creates zip from files passed in as arg 26 | func Ruby() { 27 | //Set default project type env for builder.yaml creation 28 | projectType := os.Getenv("BUILDER_PROJECT_TYPE") 29 | if projectType == "" { 30 | os.Setenv("BUILDER_PROJECT_TYPE", "ruby") 31 | } 32 | 33 | //Set up local logger 34 | localPath, _ := os.LookupEnv("BUILDER_LOGS_DIR") 35 | locallogger, closeLocalLogger = log.NewLogger("logs", localPath) 36 | 37 | hiddenDir := os.Getenv("BUILDER_HIDDEN_DIR") 38 | workspaceDir := os.Getenv("BUILDER_WORKSPACE_DIR") 39 | tempWorkspace := workspaceDir + "/temp/" 40 | //make temp dir 41 | os.Mkdir(tempWorkspace, 0755) 42 | 43 | //add hidden dir contents to temp dir, install dependencies 44 | err := cp.Copy(hiddenDir+"/.", tempWorkspace) 45 | if err != nil { 46 | spinner.LogMessage(err.Error(), "warn") 47 | } 48 | 49 | //define dir path for command to run 50 | var fullPath string 51 | configPath := os.Getenv("BUILDER_DIR_PATH") 52 | //if user defined path in builder.yaml, full path is included in tempWorkspace, else add the local path 53 | if os.Getenv("BUILDER_COMMAND") == "true" { 54 | // ex: C:/Users/Name/Projects/helloworld_19293/workspace/dir 55 | fullPath = tempWorkspace 56 | } else if configPath != "" { 57 | fullPath = tempWorkspace 58 | } else { 59 | path, _ := os.Getwd() 60 | //combine local path to newly created tempWorkspace, gets rid of "." in path name 61 | fullPath = path + tempWorkspace[strings.Index(tempWorkspace, ".")+1:] 62 | os.Setenv("BUILDER_DIR_PATH", path) 63 | } 64 | 65 | //install dependencies/build, if yaml build type exists install accordingly 66 | buildTool := strings.ToLower(os.Getenv("BUILDER_BUILD_TOOL")) 67 | buildCmd := os.Getenv("BUILDER_BUILD_COMMAND") 68 | 69 | var cmd *exec.Cmd 70 | if buildCmd != "" { 71 | //user specified cmd 72 | buildCmdArray := strings.Fields(buildCmd) 73 | cmd = exec.Command(buildCmdArray[0], buildCmdArray[1:]...) 74 | cmd.Dir = fullPath // or whatever directory it's in 75 | } else if buildTool == "bundler" { 76 | cmd = exec.Command("bundle", "install", "--path", "vendor/bundle") 77 | cmd.Dir = fullPath // or whatever directory it's in 78 | os.Setenv("BUILDER_BUILD_COMMAND", "bundle install --path vendor/bundle") 79 | } else { 80 | //default 81 | cmd = exec.Command("bundle", "install", "--path", "vendor/bundle") 82 | cmd.Dir = fullPath // or whatever directory it's in 83 | os.Setenv("BUILDER_BUILD_TOOL", "bundler") 84 | os.Setenv("BUILDER_BUILD_COMMAND", "bundle install --path vendor/bundle") 85 | } 86 | 87 | //run cmd, check for err, log cmd 88 | spinner.LogMessage("running command: "+cmd.String(), "info") 89 | 90 | stdout, pipeErr := cmd.StdoutPipe() 91 | if pipeErr != nil { 92 | spinner.LogMessage(pipeErr.Error(), "fatal") 93 | } 94 | 95 | cmd.Stderr = cmd.Stdout 96 | 97 | // Make a new channel which will be used to ensure we get all output 98 | done := make(chan struct{}) 99 | 100 | scanner := bufio.NewScanner(stdout) 101 | 102 | // Use the scanner to scan the output line by line and log it 103 | // It's running in a goroutine so that it doesn't block 104 | go func() { 105 | // Read line by line and process it 106 | for scanner.Scan() { 107 | line := scanner.Text() 108 | spinner.Spinner.Stop() 109 | locallogger.Info(line) 110 | spinner.Spinner.Start() 111 | } 112 | 113 | // We're all done, unblock the channel 114 | done <- struct{}{} 115 | 116 | }() 117 | 118 | os.Setenv("BUILD_START_TIME", time.Now().Format(time.RFC850)) 119 | 120 | if err := cmd.Start(); err != nil { 121 | spinner.LogMessage(err.Error(), "fatal") 122 | } 123 | 124 | // Wait for all output to be processed 125 | <-done 126 | 127 | // Wait for cmd to finish 128 | if err := cmd.Wait(); err != nil { 129 | spinner.LogMessage(err.Error(), "fatal") 130 | } 131 | 132 | os.Setenv("BUILD_END_TIME", time.Now().Format(time.RFC850)) 133 | 134 | // Close log file 135 | closeLocalLogger() 136 | 137 | // Update parent dir name to include start time and send back new full path 138 | fullPath = directory.UpdateParentDirName(fullPath) 139 | 140 | // Update vars because of parent dir name change 141 | // hiddenDir = os.Getenv("BUILDER_HIDDEN_DIR") 142 | workspaceDir = os.Getenv("BUILDER_WORKSPACE_DIR") 143 | tempWorkspace = workspaceDir + "/temp/" 144 | 145 | if os.Args[1] == "init" || os.Args[1] == "config" { 146 | repoPath := "./" + strings.TrimSuffix(utils.GetName(), ".git") 147 | 148 | if configPath != "" { 149 | repoPath = configPath + "/" + strings.TrimSuffix(utils.GetName(), ".git") 150 | } 151 | 152 | yaml.CreateBuilderYaml(repoPath) 153 | } else { 154 | yaml.CreateBuilderYaml(fullPath) 155 | } 156 | 157 | //CreateZip artifact dir with timestamp 158 | parsedStartTime, _ := time.Parse(time.RFC850, os.Getenv("BUILD_START_TIME")) 159 | timeBuildStarted := parsedStartTime.Unix() 160 | 161 | outFile, err := os.Create(workspaceDir + "/artifact_" + strconv.FormatInt(timeBuildStarted, 10) + ".zip") 162 | if err != nil { 163 | spinner.LogMessage("Ruby failed to get artifact: "+err.Error(), "fatal") 164 | } 165 | 166 | defer outFile.Close() 167 | 168 | // Create a new zip archive. 169 | w := zip.NewWriter(outFile) 170 | 171 | // Add files from temp dir to the archive. 172 | addRubyFiles(w, tempWorkspace, "") 173 | 174 | err = w.Close() 175 | if err != nil { 176 | spinner.LogMessage("Ruby project failed to compile: "+err.Error(), "fatal") 177 | } 178 | packageRubyArtifact(fullPath) 179 | 180 | // artifactPath := os.Getenv("BUILDER_OUTPUT_PATH") 181 | // if artifactPath != "" { 182 | // exec.Command("cp", "-a", workspaceDir+"/temp.zip", artifactPath).Run() 183 | // } 184 | spinner.LogMessage("Ruby project compiled successfully.", "info") 185 | } 186 | 187 | func packageRubyArtifact(fullPath string) { 188 | archiveExt := "" 189 | 190 | if runtime.GOOS == "windows" { 191 | archiveExt = ".zip" 192 | } else { 193 | archiveExt = ".tar.gz" 194 | } 195 | 196 | artifact.ArtifactDir() 197 | artifactDir := os.Getenv("BUILDER_ARTIFACT_DIR") 198 | workspaceDir := os.Getenv("BUILDER_WORKSPACE_DIR") 199 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 200 | 201 | //find artifact by extension 202 | _, extName := artifact.ExtExistsFunction(workspaceDir, ".zip") 203 | os.Setenv("BUILDER_ARTIFACT_NAMES", extName) 204 | 205 | //copy artifact, then remove artifact in workspace 206 | err := cp.Copy(workspaceDir+"/"+extName, artifactDir+"/"+extName) 207 | if err != nil { 208 | spinner.LogMessage(err.Error(), "warn") 209 | } 210 | 211 | // If outputpath provided also cp artifacts to that location 212 | if outputPath != "" { 213 | // Check if outputPath exists. If not, create it 214 | if _, err := os.Stat(outputPath); os.IsNotExist(err) { 215 | if err := os.Mkdir(outputPath, 0755); err != nil { 216 | spinner.LogMessage("Could not create output path", "fatal") 217 | } 218 | } 219 | 220 | err := cp.Copy(workspaceDir+"/"+extName, outputPath+"/"+extName) 221 | if err != nil { 222 | spinner.LogMessage(err.Error(), "warn") 223 | } 224 | 225 | spinner.LogMessage("Artifact(s) copied to output path provided", "info") 226 | } 227 | 228 | errRemove := os.Remove(workspaceDir + "/" + extName) 229 | if errRemove != nil { 230 | spinner.LogMessage(errRemove.Error(), "warn") 231 | } 232 | 233 | //create metadata, then copy contents to zip dir 234 | utils.Metadata(artifactDir) 235 | 236 | if os.Getenv("ARTIFACT_ZIP_ENABLED") == "true" { 237 | //zip artifact 238 | artifact.ZipArtifactDir() 239 | 240 | //remove uncompressed artifact 241 | err := os.Remove(artifactDir + "/" + extName) 242 | if err != nil { 243 | spinner.LogMessage(err.Error(), "warn") 244 | } 245 | 246 | // send artifact to user specified path or send to artifact directory 247 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 248 | if outputPath != "" { 249 | err := cp.Copy(artifactDir+archiveExt, outputPath+"/"+filepath.Base(artifactDir)+archiveExt) 250 | if err != nil { 251 | spinner.LogMessage(err.Error(), "warn") 252 | } 253 | } else { 254 | err := cp.Copy(artifactDir+archiveExt, artifactDir+"/"+filepath.Base(artifactDir)+archiveExt) 255 | if err != nil { 256 | spinner.LogMessage(err.Error(), "warn") 257 | } 258 | } 259 | 260 | errRemove := os.Remove(artifactDir + archiveExt) 261 | if errRemove != nil { 262 | spinner.LogMessage(errRemove.Error(), "warn") 263 | } 264 | } 265 | } 266 | 267 | // recursively add files 268 | func addRubyFiles(w *zip.Writer, basePath, baseInZip string) { 269 | // Open the Directory 270 | files, err := ioutil.ReadDir(basePath) 271 | if err != nil { 272 | fmt.Println(err) 273 | } 274 | 275 | for _, file := range files { 276 | if !file.IsDir() { 277 | dat, err := ioutil.ReadFile(basePath + file.Name()) 278 | if err != nil { 279 | fmt.Println(err) 280 | } 281 | 282 | // Add some files to the archive. 283 | f, err := w.Create(baseInZip + file.Name()) 284 | if err != nil { 285 | fmt.Println(err) 286 | } 287 | _, err = f.Write(dat) 288 | if err != nil { 289 | fmt.Println(err) 290 | } 291 | } else if file.IsDir() { 292 | 293 | // Recurse 294 | newBase := basePath + file.Name() + "/" 295 | addRubyFiles(w, newBase, baseInZip+file.Name()+"/") 296 | } 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /compile/rust.go: -------------------------------------------------------------------------------- 1 | // takes in code as arg from rust 2 | //run rust build on code given 3 | 4 | package compile 5 | 6 | import ( 7 | "Builder/artifact" 8 | "Builder/directory" 9 | "Builder/spinner" 10 | "Builder/utils" 11 | "Builder/utils/log" 12 | "Builder/yaml" 13 | "bufio" 14 | "os" 15 | "os/exec" 16 | "runtime" 17 | "strings" 18 | "time" 19 | ) 20 | 21 | // Rust creates exe from file passed in as arg 22 | func Rust(filePath string) { 23 | 24 | //Set default project type env for builder.yaml creation 25 | projectType := os.Getenv("BUILDER_PROJECT_TYPE") 26 | if projectType == "" { 27 | os.Setenv("BUILDER_PROJECT_TYPE", "rust") 28 | } 29 | 30 | //Set up local logger 31 | localPath, _ := os.LookupEnv("BUILDER_LOGS_DIR") 32 | locallogger, closeLocalLogger = log.NewLogger("logs", localPath) 33 | 34 | //define dir path for command to run in 35 | var fullPath string 36 | configPath := os.Getenv("BUILDER_DIR_PATH") 37 | //if user defined path in builder.yaml, full path is included already, else add curren dir + local path 38 | if os.Getenv("BUILDER_COMMAND") == "true" { 39 | fullPath = filePath 40 | } else if configPath != "" { 41 | // ex: C:/Users/Name/Projects/helloworld_19293/workspace/dir 42 | fullPath = filePath 43 | } else { 44 | path, _ := os.Getwd() 45 | //combine local path to newly created tempWorkspace, 46 | //gets rid of "." in path name 47 | // ex: C:/Users/Name/Projects + /helloworld_19293/workspace/dir 48 | fullPath = path + filePath[strings.Index(filePath, ".")+1:] 49 | os.Setenv("BUILDER_DIR_PATH", path) 50 | } 51 | 52 | //install dependencies/build, if yaml build type exists install accordingly 53 | buildTool := strings.ToLower(os.Getenv("BUILDER_BUILD_TOOL")) 54 | //find 'rs file' to be built 55 | buildFile := os.Getenv("BUILDER_BUILD_FILE") 56 | buildCmd := os.Getenv("BUILDER_BUILD_COMMAND") 57 | //if no file defined by user, use default Cargo.toml 58 | if buildFile == "" { 59 | buildFile = "Cargo.toml" 60 | os.Setenv("BUILDER_BUILD_FILE", buildFile) 61 | } 62 | 63 | //buildName = buildfile (get rid of ".rs") + Unix timestamp 64 | var cmd *exec.Cmd 65 | if buildCmd != "" { 66 | //user specified cmd 67 | buildCmdArray := strings.Fields(buildCmd) 68 | cmd = exec.Command(buildCmdArray[0], buildCmdArray[1:]...) 69 | cmd.Dir = fullPath // or whatever directory it's in 70 | } else if buildTool == "rust" { 71 | cmd = exec.Command("cargo", "build", "-r") 72 | cmd.Dir = fullPath // or whatever directory it's in 73 | os.Setenv("BUILDER_BUILD_COMMAND", "cargo build -r") 74 | } else { 75 | cmd = exec.Command("cargo", "build", "-r") 76 | cmd.Dir = fullPath // or whatever directory it's in 77 | os.Setenv("BUILDER_BUILD_COMMAND", "cargo build -r") 78 | os.Setenv("BUILDER_BUILD_TOOL", "rust") 79 | } 80 | 81 | //run cmd, check for err, log cmd 82 | spinner.LogMessage("running command: "+cmd.String(), "info") 83 | 84 | stdout, pipeErr := cmd.StdoutPipe() 85 | if pipeErr != nil { 86 | spinner.LogMessage(pipeErr.Error(), "fatal") 87 | } 88 | 89 | cmd.Stderr = cmd.Stdout 90 | 91 | // Make a new channel which will be used to ensure we get all output 92 | done := make(chan struct{}) 93 | 94 | scanner := bufio.NewScanner(stdout) 95 | 96 | // Use the scanner to scan the output line by line and log it 97 | // It's running in a goroutine so that it doesn't block 98 | go func() { 99 | // Read line by line and process it 100 | for scanner.Scan() { 101 | line := scanner.Text() 102 | spinner.Spinner.Stop() 103 | locallogger.Info(line) 104 | spinner.Spinner.Start() 105 | } 106 | 107 | // We're all done, unblock the channel 108 | done <- struct{}{} 109 | 110 | }() 111 | 112 | os.Setenv("BUILD_START_TIME", time.Now().Format(time.RFC850)) 113 | 114 | if err := cmd.Start(); err != nil { 115 | spinner.LogMessage(err.Error(), "fatal") 116 | } 117 | 118 | // Wait for all output to be processed 119 | <-done 120 | 121 | // Wait for cmd to finish 122 | if err := cmd.Wait(); err != nil { 123 | spinner.LogMessage(err.Error(), "fatal") 124 | } 125 | 126 | os.Setenv("BUILD_END_TIME", time.Now().Format(time.RFC850)) 127 | 128 | // Close log file 129 | closeLocalLogger() 130 | 131 | // Update parent dir name to include start time 132 | fullPath = directory.UpdateParentDirName(fullPath) 133 | 134 | if os.Args[1] == "init" || os.Args[1] == "config" { 135 | repoPath := "./" + strings.TrimSuffix(utils.GetName(), ".git") 136 | 137 | if configPath != "" { 138 | repoPath = configPath + "/" + strings.TrimSuffix(utils.GetName(), ".git") 139 | } 140 | 141 | yaml.CreateBuilderYaml(repoPath) 142 | } else { 143 | yaml.CreateBuilderYaml(fullPath) 144 | } 145 | 146 | packageRustArtifact(fullPath) 147 | 148 | spinner.LogMessage("Rust project built successfully.", "info") 149 | } 150 | 151 | func packageRustArtifact(fullPath string) { 152 | archiveExt := "" 153 | artifactExt := "" 154 | if runtime.GOOS == "windows" { 155 | archiveExt = ".zip" 156 | artifactExt = ".exe" 157 | } else { 158 | archiveExt = ".tar.gz" 159 | artifactExt = "" 160 | } 161 | 162 | artifact.ArtifactDir() 163 | artifactDir := os.Getenv("BUILDER_ARTIFACT_DIR") 164 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 165 | artifactList := os.Getenv("BUILDER_ARTIFACT_LIST") 166 | 167 | if artifactList != "" { 168 | os.Setenv("BUILDER_ARTIFACT_NAMES", artifactList) 169 | } else { 170 | extName := "" 171 | tomlfile, _ := os.Open(fullPath + "/" + os.Getenv("BUILDER_BUILD_FILE")) 172 | scanner := bufio.NewScanner(tomlfile) 173 | for scanner.Scan() { 174 | line := scanner.Text() 175 | if strings.HasPrefix(line, "name = ") { 176 | extName = strings.ReplaceAll(line[7:]+artifactExt, "\"", "") 177 | } 178 | } 179 | defer tomlfile.Close() 180 | os.Setenv("BUILDER_ARTIFACT_NAMES", extName) 181 | artifactList = extName 182 | 183 | } 184 | artifactArray := strings.Split(artifactList, ",") 185 | if len(artifactArray) == 0 { 186 | spinner.LogMessage("Could not find artifact(s). Please specify the name(s) in the artifactlist of the builder.yaml", "fatal") 187 | } 188 | 189 | //copy artifact(s), then remove artifact(s) from workspace 190 | for _, artifact := range artifactArray { 191 | exec.Command("cp", "-a", fullPath+"/target/release/"+artifact, artifactDir).Run() 192 | 193 | // If outputpath provided also cp artifacts to that location 194 | if outputPath != "" { 195 | // Check if outputPath exists. If not, create it 196 | if _, err := os.Stat(outputPath); os.IsNotExist(err) { 197 | if err := os.Mkdir(outputPath, 0755); err != nil { 198 | spinner.LogMessage("Could not create output path", "fatal") 199 | } 200 | } 201 | 202 | exec.Command("cp", "-a", fullPath+"/target/release/"+artifact, outputPath).Run() 203 | 204 | spinner.LogMessage("Artifact(s) copied to output path provided", "info") 205 | } 206 | 207 | exec.Command("rm", fullPath+"/target/release/"+artifact).Run() 208 | } 209 | 210 | //create metadata 211 | utils.Metadata(artifactDir) 212 | 213 | if os.Getenv("ARTIFACT_ZIP_ENABLED") == "true" { 214 | //zip artifact 215 | artifact.ZipArtifactDir() 216 | 217 | //copy zip into open artifactDir, delete zip in workspace (keeps entire artifact contained) 218 | exec.Command("cp", "-a", artifactDir+archiveExt, artifactDir).Run() 219 | exec.Command("rm", artifactDir+archiveExt).Run() 220 | 221 | // send artifact to user specified path or send to parent directory 222 | artifactStamp := os.Getenv("BUILDER_ARTIFACT_STAMP") 223 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 224 | if outputPath != "" { 225 | exec.Command("cp", "-a", artifactDir+"/"+artifactStamp+archiveExt, outputPath).Run() 226 | } else { 227 | exec.Command("cp", "-a", artifactDir+"/"+artifactStamp+archiveExt, os.Getenv("BUILDER_PARENT_DIR")).Run() 228 | } 229 | 230 | //remove artifact directory 231 | exec.Command("rm", "-r", artifactDir).Run() 232 | } 233 | } 234 | -------------------------------------------------------------------------------- /derive/derive.go: -------------------------------------------------------------------------------- 1 | package derive 2 | 3 | import ( 4 | "Builder/compile" 5 | "Builder/spinner" 6 | "Builder/utils" 7 | "fmt" 8 | "os" 9 | "os/exec" 10 | "path/filepath" 11 | "strings" 12 | 13 | "github.com/manifoldco/promptui" 14 | ) 15 | 16 | // ProjectType will derive the project type and execute its compiler 17 | func ProjectType() { 18 | 19 | //check for user defined project type from builder.yaml to define string array files 20 | configType := strings.ToLower(os.Getenv("BUILDER_PROJECT_TYPE")) 21 | 22 | var files []string 23 | //projectType exists in builder.yaml 24 | if configType != "" { 25 | //check value of config type, return string array of language's build file/files 26 | files = utils.ConfigDerive() 27 | } else { 28 | //default 29 | files = []string{"main.go", "Cargo.toml", "package.json", "pom.xml", "gemfile.lock", "gemfile", "requirements.txt", "Makefile", "Makefile.am"} 30 | } 31 | 32 | var filePath string 33 | 34 | //look for those files inside hidden dir 35 | for _, file := range files { 36 | //recursively check for file in hidden dir, return path if found 37 | filePath = findPath(file) 38 | //double check it exists 39 | fileExists, err := fileExistsInDir(filePath) 40 | if err != nil { 41 | spinner.LogMessage("No Go, Rust, Npm, Ruby, Python, C/C++ or Java File Exists: "+err.Error(), "fatal") 42 | } 43 | 44 | //if file exists and filePath isn't empty, run conditional to find correct compiler 45 | if fileExists && filePath != "" && filePath != "./" { 46 | if file == "main.go" || configType == "go" { 47 | //executes go compiler 48 | finalPath := createFinalPath(filePath, file) 49 | utils.CopyDir() 50 | spinner.LogMessage("Go project detected", "info") 51 | compile.Go(finalPath) 52 | return 53 | } else if file == "Cargo.toml" || configType == "rust" { 54 | //executes go compiler 55 | finalPath := createFinalPath(filePath, file) 56 | utils.CopyDir() 57 | spinner.LogMessage("Rust project detected", "info") 58 | compile.Rust(finalPath) 59 | return 60 | } else if file == "package.json" || configType == "node" || configType == "npm" { 61 | //executes node compiler 62 | spinner.LogMessage("Npm project detected", "info") 63 | compile.Npm() 64 | return 65 | } else if file == "pom.xml" || configType == "java" { 66 | //executes java compiler 67 | finalPath := createFinalPath(filePath, file) 68 | 69 | utils.CopyDir() 70 | spinner.LogMessage("Java project detected", "info") 71 | 72 | compile.Java(finalPath) 73 | return 74 | } else if file == "gemfile.lock" || file == "gemfile" || configType == "ruby" { 75 | //executes ruby compiler 76 | spinner.LogMessage("Ruby project detected", "info") 77 | compile.Ruby() 78 | return 79 | } else if file == "requirements.txt" || configType == "python" { 80 | //executes python compiler 81 | spinner.LogMessage("Python project detected", "info") 82 | compile.Python() 83 | return 84 | } else if file == "Makefile" || file == "Makefile.am" || configType == "c" || configType == "c++" { 85 | //executes c compiler 86 | finalPath := createFinalPath(filePath, file) 87 | 88 | utils.CopyDir() 89 | spinner.LogMessage("C/C++ project detected", "info") 90 | 91 | compile.C(finalPath) 92 | return 93 | } 94 | } 95 | } 96 | deriveProjectByExtension() 97 | 98 | // If filePath not returned file was not found, let user know 99 | if filePath == "" { 100 | spinner.LogMessage("Could not find build file. Please specify build file and project type in the builder.yaml", "fatal") 101 | } 102 | } 103 | 104 | // derive projects by Extensions 105 | func deriveProjectByExtension() { 106 | var dirPathExtToFound string 107 | if os.Getenv("BUILDER_COMMAND") == "true" { 108 | path, _ := os.Getwd() 109 | dirPathExtToFound = path 110 | } else { 111 | dirPathExtToFound = os.Getenv("BUILDER_HIDDEN_DIR") 112 | } 113 | extensions := []string{".csproj", ".sln"} 114 | 115 | for _, ext := range extensions { 116 | extFound, fileName := extExistsFunction(dirPathExtToFound, ext) 117 | 118 | if extFound { 119 | switch ext { 120 | //checks if ext exists, if it's .csprocj it will pass down the filePath to c# compiler 121 | case ".csproj": 122 | filePath := strings.Replace(findPath(fileName), ".hidden", "workspace", 1) 123 | 124 | if os.Getenv("BUILDER_COMMAND") != "true" { 125 | utils.CopyDir() 126 | } 127 | spinner.LogMessage("C# project detected, Ext .csproj", "info") 128 | compile.CSharp(filePath) 129 | 130 | //if it's .sln, it will find all the project path in the solution(repo) 131 | case ".sln": 132 | filePath := strings.Replace(findPath(fileName), ".hidden", "workspace", 1) 133 | utils.CopyDir() 134 | listOfProjects, err := exec.Command("dotnet", "sln", filePath, "list").Output() 135 | 136 | if err != nil { 137 | spinner.LogMessage("dotnet sln failed: "+err.Error(), "fatal") 138 | } 139 | 140 | stringifyListOfProjects := string(listOfProjects) 141 | listOfProjectsArray := strings.Split(stringifyListOfProjects, "\n")[2:] 142 | //if there's more than 5 projects in solution(repo), user will be asked to use builder config instead 143 | if len(listOfProjectsArray) > 5 { 144 | spinner.LogMessage("There is more than 5 projects in this solution, please use Builder Config and specify the path of your file you wish to compile in the builder.yml", "fatal") 145 | } else { 146 | // < 5 projects in solution(repo), user will be prompt to choose a project path. 147 | pathToCompileFrom := selectPathToCompileFrom(listOfProjectsArray) 148 | workspace := os.Getenv("BUILDER_WORKSPACE_DIR") 149 | pathToCompileFrom = workspace + "/" + pathToCompileFrom 150 | 151 | utils.CopyDir() 152 | spinner.LogMessage("C# project detected, Ext .sln", "info") 153 | compile.CSharp(pathToCompileFrom) 154 | 155 | } 156 | } 157 | } 158 | } 159 | 160 | } 161 | 162 | // takes in file, searches hiddenDir to find a match and returns path to file 163 | func findPath(file string) string { 164 | 165 | var dirPath string 166 | if os.Getenv("BUILDER_COMMAND") == "true" { 167 | currentDir, _ := os.Getwd() 168 | dirPath = currentDir 169 | } else { 170 | dirPath = os.Getenv("BUILDER_HIDDEN_DIR") 171 | } 172 | 173 | // if f.Name is == to file passed in "coolProject.go", filePath becomes the path that file exists in 174 | var filePath string 175 | // Check top level dir for file first before checking subdirs 176 | files, err := os.ReadDir(dirPath) 177 | if err != nil { 178 | spinner.LogMessage(err.Error(), "fatal") 179 | } 180 | 181 | for _, f := range files { 182 | if strings.EqualFold(f.Name(), file) { 183 | filePath = dirPath 184 | } 185 | } 186 | 187 | // If file not found in top level dir check subdirs 188 | if filePath == "" { 189 | err = filepath.Walk(dirPath, func(path string, f os.FileInfo, err error) error { 190 | if strings.EqualFold(f.Name(), file) { 191 | filePath = path 192 | } 193 | return err 194 | }) 195 | } 196 | 197 | if err != nil { 198 | spinner.LogMessage("Could not find build file. Please specify build file and project type in the builder.yaml: "+err.Error(), "fatal") 199 | } 200 | 201 | configPath := os.Getenv("BUILDER_DIR_PATH") 202 | //if user defined path in builder.yaml, filePath has fullPath included, if not, run it locally 203 | if os.Getenv("BUILDER_COMMAND") == "true" { 204 | return filePath 205 | } else if configPath != "" { 206 | return filePath 207 | } else { 208 | return "./" + filePath 209 | } 210 | } 211 | 212 | // changes .hidden to workspace for langs that produce binary, get's rid of file name in path 213 | func createFinalPath(path string, file string) string { 214 | workFilePath := strings.Replace(path, ".hidden", "workspace", 1) 215 | finalPath := strings.Replace(workFilePath, file, "", -1) 216 | 217 | return finalPath 218 | } 219 | 220 | // checks if file exists 221 | func fileExistsInDir(path string) (bool, error) { 222 | //file exists 223 | _, err := os.Stat(path) 224 | //return true 225 | if err == nil { 226 | return true, nil 227 | } 228 | //return false 229 | if os.IsNotExist(err) { 230 | return false, nil 231 | } 232 | return false, err 233 | } 234 | 235 | func extExistsFunction(dirPath string, ext string) (bool, string) { 236 | found := false 237 | 238 | d, err := os.Open(dirPath) 239 | if err != nil { 240 | fmt.Println(err) 241 | os.Exit(1) 242 | } 243 | defer d.Close() 244 | 245 | files, err := d.Readdir(-1) 246 | if err != nil { 247 | fmt.Println(err) 248 | os.Exit(1) 249 | } 250 | 251 | var fileName string 252 | 253 | for _, file := range files { 254 | if file.Mode().IsRegular() { 255 | if filepath.Ext(file.Name()) == ext { 256 | fileName = file.Name() 257 | found = true 258 | } 259 | } 260 | } 261 | 262 | return found, fileName 263 | } 264 | 265 | func selectPathToCompileFrom(filePaths []string) string { 266 | prompt := promptui.Select{ 267 | Label: "Select a Path To Compile From: ", 268 | Items: filePaths, 269 | } 270 | _, result, err := prompt.Run() 271 | if err != nil { 272 | spinner.LogMessage("Prompt failed "+err.Error()+"\n", "fatal") 273 | } 274 | 275 | return result 276 | } 277 | -------------------------------------------------------------------------------- /directory/builder.go: -------------------------------------------------------------------------------- 1 | package directory 2 | 3 | import ( 4 | "Builder/spinner" 5 | "os" 6 | "os/user" 7 | "runtime" 8 | ) 9 | 10 | func BuilderDir(path string) (bool, error) { 11 | //check if file path exists, returns err = nil if file exists 12 | _, err := os.Stat(path) 13 | 14 | if err == nil { 15 | spinner.LogMessage(".builder dir already exists", "info") 16 | } 17 | 18 | // should return true if dir doesn't exist 19 | if os.IsNotExist(err) { 20 | 21 | errDir := os.Mkdir(path, 0755) 22 | //should return nil once directory is made, if not, throw err 23 | if errDir != nil { 24 | spinner.LogMessage("failed to make directory at "+path+": "+err.Error(), "fatal") 25 | } 26 | } 27 | 28 | return true, err 29 | } 30 | 31 | // MakeBuilderDir does... 32 | func MakeBuilderDir() { 33 | if runtime.GOOS != "windows" { 34 | user, _ := user.Current() 35 | homeDir := user.HomeDir 36 | 37 | builderPath := homeDir + "/.builder" 38 | 39 | BuilderDir(builderPath) 40 | } else { 41 | appDataDir := os.Getenv("LOCALAPPDATA") 42 | if appDataDir == "" { 43 | appDataDir = os.Getenv("APPDATA") 44 | } 45 | 46 | builderPath := appDataDir + "/Builder" 47 | 48 | BuilderDir(builderPath) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /directory/hidden.go: -------------------------------------------------------------------------------- 1 | package directory 2 | 3 | import ( 4 | "Builder/spinner" 5 | "Builder/utils" 6 | "fmt" 7 | "os" 8 | "strings" 9 | ) 10 | 11 | func hiddenDir(path string) (bool, error) { 12 | //check if file path exists, returns err = nil if file exists 13 | _, err := os.Stat(path) 14 | 15 | if err == nil { 16 | fmt.Println("Path already exists") 17 | spinner.LogMessage("Path already exists", "warn") 18 | } 19 | 20 | // should return true if file doesn't exist 21 | if os.IsNotExist(err) { 22 | errDir := os.Mkdir(path, 0755) 23 | if errDir != nil { 24 | spinner.LogMessage("failed to create hidden directory: "+err.Error(), "fatal") 25 | } 26 | } 27 | 28 | //check workspace env exists, if not, create it 29 | val, present := os.LookupEnv("BUILDER_HIDDEN_DIR") 30 | if !present { 31 | os.Setenv("BUILDER_HIDDEN_DIR", path) 32 | } else { 33 | fmt.Println("BUILDER_HIDDEN_DIR", val) 34 | } 35 | return true, err 36 | } 37 | 38 | // MakeHiddenDir does... 39 | func MakeHiddenDir(path string) { 40 | 41 | if os.Getenv("HIDDEN_DIR_ENABLED") == "true" { 42 | hiddenPath := path + "/.hidden" 43 | hiddenDir(hiddenPath) 44 | } else { 45 | repo := utils.GetRepoURL() 46 | var repoName string 47 | if repo == "" { 48 | repoName = ".hidden" 49 | } else { 50 | repoName = strings.TrimSuffix(repo[strings.LastIndex(repo, "/"):], ".git") 51 | } 52 | // Don't add extra slash if one exists 53 | var visiblePath string 54 | if strings.Contains(repoName, "/") { 55 | visiblePath = path + repoName 56 | } else { 57 | visiblePath = path + "/" + repoName 58 | } 59 | 60 | hiddenDir(visiblePath) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /directory/logs.go: -------------------------------------------------------------------------------- 1 | package directory 2 | 3 | import ( 4 | "Builder/spinner" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | func logDir(path string) (bool, error) { 10 | //check if file path exists, returns err = nil if file exists 11 | _, err := os.Stat(path) 12 | 13 | if err == nil { 14 | fmt.Println("Path already exists") 15 | spinner.LogMessage("Path already exists", "info") 16 | } 17 | 18 | // should return true if file doesn't exist 19 | if os.IsNotExist(err) { 20 | 21 | errDir := os.Mkdir(path, 0755) 22 | //should return nil once directory is made, if not, throw err 23 | if errDir != nil { 24 | spinner.LogMessage("failed to make directory: "+err.Error(), "fatal") 25 | } 26 | 27 | } 28 | 29 | //check workspace env exists, if not, create it 30 | val, present := os.LookupEnv("BUILDER_LOGS_DIR") 31 | if !present { 32 | os.Setenv("BUILDER_LOGS_DIR", path) 33 | } else { 34 | fmt.Println("BUILDER_LOGS_DIR", val) 35 | } 36 | return true, err 37 | } 38 | 39 | // MakeLogsDir does... 40 | func MakeLogsDir(path string) { 41 | visiblePath := path + "/logs" 42 | logDir(visiblePath) 43 | } 44 | -------------------------------------------------------------------------------- /directory/parent.go: -------------------------------------------------------------------------------- 1 | package directory 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "os" 7 | "path" 8 | "strings" 9 | "time" 10 | 11 | "Builder/spinner" 12 | "Builder/utils" 13 | ) 14 | 15 | // MakeDirs does... 16 | func MakeDirs() { 17 | //handles -n flag 18 | name := utils.GetName() 19 | 20 | //check for projectPath env from builder.yaml 21 | configPath := os.Getenv("BUILDER_DIR_PATH") 22 | 23 | // If file or folder already named 'builder' in path, change builder folder name to builder_data 24 | builderFolderName := "builder" 25 | if configPath != "" && os.Getenv("BUILDER_DOCKER_COMMAND") == "true" { 26 | if _, err := os.Stat(configPath + "/" + "builder"); err != nil { 27 | builderFolderName = "builder" 28 | } else { 29 | builderFolderName = "builder_data" 30 | } 31 | } else if os.Getenv("BUILDER_DOCKER_COMMAND") == "true" { 32 | builderFolderName = "builder_data" 33 | } 34 | 35 | var path string 36 | if os.Getenv("BUILDER_COMMAND") == "true" { 37 | if configPath != "" { 38 | // Check if user wants to name builder folder a different name 39 | if os.Getenv("BUILDER_BUILDS_DIR") != "" { 40 | path = configPath + "/" + name + "/" + os.Getenv("BUILDER_BUILDS_DIR") + "/" + name + "_" + name 41 | } else { 42 | path = configPath + "/" + name + "/" + builderFolderName + "/" + name + "_" + name 43 | } 44 | } else { // Place builds in builder folder in repo 45 | // Check if user wants to name builder folder a different name 46 | if os.Getenv("BUILDER_BUILDS_DIR") != "" { 47 | path = "./" + os.Getenv("BUILDER_BUILDS_DIR") + "/" + name + "_" + name 48 | } else { 49 | path = "./" + builderFolderName + "/" + name + "_" + name 50 | } 51 | } 52 | } else if os.Getenv("BUILDER_DOCKER_COMMAND") == "true" { 53 | if configPath != "" { 54 | // Check if user wants to name builder folder a different name 55 | if os.Getenv("BUILDER_BUILDS_DIR") != "" { 56 | path = configPath + "/" + name + "/" + os.Getenv("BUILDER_BUILDS_DIR") + "/" + name + "_" + name 57 | } else { 58 | path = configPath + "/" + name + "/" + builderFolderName + "/" + name + "_" + name 59 | } 60 | } else { // Place builds in builder_data folder in repo 61 | // Check if user wants to name builder folder a different name 62 | if os.Getenv("BUILDER_BUILDS_DIR") != "" { 63 | path = "./" + os.Getenv("BUILDER_BUILDS_DIR") + "/" + name + "_" + name 64 | } else { 65 | path = "./builder_data/" + name + "_" + name 66 | } 67 | } 68 | } else { // builder init so create an initial repo dir 69 | if configPath != "" { 70 | // Check if user wants to name builder folder a different name 71 | if os.Getenv("BUILDER_BUILDS_DIR") != "" { 72 | path = configPath + "/" + name + "/" + os.Getenv("BUILDER_BUILDS_DIR") + "/" + name + "_" + name 73 | } else { 74 | path = configPath + "/" + name + "/" + builderFolderName + "/" + name + "_" + name 75 | } 76 | } else { 77 | // Check if user wants to name builder folder a different name 78 | if os.Getenv("BUILDER_BUILDS_DIR") != "" { 79 | path = "./" + name + "/" + os.Getenv("BUILDER_BUILDS_DIR") + "/" + name + "_" + name 80 | } else { 81 | path = "./" + name + "/" + builderFolderName + "/" + name + "_" + name 82 | } 83 | } 84 | } 85 | 86 | if os.Getenv("BUILDER_DOCKER_COMMAND") == "true" { 87 | MakeParentDir(path) 88 | 89 | MakeWorkspaceDir(path) 90 | 91 | MakeLogsDir(path) 92 | MakeBuilderDir() 93 | } else { 94 | MakeParentDir(path) 95 | 96 | MakeHiddenDir(path) 97 | MakeWorkspaceDir(path) 98 | 99 | MakeLogsDir(path) 100 | MakeBuilderDir() 101 | } 102 | } 103 | 104 | func MakeParentDir(path string) (bool, error) { 105 | //check if file path exists, returns err = nil if file exists 106 | info, err := os.Stat(path) 107 | 108 | if err == nil { 109 | fmt.Println("Path already exists") 110 | spinner.LogMessage("Path already exists", "info") 111 | } 112 | 113 | // should return true if file doesn't exist 114 | if os.IsNotExist(err) || !info.IsDir() { 115 | errDir := os.MkdirAll(path, 0755) 116 | //should return nil once directory is made, if not, throw err 117 | if errDir != nil { 118 | spinner.LogMessage("failed to create directory at "+path+": "+err.Error(), "fatal") 119 | } 120 | } 121 | 122 | //check workspace env exists, if not, create it 123 | val, present := os.LookupEnv("BUILDER_PARENT_DIR") 124 | if !present { 125 | os.Setenv("BUILDER_PARENT_DIR", path) 126 | } else { 127 | fmt.Println("BUILDER_PARENT_DIR", val) 128 | } 129 | 130 | return true, err 131 | } 132 | 133 | func UpdateParentDirName(pathWithWrongParentName string) string { 134 | oldName, _ := os.LookupEnv("BUILDER_PARENT_DIR") 135 | projectName := utils.GetName() 136 | startTime, _ := time.Parse(time.RFC850, os.Getenv("BUILD_START_TIME")) 137 | unixTimestamp := startTime.Unix() 138 | newName := strings.TrimSuffix(oldName, projectName) + fmt.Sprint(unixTimestamp) 139 | 140 | path := os.Getenv("BUILDER_DIR_PATH") 141 | 142 | // user using builder command and did not provide a path to build in 143 | if os.Getenv("BUILDER_COMMAND") == "true" && path == "" { 144 | wdPath, err := os.Getwd() 145 | if err != nil { 146 | spinner.LogMessage("error getting builder working directory", "error") 147 | } 148 | 149 | path = wdPath 150 | } 151 | 152 | // user using builder docker command and did not provide a path to build in 153 | if os.Getenv("BUILDER_DOCKER_COMMAND") == "true" && path == "" { 154 | wdPath, err := os.Getwd() 155 | if err != nil { 156 | spinner.LogMessage("error getting builder working directory", "error") 157 | } 158 | 159 | path = wdPath 160 | } 161 | 162 | // Rename folder 163 | if oldName[0:2] == "./" { 164 | // err := os.Rename(path+"/"+oldName[2:], path+"/"+newName[2:]) 165 | // if err != nil { 166 | // fmt.Println(err.(*os.LinkError).Err) 167 | // spinner.LogMessage("could not rename parent dir", "fatal") 168 | // } 169 | 170 | err := CopyDir(path+"/"+oldName[2:], path+"/"+newName[2:]) 171 | if err != nil { 172 | spinner.LogMessage("Couldn't copy over files to new parent dir: "+err.Error(), "fatal") 173 | } 174 | 175 | err = os.RemoveAll(path + "/" + oldName[2:]) 176 | if err != nil { 177 | spinner.LogMessage("Couldn't delete old parent dir: "+err.Error(), "fatal") 178 | } 179 | 180 | } else { 181 | // err := os.Rename(oldName, newName) 182 | // if err != nil { 183 | // fmt.Println(err.(*os.LinkError).Err) 184 | // spinner.LogMessage("could not rename parent dir", "fatal") 185 | // } 186 | 187 | err := CopyDir(oldName, newName) 188 | if err != nil { 189 | spinner.LogMessage("Couldn't copy over files to new parent dir: "+err.Error(), "fatal") 190 | } 191 | 192 | err = os.RemoveAll(oldName) 193 | if err != nil { 194 | spinner.LogMessage("Couldn't delete old parent dir: "+err.Error(), "fatal") 195 | } 196 | } 197 | 198 | // Update env vars to include new parent folder name 199 | name := utils.GetName() 200 | os.Setenv("BUILDER_PARENT_DIR", newName) 201 | os.Setenv("BUILDER_HIDDEN_DIR", newName+"/"+name) 202 | os.Setenv("BUILDER_WORKSPACE_DIR", newName+"/workspace") 203 | os.Setenv("BUILDER_LOGS_DIR", newName+"/logs") 204 | 205 | if os.Getenv("BUILDER_DOCKER_COMMAND") == "true" { 206 | oldArtifactPath := os.Getenv("BUILDER_ARTIFACT_DIR") 207 | newArtifactPath := strings.Replace(oldArtifactPath, name+"_"+name, name+"_"+fmt.Sprint(unixTimestamp), 1) 208 | 209 | os.Setenv("BUILDER_ARTIFACT_DIR", newArtifactPath) 210 | } 211 | 212 | // Return new path with new parent directory name 213 | newPath := strings.Replace(pathWithWrongParentName, oldName[2:], newName[2:], 1) 214 | 215 | return newPath 216 | } 217 | 218 | func CopyFile(src, dst string) error { 219 | var err error 220 | var srcfd *os.File 221 | var dstfd *os.File 222 | var srcinfo os.FileInfo 223 | 224 | if srcfd, err = os.Open(src); err != nil { 225 | return err 226 | } 227 | defer srcfd.Close() 228 | 229 | if dstfd, err = os.Create(dst); err != nil { 230 | return err 231 | } 232 | defer dstfd.Close() 233 | 234 | if _, err = io.Copy(dstfd, srcfd); err != nil { 235 | return err 236 | } 237 | if srcinfo, err = os.Stat(src); err != nil { 238 | return err 239 | } 240 | return os.Chmod(dst, srcinfo.Mode()) 241 | } 242 | 243 | func CopyDir(src string, dst string) error { 244 | var err error 245 | var fds []os.DirEntry 246 | var srcinfo os.FileInfo 247 | 248 | if srcinfo, err = os.Stat(src); err != nil { 249 | return err 250 | } 251 | 252 | if err = os.MkdirAll(dst, srcinfo.Mode()); err != nil { 253 | return err 254 | } 255 | 256 | if fds, err = os.ReadDir(src); err != nil { 257 | return err 258 | } 259 | for _, fd := range fds { 260 | srcfp := path.Join(src, fd.Name()) 261 | dstfp := path.Join(dst, fd.Name()) 262 | 263 | if fd.IsDir() { 264 | if err = CopyDir(srcfp, dstfp); err != nil { 265 | fmt.Println(err) 266 | } 267 | } else { 268 | if err = CopyFile(srcfp, dstfp); err != nil { 269 | fmt.Println(err) 270 | } 271 | } 272 | } 273 | return nil 274 | } 275 | -------------------------------------------------------------------------------- /directory/workspace.go: -------------------------------------------------------------------------------- 1 | package directory 2 | 3 | import ( 4 | "Builder/spinner" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | func workSpaceDir(path string) (bool, error) { 10 | //check if file path exists, returns err = nil if file exists 11 | _, err := os.Stat(path) 12 | 13 | if err == nil { 14 | fmt.Println("Path already exists") 15 | spinner.LogMessage("Path already exists", "info") 16 | } 17 | 18 | // should return true if file doesn't exist 19 | if os.IsNotExist(err) { 20 | 21 | errDir := os.Mkdir(path, 0755) 22 | //should return nil once directory is made, if not, throw err 23 | if errDir != nil { 24 | spinner.LogMessage("failed to create directory at "+path+": "+err.Error(), "fatal") 25 | } 26 | } 27 | 28 | //check workspace env exists, if not, create it 29 | val, present := os.LookupEnv("BUILDER_WORKSPACE_DIR") 30 | if !present { 31 | os.Setenv("BUILDER_WORKSPACE_DIR", path) 32 | } else { 33 | fmt.Println("BUILDER_WORKSPACE_DIR", val) 34 | } 35 | return true, err 36 | } 37 | 38 | // MakeWorkspaceDir does... 39 | func MakeWorkspaceDir(path string) { 40 | 41 | workPath := path + "/workspace" 42 | 43 | workSpaceDir(workPath) 44 | 45 | } 46 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module Builder 2 | 3 | go 1.16 4 | 5 | require ( 6 | github.com/google/go-cmp v0.5.9 // indirect 7 | github.com/kr/text v0.2.0 // indirect 8 | github.com/manifoldco/promptui v0.8.0 9 | github.com/mattn/go-colorable v0.1.13 // indirect 10 | github.com/mattn/go-runewidth v0.0.14 // indirect 11 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect 12 | github.com/pkg/errors v0.9.1 // indirect 13 | github.com/stretchr/testify v1.8.4 // indirect 14 | github.com/otiai10/copy v1.12.0 // indirect 15 | github.com/theckman/yacspin v0.13.12 16 | github.com/zserge/lorca v0.1.10 17 | go.uber.org/zap v1.24.0 18 | golang.org/x/net v0.10.0 // indirect 19 | golang.org/x/sys v0.11.0 // indirect 20 | golang.org/x/text v0.12.0 21 | gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect 22 | gopkg.in/yaml.v2 v2.4.0 23 | gopkg.in/yaml.v3 v3.0.1 24 | ) 25 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= 2 | github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= 3 | github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= 4 | github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= 5 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= 6 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= 7 | github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= 8 | github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= 9 | github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 10 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 11 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 12 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 13 | github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= 14 | github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= 15 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 16 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 17 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 18 | github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a h1:FaWFmfWdAUKbSCtOU2QjDaorUexogfaMgbipgYATUMU= 19 | github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= 20 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 21 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 22 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 23 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 24 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 25 | github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a h1:weJVJJRzAJBFRlAiJQROKQs8oC9vOxvm4rZmBBk0ONw= 26 | github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= 27 | github.com/manifoldco/promptui v0.8.0 h1:R95mMF+McvXZQ7j1g8ucVZE1gLP3Sv6j9vlF9kyRqQo= 28 | github.com/manifoldco/promptui v0.8.0/go.mod h1:n4zTdgP0vr0S3w7/O/g98U+e0gwLScEXGwov2nIKuGQ= 29 | github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= 30 | github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= 31 | github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= 32 | github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= 33 | github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= 34 | github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= 35 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 36 | github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= 37 | github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= 38 | github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 39 | github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 40 | github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= 41 | github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 42 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= 43 | github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= 44 | github.com/otiai10/copy v1.12.0 h1:cLMgSQnXBs1eehF0Wy/FAGsgDTDmAqFR7rQylBb1nDY= 45 | github.com/otiai10/copy v1.12.0/go.mod h1:rSaLseMUsZFFbsFGc7wCJnnkTAvdc5L6VWxPE4308Ww= 46 | github.com/otiai10/mint v1.5.1/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM= 47 | github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= 48 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 49 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 50 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 51 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 52 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 53 | github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= 54 | github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= 55 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 56 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 57 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 58 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 59 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 60 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 61 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 62 | github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= 63 | github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 64 | github.com/theckman/yacspin v0.13.12 h1:CdZ57+n0U6JMuh2xqjnjRq5Haj6v1ner2djtLQRzJr4= 65 | github.com/theckman/yacspin v0.13.12/go.mod h1:Rd2+oG2LmQi5f3zC3yeZAOl245z8QOvrH4OPOJNZxLg= 66 | github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= 67 | github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= 68 | github.com/zserge/lorca v0.1.10 h1:f/xBJ3D3ipcVRCcvN8XqZnpoKcOXV8I4vwqlFyw7ruc= 69 | github.com/zserge/lorca v0.1.10/go.mod h1:bVmnIbIRlOcoV285KIRSe4bUABKi7R7384Ycuum6e4A= 70 | go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= 71 | go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= 72 | go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI= 73 | go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= 74 | go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= 75 | go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= 76 | go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60= 77 | go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg= 78 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 79 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 80 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 81 | golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 82 | golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 83 | golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= 84 | golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 85 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 86 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 87 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 88 | golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 89 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 90 | golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= 91 | golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 92 | golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= 93 | golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= 94 | golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= 95 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 96 | golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 97 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 98 | golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 99 | golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 100 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 101 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 102 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 103 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 104 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 105 | golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 106 | golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 107 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 108 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 109 | golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 110 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 111 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 112 | golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 113 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 114 | golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 115 | golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 116 | golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= 117 | golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 118 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 119 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 120 | golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= 121 | golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= 122 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 123 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 124 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 125 | golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 126 | golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= 127 | golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= 128 | golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= 129 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 130 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 131 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 132 | golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= 133 | golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= 134 | golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= 135 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 136 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 137 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 138 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 139 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 140 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 141 | gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= 142 | gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 143 | gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 144 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 145 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 146 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 147 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 148 | -------------------------------------------------------------------------------- /gui/CLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AuditDeploy/Builder/57259acf3fdeb79663701b6a61d450bb85c40e58/gui/CLogo.png -------------------------------------------------------------------------------- /gui/CSharpLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AuditDeploy/Builder/57259acf3fdeb79663701b6a61d450bb85c40e58/gui/CSharpLogo.png -------------------------------------------------------------------------------- /gui/GoLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AuditDeploy/Builder/57259acf3fdeb79663701b6a61d450bb85c40e58/gui/GoLogo.png -------------------------------------------------------------------------------- /gui/JavaLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AuditDeploy/Builder/57259acf3fdeb79663701b6a61d450bb85c40e58/gui/JavaLogo.png -------------------------------------------------------------------------------- /gui/NodeLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AuditDeploy/Builder/57259acf3fdeb79663701b6a61d450bb85c40e58/gui/NodeLogo.png -------------------------------------------------------------------------------- /gui/PythonLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AuditDeploy/Builder/57259acf3fdeb79663701b6a61d450bb85c40e58/gui/PythonLogo.png -------------------------------------------------------------------------------- /gui/RubyLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AuditDeploy/Builder/57259acf3fdeb79663701b6a61d450bb85c40e58/gui/RubyLogo.png -------------------------------------------------------------------------------- /gui/RustLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AuditDeploy/Builder/57259acf3fdeb79663701b6a61d450bb85c40e58/gui/RustLogo.png -------------------------------------------------------------------------------- /gui/gui.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #1E1E1E; 3 | font-family: Arial, sans-serif; 4 | padding: 0; 5 | margin: 0; 6 | } 7 | 8 | table { 9 | border-collapse: collapse; 10 | } 11 | 12 | #container { 13 | margin: 0; 14 | padding: 0; 15 | display:flex; 16 | flex-direction: column; 17 | } 18 | 19 | #header { 20 | background-color: black; 21 | height: 40px; 22 | margin: 0; 23 | padding: 0; 24 | display: flex; 25 | justify-content: center; 26 | align-items: center; 27 | } 28 | 29 | #headerBackBtn { 30 | position: absolute; 31 | left: 3.8%; 32 | color: white; 33 | font-size: 30px; 34 | 35 | cursor: pointer; 36 | 37 | display: none; 38 | visibility: hidden; 39 | } 40 | 41 | #searchBarContainer { 42 | text-align: center; 43 | position: relative; 44 | } 45 | 46 | #searchBar { 47 | display: inline-block; 48 | background-color: #36373A; 49 | width: 90%; 50 | margin-top: 15px; 51 | padding: 5px 5px 5px 25px; 52 | border: 0px #36373A solid; 53 | border-radius: 15px; 54 | color: lightgray; 55 | } 56 | 57 | #searchBar:focus { 58 | outline: none; 59 | } 60 | 61 | #clearIcon { 62 | all: unset; 63 | cursor: pointer; 64 | color: lightgray; 65 | position: absolute; 66 | right: 5%; 67 | top: 48%; 68 | } 69 | 70 | #buildsListContainer { 71 | position: relative; 72 | width: 92.5%; 73 | margin-top: 15px; 74 | margin-left: 3.8%; 75 | } 76 | 77 | #buildsListTable { 78 | width: 100%; 79 | } 80 | 81 | .buildsListTableHeader { 82 | background-color: black; 83 | height: 30px; 84 | color: lightgray; 85 | font-weight: normal; 86 | position: sticky; 87 | top: 0; 88 | } 89 | 90 | .buildsListTableCell { 91 | background-color: #2F2F2F; 92 | height: 43px; 93 | padding: 0 10px 0 10px; 94 | text-align: center; 95 | color: lightgray; 96 | border-bottom: 4px solid #1E1E1E; 97 | } 98 | 99 | .buildsListTableCell:nth-child(1) { 100 | padding: 2px 10px 0 10px; 101 | } 102 | 103 | .buildsListTableCell:nth-child(5) { 104 | color: #F16522; 105 | } 106 | 107 | #noBuildsPresentContainer { 108 | display: none; 109 | visibility: hidden; 110 | text-align: center; 111 | } 112 | 113 | #noBuildsPresent { 114 | color: rgb(167, 166, 166); 115 | font-style: italic; 116 | } 117 | 118 | /* Details page */ 119 | 120 | #detailspage { 121 | display: none; 122 | visibility: hidden; 123 | } 124 | 125 | #detailspageContentContainer { 126 | position: relative; 127 | width: 92.5%; 128 | margin-top: 8px; 129 | margin-left: 3.8%; 130 | } 131 | 132 | #projectHeader { 133 | display: flex; 134 | flex-direction: row; 135 | justify-content: space-between; 136 | align-items: center; 137 | } 138 | 139 | #projectName { 140 | color: #F16522; 141 | font-size: 24px; 142 | } 143 | 144 | #timestamp { 145 | color: lightgray; 146 | font-size: 15px; 147 | } 148 | 149 | #artifactsTableHeader { 150 | background-color: black; 151 | height: 30px; 152 | color: lightgray; 153 | font-weight: normal; 154 | } 155 | 156 | #detailsContainer { 157 | display: flex; 158 | flex-direction: row; 159 | justify-content: space-between; 160 | } 161 | 162 | #metadataContainer { 163 | display: flex; 164 | flex-direction: row; 165 | width: 50%; 166 | } 167 | 168 | #metadataDataContainer { 169 | margin-left: 40px; 170 | } 171 | 172 | #metadataTable { 173 | border-collapse: collapse; 174 | border-spacing: 0; 175 | } 176 | 177 | .metadataTag { 178 | color: #F16522; 179 | font-size: 15px; 180 | } 181 | 182 | .metadataData { 183 | color: lightgray; 184 | font-size: 15px; 185 | padding-left: 8px; 186 | padding-right: 8px; 187 | height: 32px; 188 | } 189 | 190 | #artifactsContainer { 191 | float: right; 192 | width: 500px; 193 | } 194 | 195 | #artifactsTable { 196 | width: 100%; 197 | } 198 | 199 | .artifact { 200 | padding-left: 10px; 201 | padding-right: 10px; 202 | background-color: #2F2F2F; 203 | height: 43px; 204 | margin-bottom: 2px; 205 | text-align: center; 206 | color: lightgray; 207 | border-bottom: 4px solid #1E1E1E; 208 | } 209 | 210 | #fileLocationContainer { 211 | background-color: black; 212 | opacity: 50%; 213 | min-height: 30px; 214 | margin-top: -4px; 215 | display: flex; 216 | align-items: center; 217 | } 218 | 219 | #folderIcon { 220 | color: lightgray; 221 | margin-left: 8px; 222 | } 223 | 224 | #artifactsLocation { 225 | color: lightgray; 226 | margin-left: 8px; 227 | margin-right: 8px; 228 | font-size: 14px; 229 | word-break: break-word; 230 | } 231 | 232 | #logsContainer { 233 | margin-top: 20px; 234 | margin-bottom: 15px; 235 | } 236 | 237 | #logsHeader { 238 | background-color: black; 239 | height: 30px; 240 | display: flex; 241 | justify-content: center; 242 | align-items: center; 243 | } 244 | 245 | #logsHeaderText { 246 | color: lightgray; 247 | font-weight: normal; 248 | } 249 | 250 | #logsContent { 251 | background-color: black; 252 | margin-top: 2px; 253 | height: 40vh; 254 | overflow-x: scroll; 255 | overflow-y: auto; 256 | border: 2px solid black; 257 | } 258 | 259 | #logsTable { 260 | width: 100%; 261 | } 262 | 263 | .logTime { 264 | padding-left: 8px; 265 | color: #A1FF9F; 266 | white-space: nowrap; 267 | vertical-align: middle; 268 | } 269 | 270 | .logTypeInfo { 271 | padding-left: 5px; 272 | color: #70A9FF; 273 | white-space: nowrap; 274 | vertical-align: middle; 275 | } 276 | 277 | .logTypeWarn { 278 | padding-left: 5px; 279 | color: #FFCE70; 280 | white-space: nowrap; 281 | vertical-align: middle; 282 | } 283 | 284 | .logTypeError { 285 | padding-left: 5px; 286 | color: #FF7070; 287 | white-space: nowrap; 288 | vertical-align: middle; 289 | } 290 | 291 | .logCaller { 292 | padding-left: 5px; 293 | color: #a1a1a1; 294 | white-space: nowrap; 295 | vertical-align: middle; 296 | } 297 | 298 | .logMessage { 299 | padding-left: 8px; 300 | color: lightgray; 301 | white-space: nowrap; 302 | vertical-align: middle; 303 | } 304 | 305 | /* scrollbar styling */ 306 | 307 | ::-webkit-scrollbar { 308 | height: 8px; 309 | width: 8px; 310 | } 311 | 312 | ::-webkit-scrollbar-track { 313 | background: #1E1E1E; 314 | } 315 | 316 | ::-webkit-scrollbar-thumb { 317 | background: #474747; 318 | opacity: 80%; 319 | } 320 | 321 | ::-webkit-scrollbar-thumb:hover { 322 | background: #555; 323 | } -------------------------------------------------------------------------------- /gui/gui.go: -------------------------------------------------------------------------------- 1 | package gui 2 | 3 | import ( 4 | "bufio" 5 | _ "embed" 6 | "encoding/base64" 7 | "log" 8 | "net/url" 9 | "os" 10 | "regexp" 11 | "runtime" 12 | "strings" 13 | 14 | "github.com/zserge/lorca" 15 | ) 16 | 17 | // Embed html code for gui 18 | // 19 | //go:embed gui_index.html 20 | var IndexHtmlContents []byte 21 | 22 | // Embed js code for gui 23 | // 24 | //go:embed gui.js 25 | var jsContents []byte 26 | 27 | // Embed css code for gui 28 | // 29 | //go:embed gui.css 30 | var cssContents []byte 31 | 32 | // Embed logo for gui 33 | // 34 | //go:embed logo.png 35 | var logo []byte 36 | 37 | // Embed C logo 38 | // 39 | //go:embed CLogo.png 40 | var CLogo []byte 41 | 42 | // Embed CSharp logo 43 | // 44 | //go:embed CSharpLogo.png 45 | var CSharpLogo []byte 46 | 47 | // Embed Go logo 48 | // 49 | //go:embed GoLogo.png 50 | var GoLogo []byte 51 | 52 | // Embed Java logo 53 | // 54 | //go:embed JavaLogo.png 55 | var JavaLogo []byte 56 | 57 | // Embed Node logo 58 | // 59 | //go:embed NodeLogo.png 60 | var NodeLogo []byte 61 | 62 | // Embed Python logo 63 | // 64 | //go:embed PythonLogo.png 65 | var PythonLogo []byte 66 | 67 | // Embed Ruby logo 68 | // 69 | //go:embed RubyLogo.png 70 | var RubyLogo []byte 71 | 72 | // Embed Rust logo 73 | // 74 | //go:embed RustLogo.png 75 | var RustLogo []byte 76 | 77 | type Build struct { 78 | ProjectName string `json:"ProjectName"` 79 | ProjectType string `json:"ProjectType"` 80 | ArtifactName string `json:"ArtifactName"` 81 | ArtifactLocation string `json:"ArtifactLocation"` 82 | UserName string `json:"UserName"` 83 | HomeDir string `json:"HomeDir"` 84 | IP string `json:"IP"` 85 | StartTime string `json:"StartTime"` 86 | EndTime string `json:"EndTime"` 87 | MasterGitHash string `json:"MasterGitHash"` 88 | BranchName string `json:"BranchName"` 89 | BuildHash string `json:"BuildHash"` 90 | } 91 | 92 | func Gui() { 93 | 94 | // Read in json data 95 | getBuildsJSON := func() string { 96 | // Read in builds JSON data from application builder folder 97 | var buildsPath string 98 | if runtime.GOOS == "windows" { 99 | appDataDir := os.Getenv("LOCALAPPDATA") 100 | if appDataDir == "" { 101 | appDataDir = os.Getenv("APPDATA") 102 | } 103 | 104 | buildsPath = appDataDir + "/Builder/builds.json" 105 | } else { 106 | homeDir, err := os.UserHomeDir() 107 | if err != nil { 108 | log.Fatal(err) 109 | } 110 | 111 | buildsPath = homeDir + "/.builder/builds.json" 112 | } 113 | 114 | buildsJSON, err := os.ReadFile(buildsPath) 115 | if err != nil { 116 | log.Fatal(err) 117 | } 118 | 119 | FormattedBuildsJSON := strings.TrimSuffix(string(buildsJSON), ",\n") 120 | 121 | FormattedBuildsJSON = "[" + FormattedBuildsJSON + "]" 122 | 123 | return FormattedBuildsJSON 124 | } 125 | 126 | getLogsJSON := func(path string) string { 127 | logsFile, err := os.Open(path) 128 | if err != nil { 129 | log.Fatal(err) 130 | } 131 | defer logsFile.Close() 132 | 133 | var lines []string 134 | scanner := bufio.NewScanner(logsFile) 135 | for scanner.Scan() { 136 | lines = append(lines, scanner.Text()) 137 | } 138 | 139 | // Re-format zap logger output to valid JSON 140 | asString := strings.Join(lines, ",") 141 | 142 | jsonString := "[" + asString + "]" 143 | 144 | return jsonString 145 | } 146 | 147 | getImage := func() string { 148 | image := base64.StdEncoding.EncodeToString(logo) 149 | 150 | return image 151 | } 152 | 153 | getCLogoImage := func() string { 154 | image := base64.StdEncoding.EncodeToString(CLogo) 155 | 156 | return image 157 | } 158 | 159 | getCSharpLogoImage := func() string { 160 | image := base64.StdEncoding.EncodeToString(CSharpLogo) 161 | 162 | return image 163 | } 164 | 165 | getGoLogoImage := func() string { 166 | image := base64.StdEncoding.EncodeToString(GoLogo) 167 | 168 | return image 169 | } 170 | 171 | getJavaLogoImage := func() string { 172 | image := base64.StdEncoding.EncodeToString(JavaLogo) 173 | 174 | return image 175 | } 176 | 177 | getNodeLogoImage := func() string { 178 | image := base64.StdEncoding.EncodeToString(NodeLogo) 179 | 180 | return image 181 | } 182 | 183 | getPythonLogoImage := func() string { 184 | image := base64.StdEncoding.EncodeToString(PythonLogo) 185 | 186 | return image 187 | } 188 | 189 | getRubyLogoImage := func() string { 190 | image := base64.StdEncoding.EncodeToString(RubyLogo) 191 | 192 | return image 193 | } 194 | 195 | getRustLogoImage := func() string { 196 | image := base64.StdEncoding.EncodeToString(RustLogo) 197 | 198 | return image 199 | } 200 | 201 | // Combine html, css, and js files for gui 202 | cssRegex := regexp.MustCompile(`cssgoeshere`) 203 | jsRegex := regexp.MustCompile(`jsgoeshere`) 204 | 205 | finalHTMLContent := cssRegex.ReplaceAllString(string(IndexHtmlContents), string(cssContents)) 206 | finalHTMLContent = jsRegex.ReplaceAllString(finalHTMLContent, string(jsContents)) 207 | 208 | // Custom arguments for chrome popup 209 | args := []string{"--remote-allow-origins=*"} 210 | 211 | // Create UI with basic HTML passed via data URI 212 | ui, err := lorca.New("", "", 1200, 1000, args...) 213 | 214 | if err != nil { 215 | log.Fatal(err) 216 | } 217 | defer ui.Close() 218 | 219 | ui.Bind("getBuildsJSON", getBuildsJSON) 220 | ui.Bind("getLogsJSON", getLogsJSON) 221 | ui.Bind("getImage", getImage) 222 | ui.Bind("getCLogoImage", getCLogoImage) 223 | ui.Bind("getCSharpLogoImage", getCSharpLogoImage) 224 | ui.Bind("getGoLogoImage", getGoLogoImage) 225 | ui.Bind("getJavaLogoImage", getJavaLogoImage) 226 | ui.Bind("getNodeLogoImage", getNodeLogoImage) 227 | ui.Bind("getPythonLogoImage", getPythonLogoImage) 228 | ui.Bind("getRubyLogoImage", getRubyLogoImage) 229 | ui.Bind("getRustLogoImage", getRustLogoImage) 230 | 231 | ui.Load("data:text/html," + url.PathEscape(finalHTMLContent)) 232 | 233 | // Wait until UI window is closed 234 | <-ui.Done() 235 | } 236 | -------------------------------------------------------------------------------- /gui/gui.js: -------------------------------------------------------------------------------- 1 | const searchBar = document.getElementById("searchBar"); 2 | 3 | 4 | function stringToUTC(timeString) { 5 | let time = new Date(timeString); 6 | 7 | return time.toUTCString(); 8 | } 9 | 10 | function clearSearch() { 11 | if(searchBar.value != "") { 12 | searchBar.value = ""; 13 | search(); 14 | } 15 | } 16 | 17 | function search() { 18 | // Declare variables 19 | var filters, table, tr, td, i, t; 20 | filters = searchBar.value.toLowerCase().match(/\b(\w+)\b/g); 21 | table = document.getElementById("buildsListTable"); 22 | tr = table.getElementsByTagName("tr"); 23 | 24 | // If filters are deleted repopulate table 25 | if(searchBar.value == ""){ 26 | renderBuildsList() 27 | } else { 28 | // Loop through all table rows (excluding the header), and hide those who don't match the search query 29 | for (index in filters) { 30 | for (i = 1; i < tr.length; i++) { 31 | var filtered = false; 32 | var tds = tr[i].getElementsByTagName("td"); 33 | for(t = 1; t < tds.length; t++) { 34 | var td = tds[t]; 35 | 36 | if (td) { 37 | if (td.innerHTML.toLowerCase().indexOf(filters[index]) > -1) { 38 | filtered = true; 39 | } 40 | } 41 | } 42 | if(filtered === true) { 43 | tr[i].style.display = ''; 44 | } 45 | else { 46 | tr[i].style.display = 'none'; 47 | } 48 | } 49 | } 50 | } 51 | } 52 | 53 | const buildsTable = document.getElementById("buildsListTableBody"); 54 | var builds; 55 | 56 | function createBuildsListTable(buildsJSON) { 57 | builds = JSON.parse(buildsJSON); 58 | let text = "" 59 | 60 | for (let build in builds.reverse()) { 61 | text += "" 62 | 63 | let tdString = "" 64 | let dateObj = Date.parse(builds[build].EndTime) 65 | let time = new Date(dateObj).toUTCString(); 66 | 67 | // Determine what language logo to show 68 | let image 69 | switch (builds[build].ProjectType.toLowerCase()) { 70 | case "c": 71 | image = "" 72 | break; 73 | case "csharp": 74 | image = "" 75 | break; 76 | case "go": 77 | image = "" 78 | break; 79 | case "java": 80 | image = "" 81 | break; 82 | case "node": 83 | image = "" 84 | break; 85 | case "python": 86 | image = "" 87 | break; 88 | case "ruby": 89 | image = "" 90 | break; 91 | case "rust": 92 | image = "" 93 | break; 94 | default: 95 | image = "" 96 | } 97 | text += tdString + image + "" 98 | 99 | // Fill in table data 100 | text += tdString + time + "" 101 | text += tdString + builds[build].UserName + "" 102 | text += tdString + builds[build].ArtifactName + "" 103 | text += tdString + builds[build].ProjectName + "" 104 | text += tdString + builds[build].MasterGitHash.slice(0,7) + "" 105 | text += tdString + builds[build].BuildID + "" 106 | 107 | text += "" 108 | } 109 | 110 | return text 111 | } 112 | 113 | const renderBuildsList = async () => { 114 | // Render builds data into table 115 | let buildsJSON = await getBuildsJSON(); 116 | let tableBodyToDisplay = createBuildsListTable(buildsJSON); 117 | if (tableBodyToDisplay != "") { 118 | // Hide no builds to display div and display table data 119 | document.getElementById("noBuildsPresentContainer").style.display = "none"; 120 | document.getElementById("noBuildsPresentContainer").style.visibility = "hidden"; 121 | buildsTable.innerHTML = tableBodyToDisplay; 122 | } else { 123 | // Show no builds to display div 124 | document.getElementById("noBuildsPresentContainer").style.display = "block"; 125 | document.getElementById("noBuildsPresentContainer").style.visibility = "visible"; 126 | } 127 | 128 | // Load and display language logos to builds list 129 | // C 130 | let c_logo_img = await getCLogoImage(); 131 | const c_logos = document.getElementsByClassName("c_logo"); 132 | for (let i = 0; i < c_logos.length; i++) { 133 | c_logos[i].src = "data:image/png;base64," + c_logo_img; 134 | } 135 | 136 | // C# 137 | let csharp_logo_img = await getCSharpLogoImage(); 138 | const csharp_logos = document.getElementsByClassName("csharp_logo"); 139 | for (let i = 0; i < csharp_logos.length; i++) { 140 | csharp_logos[i].src = "data:image/png;base64," + csharp_logo_img; 141 | } 142 | 143 | // Go 144 | let go_logo_img = await getGoLogoImage(); 145 | const go_logos = document.getElementsByClassName("go_logo"); 146 | for (let i = 0; i < go_logos.length; i++) { 147 | go_logos[i].src = "data:image/png;base64," + go_logo_img; 148 | } 149 | 150 | // Java 151 | let java_logo_img = await getJavaLogoImage(); 152 | const java_logos = document.getElementsByClassName("java_logo"); 153 | for (let i = 0; i < java_logos.length; i++) { 154 | java_logos[i].src = "data:image/png;base64," + java_logo_img; 155 | } 156 | 157 | // Node 158 | let node_logo_img = await getNodeLogoImage(); 159 | const node_logos = document.getElementsByClassName("node_logo"); 160 | for (let i = 0; i < node_logos.length; i++) { 161 | node_logos[i].src = "data:image/png;base64," + node_logo_img; 162 | } 163 | 164 | // Python 165 | let python_logo_img = await getPythonLogoImage(); 166 | const python_logos = document.getElementsByClassName("python_logo"); 167 | for (let i = 0; i < python_logos.length; i++) { 168 | python_logos[i].src = "data:image/png;base64," + python_logo_img; 169 | } 170 | 171 | // Ruby 172 | let ruby_logo_img = await getRubyLogoImage(); 173 | const ruby_logos = document.getElementsByClassName("ruby_logo"); 174 | for (let i = 0; i < ruby_logos.length; i++) { 175 | ruby_logos[i].src = "data:image/png;base64," + ruby_logo_img; 176 | } 177 | 178 | //Rust 179 | let rust_logo_img = await getRustLogoImage(); 180 | const rust_logos = document.getElementsByClassName("rust_logo"); 181 | for (let i = 0; i < rust_logos.length; i++) { 182 | rust_logos[i].src = "data:image/png;base64," + rust_logo_img; 183 | } 184 | 185 | }; 186 | 187 | function displayHomePage() { 188 | let detailspage = document.getElementById("detailspage"); 189 | let backBtn = document.getElementById("headerBackBtn"); 190 | let homepage = document.getElementById("homepage"); 191 | 192 | detailspage.style.display = "none"; 193 | detailspage.style.visibility = "hidden"; 194 | 195 | backBtn.style.display = "none"; 196 | backBtn.style.visibility = "hidden"; 197 | 198 | homepage.style.display = "block"; 199 | homepage.style.visibility = "visible"; 200 | 201 | renderBuildsList(); 202 | } 203 | 204 | async function onPageLoad() { 205 | // Load and display Builder logo 206 | let image = await getImage(); 207 | document.getElementById("logo").src = "data:image/png;base64," + image; 208 | 209 | // Display homepage only 210 | document.getElementById("homepage").style.display = "block"; 211 | document.getElementById("homepage").style.visibility = "visible"; 212 | document.getElementById("detailspage").style.display = "none"; 213 | document.getElementById("detailspage").style.visibility = "hidden"; 214 | document.getElementById("headerBackBtn").style.display = "none"; 215 | document.getElementById("headerBackBtn").style.visibility = "hidden"; 216 | 217 | // Render builds data 218 | renderBuildsList(); 219 | } 220 | 221 | // Details page functions 222 | 223 | function displayDetailsPage(buildID) { 224 | let detailspage = document.getElementById("detailspage"); 225 | let backBtn = document.getElementById("headerBackBtn"); 226 | let homepage = document.getElementById("homepage"); 227 | 228 | detailspage.style.display = "block"; 229 | detailspage.style.visibility = "visible"; 230 | 231 | backBtn.style.display = "inline"; 232 | backBtn.style.visibility = "visible"; 233 | backBtn.innerText = "<"; 234 | 235 | homepage.style.display = "none"; 236 | homepage.style.visibility = "hidden"; 237 | 238 | displayDetailsData(buildID); 239 | } 240 | 241 | async function displayDetailsData(buildID) { 242 | let build = builds.find(build => build.BuildID.match(buildID)); 243 | 244 | document.getElementById("projectName").innerHTML = build.ProjectName; 245 | 246 | let dateObj = Date.parse(build.EndTime) 247 | let time = new Date(dateObj).toUTCString(); 248 | document.getElementById("timestamp").innerHTML = time; 249 | 250 | // Display metadata 251 | document.getElementById("projectType").innerHTML = build.ProjectType; 252 | document.getElementById("username").innerHTML = build.UserName; 253 | document.getElementById("homeDir").innerHTML = build.HomeDir; 254 | document.getElementById("ipAddr").innerHTML = build.IP; 255 | document.getElementById("gitURL").innerHTML = build.GitURL; 256 | document.getElementById("gitHash").innerHTML = build.MasterGitHash; 257 | document.getElementById("branchName").innerHTML = build.BranchName; 258 | document.getElementById("buildID").innerHTML = build.BuildID; 259 | 260 | // Display artifact(s) 261 | let text = ""; 262 | 263 | let artifactArray = build.ArtifactName.split(",") 264 | 265 | for (artifact in artifactArray) { 266 | text += "" 267 | text += "" + artifactArray[artifact] + ""; 268 | text += "" 269 | } 270 | 271 | document.getElementById("artifactsTableBody").innerHTML = text; 272 | 273 | // Display artifact(s) location 274 | document.getElementById("artifactsLocation").innerHTML = build.ArtifactLocation; 275 | 276 | // Get logs 277 | let path = build.LogsLocation; 278 | //path = path.substring(0, path.lastIndexOf('/')) + '/logs/logs.json'; 279 | displayLogs(path); 280 | } 281 | 282 | async function displayLogs(path) { 283 | let logsJSON = await getLogsJSON(path); 284 | var buildLogs = JSON.parse(logsJSON); 285 | 286 | let text = "" 287 | for (let log in buildLogs) { 288 | text += "" 289 | 290 | // Time 291 | text += "" + new Date(buildLogs[log].timestamp).toLocaleString().replaceAll(',','') + ""; 292 | 293 | // Type 294 | if (buildLogs[log].level == 'info'){ 295 | text += "" + buildLogs[log].level.toUpperCase() + ""; 296 | } else if(buildLogs[log].level == 'warn'){ 297 | text += "" + buildLogs[log].level.toUpperCase() + ""; 298 | } else { 299 | text += "" + buildLogs[log].level.toUpperCase() + ""; 300 | } 301 | 302 | // Caller 303 | //text += "" + buildLogs[log].caller + ":" + ""; 304 | 305 | // Message 306 | text += "" + buildLogs[log].msg + ""; 307 | 308 | text += "" 309 | } 310 | document.getElementById("logsTable").innerHTML = text; 311 | } -------------------------------------------------------------------------------- /gui/gui_index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Builder 5 | 6 | 9 | 10 | 11 |
12 | 16 |
17 |
18 | 25 | 33 |
34 |
35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
TimeUserArtifact(s)ProjectGit HashBuild ID
51 |
52 |

No builds to display

53 |
54 |
55 |
56 |
57 |
58 |
59 |

60 |

61 |

62 |

63 |
64 |
65 |
66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 |
Project Type:
Username:
Home Directory:
IP Address:
Git URL:
Git Hash:
Branch Name:
Build ID:
102 |
103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 |
Artifact(s)
113 |
114 | 118 |

119 |

120 |
121 |
122 |
123 |
124 |
125 |

126 | Build Log 127 |

128 |
129 |
130 | 131 |
132 |
133 |
134 |
135 |
136 |
137 | 140 | 141 | -------------------------------------------------------------------------------- /gui/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AuditDeploy/Builder/57259acf3fdeb79663701b6a61d450bb85c40e58/gui/logo.png -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "Builder/cmd" 5 | "Builder/gui" 6 | "Builder/utils" 7 | "fmt" 8 | "os" 9 | 10 | "go.uber.org/zap" 11 | ) 12 | 13 | var BuilderLog = zap.S() 14 | 15 | func main() { 16 | 17 | if len(os.Args) > 1 { 18 | utils.Help() 19 | builderCommand := os.Args[1] 20 | if builderCommand == "init" { 21 | cmd.Init() 22 | fmt.Println("Build Complete 🔨") 23 | } else if builderCommand == "config" { 24 | cmd.Config() 25 | fmt.Println("Build Complete 🔨") 26 | } else if builderCommand == "docker" { 27 | cmd.Docker() 28 | fmt.Println("Build Complete 🔨") 29 | } else if builderCommand == "gui" { 30 | gui.Gui() 31 | } else { 32 | cmd.Builder() 33 | fmt.Println("Build Complete 🔨") 34 | } 35 | } else { 36 | cmd.Builder() 37 | fmt.Println("Build Complete 🔨") 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spinner/spinner.go: -------------------------------------------------------------------------------- 1 | package spinner 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path/filepath" 7 | "runtime" 8 | "time" 9 | 10 | "github.com/theckman/yacspin" 11 | "go.uber.org/zap" 12 | ) 13 | 14 | var BuilderLog = zap.S() 15 | 16 | var cfg = yacspin.Config{ 17 | Frequency: 100 * time.Millisecond, 18 | CharSet: []string{"⣧", "⣇", "⡇", "⠇", "⠃", "⠁", "⠃", "⠇", "⡇", "⣇", "⣧", "⣧"}, 19 | StopCharacter: "", 20 | } 21 | var Spinner, err = yacspin.New(cfg) 22 | var Caller string 23 | 24 | func LogMessage(msg string, level string) { 25 | args := os.Args[1:] 26 | _, file, no, ok := runtime.Caller(1) 27 | if ok { 28 | Caller = filepath.Base(file) + ":" + fmt.Sprint(no) 29 | } 30 | 31 | Spinner.Stop() 32 | 33 | // Check if debug flag is given 34 | for i := 0; i < len(args); i++ { 35 | if args[i] == "-d" || args[i] == "--debug" { 36 | // Print log message at correct level 37 | switch level { 38 | case "info": 39 | fmt.Println(time.Now().Local().String() + " INFO " + Caller + ": " + msg) 40 | break 41 | case "warn": 42 | fmt.Println(time.Now().Local().String() + " WARN " + Caller + ": " + msg) 43 | break 44 | case "error": 45 | fmt.Println(time.Now().Local().String() + " ERROR " + Caller + ": " + msg) 46 | break 47 | default: // Fatal 48 | fmt.Println(time.Now().Local().String() + " FATAL " + Caller + ": " + msg) 49 | BuilderLog.Fatal() 50 | } 51 | } 52 | } 53 | 54 | Spinner.Start() 55 | } 56 | -------------------------------------------------------------------------------- /utils/checkArgs.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "Builder/spinner" 5 | "fmt" 6 | "os" 7 | "os/exec" 8 | ) 9 | 10 | // CheckArgs is... 11 | func CheckArgs() { 12 | //Repo 13 | repo := GetRepoURL() 14 | cArgs := os.Args[1:] 15 | //if flag present, but no url 16 | if repo == "" { 17 | spinner.LogMessage("No Repo Url Provided", "fatal") 18 | } 19 | 20 | //check to see if repo exists 21 | //git ls-remote lists refs/heads & tags of a repo, if none exists, exit status thrown 22 | //returns the exit status in err 23 | _, err := exec.Command("git", "ls-remote", repo, "-q").Output() 24 | if err != nil { 25 | spinner.LogMessage("Provided repository does not exist", "fatal") 26 | } 27 | 28 | //check if artifact path is passed in 29 | var artifactPath string 30 | for i, v := range cArgs { 31 | if v == "--output" || v == "-o" { 32 | if len(cArgs) <= i+1 { 33 | spinner.LogMessage("No Output Path Provided", "fatal") 34 | 35 | } else { 36 | artifactPath = cArgs[i+1] 37 | val, present := os.LookupEnv("BUILDER_OUTPUT_PATH") 38 | if !present { 39 | os.Setenv("BUILDER_OUTPUT_PATH", artifactPath) 40 | } else { 41 | fmt.Println("BUILDER_OUTPUT_PATH", val) 42 | fmt.Println("Output Path already present") 43 | spinner.LogMessage("Output path already present", "error") 44 | } 45 | } 46 | } 47 | if v == "--compress" || v == "-z" || v == "-C" { 48 | os.Setenv("ARTIFACT_ZIP_ENABLED", "true") 49 | } 50 | if v == "--hidden" || v == "-H" { 51 | os.Setenv("HIDDEN_DIR_ENABLED", "true") 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /utils/cloneRepo.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "Builder/spinner" 5 | "os" 6 | "os/exec" 7 | "path/filepath" 8 | "strings" 9 | ) 10 | 11 | // CloneRepo grabs url and clones the repo 12 | func CloneRepo(to string) { 13 | // Get absolute path if a relative path was given 14 | toPath, _ := filepath.Abs(to) 15 | 16 | repo := GetRepoURL() 17 | 18 | // Stat path, if it doesn't exist, create it 19 | _, err := os.Stat(toPath) 20 | if err != nil { 21 | errDir := os.MkdirAll(toPath, 0755) 22 | if errDir != nil { 23 | spinner.LogMessage("Could not create new repo directory: "+errDir.Error(), "fatal") 24 | } 25 | 26 | cmd := exec.Command("git", "clone", repo, toPath) 27 | cmd.Run() 28 | 29 | // Get branch name 30 | os.Setenv("REPO_BRANCH_NAME", GetBranchName(toPath)) 31 | } else { 32 | bFlagExists, branchExists, branchName := bFlagAndBranchExists() 33 | 34 | if bFlagExists { 35 | if branchExists { 36 | cmd := exec.Command("git", "clone", "-b", branchName, "--single-branch", repo, toPath) 37 | cmd.Run() 38 | spinner.LogMessage("git clone -b "+branchName+" --single-branch "+repo, "info") 39 | 40 | // Get branch name 41 | os.Setenv("REPO_BRANCH_NAME", branchName) 42 | } else { 43 | spinner.LogMessage("Branch does not exists", "fatal") 44 | } 45 | } else if branchExists { // Repo branch given in builder.yaml not by -b flag 46 | cmd := exec.Command("git", "clone", "-b", branchName, "--single-branch", repo, toPath) 47 | cmd.Run() 48 | spinner.LogMessage("git clone -b "+branchName+" --single-branch "+repo, "info") 49 | 50 | // Get branch name 51 | os.Setenv("REPO_BRANCH_NAME", branchName) 52 | } else { 53 | cmd := exec.Command("git", "clone", repo, toPath) 54 | cmd.Run() 55 | spinner.LogMessage("git clone "+repo, "info") 56 | 57 | // Get branch name 58 | os.Setenv("REPO_BRANCH_NAME", GetBranchName(toPath)) 59 | } 60 | } 61 | } 62 | 63 | func bFlagAndBranchExists() (bool, bool, string) { 64 | var bFlagExists, branchExists = false, false 65 | args := os.Args[1:] 66 | 67 | branchName := os.Getenv("REPO_BRANCH") 68 | 69 | for i, v := range args { 70 | if v == "-b" || v == "--branch" { 71 | if len(args) <= i+1 { 72 | spinner.LogMessage("No Branch Name Provided", "fatal") 73 | 74 | } else { 75 | branchName = args[i+1] 76 | bFlagExists = true 77 | } 78 | } 79 | } 80 | 81 | if branchName != "" { 82 | branchExists = true 83 | } 84 | 85 | return bFlagExists, branchExists, branchName 86 | } 87 | 88 | func GetBranchName(path string) string { 89 | branchCmd := exec.Command("git", "branch") 90 | branchCmd.Dir = path 91 | branch, _ := branchCmd.Output() 92 | 93 | formatName := strings.TrimSuffix(string(branch), "\n") 94 | 95 | return formatName[2:] 96 | } 97 | -------------------------------------------------------------------------------- /utils/cloneRepoFiles.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "Builder/spinner" 5 | "os" 6 | "path/filepath" 7 | 8 | cp "github.com/otiai10/copy" 9 | ) 10 | 11 | // CloneRepo grabs url and clones the repo/copies current dir 12 | func CloneRepoFiles(from string, to string) { 13 | //Get absolute paths in case relative paths are given 14 | fromPath, _ := filepath.Abs(from) 15 | toPath, _ := filepath.Abs(to) 16 | 17 | // Copy all but Builder created dir 18 | if os.Getenv("BUILDER_BUILDS_DIR") != "" { // A different folder to store builds is provided 19 | opt := cp.Options{ 20 | Skip: func(info os.FileInfo, src, dest string) (bool, error) { 21 | return info.Name() == os.Getenv("BUILDER_BUILDS_DIR"), nil 22 | }, 23 | } 24 | err := cp.Copy(fromPath, toPath, opt) 25 | if err != nil { 26 | spinner.LogMessage(err.Error(), "fatal") 27 | } 28 | } else { // Builds are stored in default named 'builder' folder 29 | // copy files to given path 30 | opt := cp.Options{ 31 | Skip: func(info os.FileInfo, src, dest string) (bool, error) { 32 | return info.Name() == "builder", nil 33 | }, 34 | } 35 | err := cp.Copy(fromPath, toPath, opt) 36 | if err != nil { 37 | spinner.LogMessage(err.Error(), "fatal") 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /utils/configDerive.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "os" 5 | "strings" 6 | ) 7 | 8 | // ConfigDerive checks "BUILDER_PROJECT_TYPE" env var and returns string arr based on type 9 | func ConfigDerive() []string { 10 | 11 | //make type lowercase 12 | configType := strings.ToLower(os.Getenv("BUILDER_PROJECT_TYPE")) 13 | buildFile := os.Getenv("BUILDER_BUILD_FILE") 14 | 15 | var files []string 16 | if configType == "go" { 17 | if buildFile != "" { 18 | //custom build file from builder.yaml 19 | files = []string{buildFile} 20 | } else { 21 | //default 22 | files = []string{"main.go"} 23 | } 24 | } else if configType == "rust" { 25 | if buildFile != "" { 26 | //custom build file from builder.yaml 27 | files = []string{buildFile} 28 | } else { 29 | //default 30 | files = []string{"Cargo.toml"} 31 | } 32 | } else if configType == "node" || configType == "npm" { 33 | if buildFile != "" { 34 | files = []string{buildFile} 35 | } else { 36 | files = []string{"package.json"} 37 | } 38 | } else if configType == "java" { 39 | if buildFile != "" { 40 | files = []string{buildFile} 41 | } else { 42 | files = []string{"pom.xml"} 43 | } 44 | } else if configType == "ruby" { 45 | if buildFile != "" { 46 | files = []string{buildFile} 47 | } else { 48 | files = []string{"gemfile.lock", "gemfile"} 49 | } 50 | } else if configType == "c#" || configType == "csharp" { 51 | if buildFile != "" { 52 | files = []string{buildFile} 53 | } else { 54 | files = []string{".csproj", ".sln"} 55 | } 56 | } else if configType == "python" { 57 | if buildFile != "" { 58 | files = []string{buildFile} 59 | } else { 60 | files = []string{"requirements.txt"} 61 | } 62 | } else if configType == "c" { 63 | if buildFile != "" { 64 | files = []string{buildFile} 65 | } else { 66 | files = []string{"Makefile.am"} 67 | } 68 | } 69 | 70 | return files 71 | } 72 | -------------------------------------------------------------------------------- /utils/copyDir.go: -------------------------------------------------------------------------------- 1 | // takes in code as arg from go 2 | //run go build on code given 3 | 4 | package utils 5 | 6 | import ( 7 | "os" 8 | "os/exec" 9 | ) 10 | 11 | //CopyDir creates exe from file passed in as arg 12 | func CopyDir() { 13 | 14 | //copies contents of .hidden to workspace 15 | hiddenDir := os.Getenv("BUILDER_HIDDEN_DIR") 16 | workspaceDir := os.Getenv("BUILDER_WORKSPACE_DIR") 17 | exec.Command("cp", "-a", hiddenDir+"/.", workspaceDir).Run() 18 | } 19 | 20 | -------------------------------------------------------------------------------- /utils/docker.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "Builder/spinner" 5 | "bytes" 6 | "fmt" 7 | "os" 8 | "os/exec" 9 | "strings" 10 | ) 11 | 12 | // Docker creates image from dockerfile and pushes to dockerhub 13 | func Docker() { 14 | dockerFlag := CheckDockerFlag() 15 | 16 | //if -D flag exists, build image 17 | if dockerFlag { 18 | //DETERMINE CMD 19 | var cmd *exec.Cmd 20 | dockerCmd := os.Getenv("BUILDER_DOCKER_CMD") 21 | //if dockerCmd doesn't exist use default 22 | if dockerCmd == "" { 23 | name := GetName() 24 | imageName := fmt.Sprintf("builder/%s", name) 25 | unixTime := os.Getenv("BUILDER_TIMESTAMP") 26 | cmd = exec.Command("docker", "build", ".", "-t", imageName+"-"+unixTime) 27 | } else { 28 | //else use defined dockerCmd 29 | dockerCmdArray := strings.Fields(dockerCmd) 30 | cmd = exec.Command(dockerCmdArray[0], dockerCmdArray[1:]...) 31 | } 32 | 33 | //DETERMINE PATH 34 | //determine projectType to top level Dockerfile path 35 | compType := []string{"go", "rust", "c#", "java"} 36 | nonCompType := []string{"node", "npm", "python", "ruby"} 37 | workspaceDir := os.Getenv("BUILDER_WORKSPACE_DIR") 38 | projectType := os.Getenv("BUILDER_PROJECT_TYPE") 39 | if contains(compType, projectType) { 40 | cmd.Dir = workspaceDir 41 | } else if contains(nonCompType, projectType) { 42 | cmd.Dir = workspaceDir + "/temp/" 43 | } else { 44 | spinner.LogMessage("Please define your projectType in builder.yaml", "fatal") 45 | } 46 | 47 | //RUN DOCKER BUILD 48 | spinner.LogMessage("running command: "+cmd.String(), "info") 49 | err := cmd.Run() 50 | if err != nil { 51 | var outb, errb bytes.Buffer 52 | cmd.Stdout = &outb 53 | cmd.Stderr = &errb 54 | fmt.Println("out:", outb.String(), "err:", errb.String()) 55 | spinner.LogMessage("docker build failed: "+err.Error(), "fatal") 56 | } 57 | 58 | //RUN DOCKER PUSH 59 | } 60 | } 61 | 62 | // CheckDockerFlag for docker flag 63 | func CheckDockerFlag() bool { 64 | var exists bool 65 | cArgs := os.Args[1:] 66 | for _, v := range cArgs { 67 | if v == "--docker" || v == "-D" { 68 | spinner.LogMessage("Building docker image 🐳", "info") 69 | exists = true 70 | } else { 71 | exists = false 72 | } 73 | } 74 | return exists 75 | } 76 | 77 | func contains(s []string, str string) bool { 78 | for _, v := range s { 79 | if v == str { 80 | return true 81 | } 82 | } 83 | return false 84 | } 85 | -------------------------------------------------------------------------------- /utils/getName.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "Builder/spinner" 5 | "os" 6 | "strings" 7 | ) 8 | 9 | // GetName does ... 10 | func GetName() string { 11 | var name string 12 | args := os.Args[1:] 13 | 14 | dirName, present := os.LookupEnv("BUILDER_DIR_NAME") 15 | if present && (dirName != "") && !(contains(args, "-n") || contains(args, "--name")) { 16 | //convert val interface{} to string to be set as env var 17 | name = dirName 18 | } else { 19 | //if args contains name flag, use name 20 | if contains(args, "-n") || contains(args, "--name") { 21 | for i, v := range args { 22 | if v == "--name" || v == "-n" { 23 | if len(args) <= i+1 { 24 | spinner.LogMessage("Please provide a name", "fatal") 25 | } else { 26 | if specialChar(args[i+1]) { 27 | spinner.LogMessage("Special Characters Not Allowed In Names", "fatal") 28 | } 29 | name = args[i+1] 30 | } 31 | } 32 | } 33 | } else if os.Getenv("BUILDER_COMMAND") == "true" || os.Getenv("BUILDER_DOCKER_COMMAND") == "true" { 34 | //use current dir name if no --name flag and using builder cmd 35 | path, err := os.Getwd() 36 | if err != nil { 37 | spinner.LogMessage("error getting builder command directory", "error") 38 | } 39 | name = path[strings.LastIndex(path, "/")+1:] 40 | 41 | // if includes '\' instead, remove them 42 | if strings.Contains(name, "\\") { 43 | name = path[strings.LastIndex(path, "\\")+1:] 44 | } 45 | 46 | } else { 47 | //if init or config and no --name flag, use repo name 48 | repoURL := os.Args[2] 49 | name = repoURL[strings.LastIndex(repoURL, "/")+1:] 50 | 51 | //if .git still in the name, remove it 52 | if strings.HasSuffix(name, ".git") { 53 | name = strings.TrimSuffix(name, ".git") 54 | } 55 | } 56 | os.Setenv("BUILDER_DIR_NAME", name) 57 | } 58 | return name 59 | } 60 | 61 | func specialChar(str string) bool { 62 | hasSpecialCharacter := false 63 | 64 | f := func(r rune) bool { 65 | return r < 'A' || r > 'z' 66 | } 67 | 68 | if strings.IndexFunc(str, f) != -1 { 69 | hasSpecialCharacter = true 70 | } 71 | 72 | return hasSpecialCharacter 73 | } 74 | -------------------------------------------------------------------------------- /utils/getRepoURL.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "Builder/spinner" 5 | "os" 6 | "os/exec" 7 | ) 8 | 9 | func GetRepoURL() string { 10 | args := os.Args[1:] 11 | 12 | //grab URL first 13 | var repo string 14 | for i, v := range args { 15 | if v == "init" || v == "config" { 16 | if len(args) <= i+1 { 17 | // logger.ErrorLogger.Println("No Repo Url Provided") 18 | spinner.LogMessage("No Repo Url Provided", "fatal") 19 | 20 | } else { 21 | repo = args[i+1] 22 | } 23 | } 24 | } 25 | if repo == "" { 26 | // Get repo name from git config file 27 | out, err := exec.Command("git", "config", "--get", "remote.origin.url").Output() 28 | if err != nil { 29 | spinner.LogMessage("Can't find git URL. Please provide it in the builder.yaml", "info") 30 | return "" 31 | } 32 | 33 | repo = string(out[:len(out)-1]) // Get rid of last char because it is a newline char 34 | 35 | if repo == "" { 36 | if os.Getenv("GIT_URL") != "" { 37 | repo = os.Getenv("GIT_URL") 38 | } else { 39 | spinner.LogMessage("Can't find git URL. Please provide it in the builder.yaml", "info") 40 | } 41 | } 42 | 43 | } 44 | return repo 45 | } 46 | -------------------------------------------------------------------------------- /utils/help.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | // Help is application info 9 | func Help() { 10 | cArgs := os.Args[1:] 11 | var helpExists bool 12 | 13 | for _, v := range cArgs { 14 | if v == "--help" || v == "-h" { 15 | helpExists = true 16 | } 17 | } 18 | 19 | //check for help flag or builder cmd to print info 20 | if (os.Getenv("BUILDER_COMMAND") == "true") || helpExists { 21 | fmt.Println(` 22 | 🔨 BUILDER 🔨 23 | 24 | #%&&&% ,&& 25 | ##. #&&&&&&&&& &&&&& 26 | .&&&# &&&&/ 27 | .&&&% &&&& 28 | .&&&# &&&&, 29 | .&&&% &&&&&&&&&& 30 | .&&&# ......,#&&&&% 31 | .&&&# &&&& 32 | .&&&# #&&&. 33 | .&&&# %&&&# 34 | .&&&% &&&&&&&&&&&&. 35 | .&&&% &&&&&&&#, 36 | 37 | Commands 38 | 39 | * builder init: auto-build a project that doesn't have a builder yaml (repo needed) 40 | - ex: builder init 41 | * builder config: build project w/ a builder.yaml (repo needed) 42 | - ex: builder config 43 | * builder push [optional flags]: pushes build metadata and logs JSON to provided url (url needed in line or in builder.yaml) 44 | - optional flag: '--save' to automate "push" process for future builds 45 | - ex: builder push 46 | * builder: build project w/ builder.yaml while in the projects directory (no repo needed) 47 | - ex: builder 48 | * builder gui: display the Builder GUI (requires Chrome for use) 49 | 50 | Flags 51 | 52 | * '--help' or '-h': provide info for Builder 53 | * '--output' or '-o': user defined output path for artifact 54 | * '--name' or '-n': user defined project name 55 | * '--branch' or '-b': specify repo branch 56 | * '--debug' or '-d': show Builder log output 57 | * '--verbose' or '-v': show log output for project being built 58 | * '--docker' or '-D': build Docker image 59 | 60 | 61 | builder.yaml params 62 | 63 | * projectname: provide name for project 64 | - ("helloworld", etc) 65 | * projectpath: provide path for project to be built 66 | - ("/Users/Name/Projects", etc) 67 | * projecttype: provide language/framework being used 68 | - ("Node", "Java", "Go", "Rust", "Python", "C#", "Ruby") 69 | * buildtool: provide tool used to install dependencies/build project 70 | - ("maven", "npm", "bundler", "pipenv", etc) 71 | * buildfile: provide file name needed to install dep/build project 72 | - Can be any user specified file. ("myCoolProject.go", "package.json" etc) 73 | * prebuildcmd: for C/C++ projects only. Provide command to run before configcmd and buildcmd 74 | - ("autoreconf -vfi", "./autogen.sh", etc) 75 | * configcmd: for C/C++ projects only. provide full command to configure C/C++ project before running buildcmd 76 | - ("./configure") 77 | * buildcmd: provide full command to build/compile project 78 | - ("npm install --silent", "mvn -o package", anything not provided by the Builder as a default) 79 | * artifactlist: provide comma seperated list of artifact names as string 80 | - ("artifact", "artifact.exe", "artifact.rpm,artifact2.rpm,artifact3.rpm", etc) 81 | * outputpath: provide path for artifact to be sent 82 | - ("/Users/Name/Artifacts", etc) 83 | * repobranch: specify repo branch name 84 | - (“feature/“new-branch”) 85 | * docker: generate docker image 86 | - dockerfile: name of dockerfile 87 | - registry: registry to push docker image to 88 | - version: tag to give docker image 89 | * push: 90 | - url: url to push build metadata and logs JSON to 91 | - auto: (true/false) whether to automate pushing process for future builds 92 | * appicon: specify url to app icon image 93 | - ("http://domain.co/path/to/app_icon.png") 94 | `) 95 | os.Exit(0) 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /utils/log/log.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path/filepath" 7 | 8 | "go.uber.org/zap" 9 | "go.uber.org/zap/zapcore" 10 | ) 11 | 12 | var logger *zap.Logger 13 | 14 | func NewLogger(logFileName string, path string) (*zap.Logger, func()) { 15 | defaultLogLevel := zapcore.Level(logLevel) 16 | 17 | config := zap.NewProductionEncoderConfig() 18 | config.TimeKey = "timestamp" 19 | config.EncodeTime = zapcore.ISO8601TimeEncoder 20 | 21 | //logfile, _ := os.OpenFile(filepath.Join(path, logFileName+".json"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) 22 | 23 | writer, closeFile, err := zap.Open(filepath.Join(path, logFileName+".json")) 24 | if err != nil { 25 | fmt.Println("logger err") 26 | } 27 | 28 | // If debug flag given display caller in log and print build logs to console 29 | args := os.Args[1:] 30 | verboseFlag := false 31 | debugFlag := false 32 | for i := 0; i < len(args); i++ { 33 | if args[i] == "-v" || args[i] == "--verbose" { 34 | verboseFlag = true 35 | } 36 | if args[i] == "-d" || args[i] == "--debug" { 37 | debugFlag = true 38 | } 39 | } 40 | 41 | var core zapcore.Core 42 | 43 | // If verbose flag given display build logs to console as well as to file 44 | if verboseFlag { 45 | fileEncoder := zapcore.NewJSONEncoder(config) 46 | consoleEncoder := zapcore.NewConsoleEncoder(config) 47 | core = zapcore.NewTee( 48 | zapcore.NewCore(fileEncoder, writer, defaultLogLevel), 49 | zapcore.NewCore(consoleEncoder, zapcore.AddSync(os.Stdout), defaultLogLevel), 50 | ) 51 | } else { 52 | fileEncoder := zapcore.NewJSONEncoder(config) 53 | core = zapcore.NewTee( 54 | zapcore.NewCore(fileEncoder, writer, defaultLogLevel), 55 | ) 56 | } 57 | 58 | // If debug flag given add Builder caller to build logs 59 | if debugFlag { 60 | logger = zap.New(core, zap.AddCaller(), zap.AddStacktrace(zapcore.ErrorLevel)) 61 | } else { 62 | logger = zap.New(core, zap.AddStacktrace(zapcore.ErrorLevel)) 63 | } 64 | 65 | return logger, closeFile 66 | } 67 | 68 | func init() { 69 | args := os.Args[1:] 70 | 71 | // If debug flag given display Builder logs to console 72 | for i := 0; i < len(args); i++ { 73 | if args[i] == "-d" || args[i] == "--debug" { 74 | logger, _ := zap.NewDevelopment() 75 | defer logger.Sync() 76 | 77 | zap.ReplaceGlobals(logger) 78 | } 79 | } 80 | } 81 | 82 | type Level int 83 | 84 | const ( 85 | DEBUG Level = iota 86 | INFO 87 | WARNING 88 | ERROR 89 | ErrorFATAL 90 | ) 91 | 92 | var logLevel Level 93 | -------------------------------------------------------------------------------- /utils/makeHidden.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "os" 5 | "os/exec" 6 | ) 7 | 8 | func MakeHidden() { 9 | hiddenDir := os.Getenv("BUILDER_HIDDEN_DIR") 10 | if os.Getenv("HIDDEN_DIR_ENABLED") == "true" { 11 | //make hiddenDir hidden 12 | exec.Command("attrib", hiddenDir, "-h").Run() 13 | //make contents read-only 14 | exec.Command("chmod", "-R", "0444", hiddenDir).Run() 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /utils/metadata.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "Builder/spinner" 5 | "crypto/sha256" 6 | "fmt" 7 | "runtime" 8 | "sync" 9 | 10 | "encoding/json" 11 | "net" 12 | "os" 13 | "os/exec" 14 | "os/user" 15 | "path/filepath" 16 | "strings" 17 | 18 | "golang.org/x/text/cases" 19 | "golang.org/x/text/language" 20 | "gopkg.in/yaml.v2" 21 | ) 22 | 23 | func Metadata(path string) { 24 | //Metedata 25 | projectName := GetName() 26 | 27 | caser := cases.Title(language.English) 28 | projectType := caser.String(os.Getenv("BUILDER_PROJECT_TYPE")) 29 | 30 | // If we are running the builder docker command we will not have 31 | // artifact to display in docker metadata so leave as empty 32 | var artifactName, artifactChecksums string 33 | if os.Getenv("BUILDER_DOCKER_COMMAND") == "true" { 34 | artifactName = "" 35 | artifactChecksums = "" 36 | } else { 37 | artifactName = os.Getenv("BUILDER_ARTIFACT_NAMES") 38 | artifactChecksums = GetArtifactChecksum() 39 | } 40 | 41 | builderPath, _ := os.Getwd() 42 | artifactPath := os.Getenv("BUILDER_ARTIFACT_DIR") 43 | var artifactLocation string 44 | if os.Getenv("BUILDER_OUTPUT_PATH") != "" { 45 | artifactLocation = os.Getenv("BUILDER_OUTPUT_PATH") 46 | } else { 47 | if os.Getenv("BUILDER_DIR_PATH") != "" { 48 | if artifactPath[0:1] == "." { 49 | artifactPath = artifactPath[1:] 50 | artifactLocation = builderPath + artifactPath 51 | } else { 52 | artifactLocation = artifactPath 53 | } 54 | } else { 55 | artifactPath = artifactPath[1:] 56 | artifactLocation = builderPath + artifactPath 57 | } 58 | } 59 | 60 | logsPath := os.Getenv("BUILDER_LOGS_DIR") 61 | var logsLocation string 62 | if strings.HasPrefix(logsPath, "./") { 63 | logsLocation = builderPath + "/" + logsPath[2:] + "/logs.json" 64 | } else { 65 | logsLocation = logsPath + "/logs.json" 66 | } 67 | 68 | ip := GetIPAdress().String() 69 | 70 | userName := GetUserData().Username 71 | 72 | // If on Windows, remove computer ID prefix from returned username 73 | if runtime.GOOS == "windows" { 74 | splitString := strings.Split(userName, "\\") 75 | userName = splitString[1] 76 | } 77 | 78 | homeDir := GetUserData().HomeDir 79 | startTime := os.Getenv("BUILD_START_TIME") 80 | endTime := os.Getenv("BUILD_END_TIME") 81 | 82 | var gitURL = GetRepoURL() 83 | _, masterGitHash := GitMasterNameAndHash() 84 | 85 | var branchName string 86 | if os.Getenv("BUILDER_COMMAND") == "true" { 87 | if os.Getenv("REPO_BRANCH_NAME") != "" { 88 | branchName = os.Getenv("REPO_BRANCH_NAME") 89 | } else { 90 | out, err := exec.Command("git", "symbolic-ref", "--short", "HEAD").Output() 91 | if err != nil { 92 | spinner.LogMessage("Can't get current branch name. Please provide it in the builder.yaml.", "info") 93 | branchName = "" 94 | } else { 95 | // remove \n at end of returned branch name before returning 96 | branchName = strings.TrimSuffix(string(out), "\n") 97 | } 98 | } 99 | } else { 100 | branchName = os.Getenv("REPO_BRANCH_NAME") 101 | } 102 | 103 | appIcon := os.Getenv("BUILD_APP_ICON") 104 | 105 | //Contains a collection of files with user's metadata 106 | userMetaData := AllMetaData{ 107 | ProjectName: projectName, 108 | ProjectType: projectType, 109 | ArtifactName: artifactName, 110 | ArtifactChecksums: artifactChecksums, 111 | ArtifactLocation: artifactLocation, 112 | LogsLocation: logsLocation, 113 | UserName: userName, 114 | HomeDir: homeDir, 115 | IP: ip, 116 | StartTime: startTime, 117 | EndTime: endTime, 118 | GitURL: gitURL, 119 | MasterGitHash: masterGitHash, 120 | BranchName: branchName, 121 | AppIcon: appIcon, 122 | } 123 | 124 | OutputMetadata(path, &userMetaData) 125 | 126 | } 127 | 128 | // AllMetaData holds the stuct of all the arguments 129 | type AllMetaData struct { 130 | ProjectName string 131 | ProjectType string 132 | ArtifactName string 133 | ArtifactChecksums string 134 | ArtifactLocation string 135 | LogsLocation string 136 | UserName string 137 | HomeDir string 138 | IP string 139 | StartTime string 140 | EndTime string 141 | GitURL string 142 | MasterGitHash string 143 | BranchName string 144 | AppIcon string 145 | } 146 | 147 | // GetUserData return username and userdir 148 | func GetUserData() *user.User { 149 | user, err := user.Current() 150 | if err != nil { 151 | panic(err) 152 | 153 | } 154 | 155 | return user 156 | 157 | } 158 | 159 | // GetIPAdress Get preferred outbound ip of this machine 160 | func GetIPAdress() net.IP { 161 | conn, err := net.Dial("udp", "8.8.8.8:80") 162 | if err != nil { 163 | spinner.LogMessage("could not connect to outbound ip: "+err.Error(), "fatal") 164 | } 165 | defer conn.Close() 166 | 167 | localAddr := conn.LocalAddr().(*net.UDPAddr) 168 | 169 | return localAddr.IP 170 | } 171 | 172 | // OutputJSONall outputs allMetaData struct in JSON format 173 | func OutputMetadata(path string, allData *AllMetaData) { 174 | yamlData, _ := yaml.Marshal(allData) 175 | jsonData, _ := json.Marshal(allData) 176 | 177 | err := os.WriteFile(path+"/metadata.json", jsonData, 0666) 178 | err2 := os.WriteFile(path+"/metadata.yaml", yamlData, 0666) 179 | 180 | if err != nil { 181 | spinner.LogMessage("JSON Metadata creation unsuccessful.", "fatal") 182 | } 183 | 184 | if err2 != nil { 185 | spinner.LogMessage("YAML Metadata creation unsuccessful.", "fatal") 186 | } 187 | } 188 | 189 | // Gets the name of the repo's master branch and its hash 190 | func GitMasterNameAndHash() (string, string) { 191 | hiddenDir := os.Getenv("BUILDER_HIDDEN_DIR") 192 | currentDir, _ := os.Getwd() 193 | var dirToRunIn string 194 | if os.Getenv("BUILDER_COMMAND") == "true" || os.Getenv("BUILDER_DOCKER_COMMAND") == "true" { 195 | dirToRunIn = currentDir 196 | } else { 197 | dirToRunIn, _ = filepath.Abs(hiddenDir) 198 | } 199 | 200 | //outputs the name of the master branch 201 | cmd := exec.Command("git", "symbolic-ref", "refs/remotes/origin/HEAD", "--short") 202 | if os.Getenv("BUILDER_COMMAND") != "true" { 203 | cmd.Dir = dirToRunIn 204 | } 205 | output, err := cmd.Output() 206 | if err != nil { 207 | // Can't find master branch name so return undefined 208 | return "undefined", "undefined" 209 | } 210 | formattedOutput := strings.TrimSuffix(string(output), "\n") 211 | masterBranchName := formattedOutput[strings.LastIndex(formattedOutput, "/")+1:] 212 | 213 | //outputs the hash of the provided branch 214 | cmd = exec.Command("git", "rev-parse", masterBranchName) 215 | if os.Getenv("BUILDER_COMMAND") != "true" { 216 | cmd.Dir = dirToRunIn 217 | } 218 | hashOutput, hashErr := cmd.Output() 219 | if hashErr != nil { 220 | return "undefined", "undefined" 221 | } 222 | masterBranchHash := strings.TrimSuffix(string(hashOutput), "\n") 223 | 224 | return masterBranchName, masterBranchHash 225 | } 226 | 227 | type Artifacts struct { 228 | name string 229 | checksum string 230 | } 231 | 232 | func GetArtifactChecksum() string { 233 | artifactDir := os.Getenv("BUILDER_ARTIFACT_DIR") 234 | 235 | files, err := os.ReadDir(artifactDir) 236 | if err != nil { 237 | spinner.LogMessage(err.Error(), "fatal") 238 | } 239 | 240 | var checksum, checksums string 241 | var checksumsArray []Artifacts 242 | wg := sync.WaitGroup{} 243 | wg.Add(1) 244 | go func() { 245 | defer wg.Done() 246 | 247 | for _, file := range files { 248 | if file.Name() != "metadata.json" && file.Name() != "metadata.yaml" { 249 | // Get checksum of artifact 250 | artifact, err := os.ReadFile(artifactDir + "/" + file.Name()) 251 | if err != nil { 252 | spinner.LogMessage(err.Error(), "fatal") 253 | } 254 | 255 | sum := sha256.Sum256(artifact) 256 | checksum = fmt.Sprintf("%x", sum) 257 | 258 | var artifactObj Artifacts 259 | artifactObj.name = file.Name() 260 | artifactObj.checksum = checksum 261 | 262 | checksumsArray = append(checksumsArray, artifactObj) 263 | checksums = fmt.Sprintf("%+v", checksumsArray) 264 | } 265 | } 266 | }() 267 | wg.Wait() 268 | 269 | return checksums 270 | } 271 | 272 | func GetBuildID() string { 273 | artifactDir := os.Getenv("BUILDER_ARTIFACT_DIR") 274 | var checksum string 275 | 276 | // Get checksum of metadata.json 277 | metadata, err := os.ReadFile(artifactDir + "/metadata.json") 278 | if err != nil { 279 | spinner.LogMessage(err.Error(), "fatal") 280 | } 281 | 282 | sum := sha256.Sum256(metadata) 283 | checksum = fmt.Sprintf("%x", sum) 284 | 285 | // Only return first 10 char of sum 286 | return checksum[0:9] 287 | } 288 | 289 | func StoreBuildMetadataLocally() { 290 | // Read in build JSON data from build artifact directory 291 | artifactDir := os.Getenv("BUILDER_ARTIFACT_DIR") 292 | 293 | metadataJSON, err := os.ReadFile(artifactDir + "/metadata.json") 294 | if err != nil { 295 | spinner.LogMessage("Cannot find metadata.json file: "+err.Error(), "fatal") 296 | } 297 | 298 | // Unmarshal json data so we can add buildID 299 | var metadataFormat map[string]interface{} 300 | json.Unmarshal(metadataJSON, &metadataFormat) 301 | metadataFormat["BuildID"] = GetBuildID() 302 | 303 | updatedMetadataJSON, err := json.Marshal(metadataFormat) 304 | if err != nil { 305 | spinner.LogMessage("Cannot marshal metadata: "+err.Error(), "fatal") 306 | } 307 | 308 | // Check if builds.json exists and append to it, if not, create it 309 | textToAppend := string(updatedMetadataJSON) + ",\n" 310 | 311 | var pathToBuildsJSON string 312 | 313 | if runtime.GOOS == "windows" { 314 | appDataDir := os.Getenv("LOCALAPPDATA") 315 | if appDataDir == "" { 316 | appDataDir = os.Getenv("APPDATA") 317 | } 318 | 319 | pathToBuildsJSON = appDataDir + "/Builder/builds.json" 320 | } else { 321 | user, _ := user.Current() 322 | homeDir := user.HomeDir 323 | 324 | pathToBuildsJSON = homeDir + "/.builder/builds.json" 325 | } 326 | 327 | buildsFile, err := os.OpenFile(pathToBuildsJSON, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) 328 | 329 | if err != nil { 330 | spinner.LogMessage("Could not create builds.json file: "+err.Error(), "fatal") 331 | } 332 | if _, err := buildsFile.WriteString(textToAppend); err != nil { 333 | spinner.LogMessage("Could not write to builds.json file: "+err.Error(), "fatal") 334 | } 335 | if err := buildsFile.Close(); err != nil { 336 | spinner.LogMessage("Could not close builds.json file: "+err.Error(), "fatal") 337 | } 338 | } 339 | -------------------------------------------------------------------------------- /utils/pushBuildData.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "Builder/spinner" 5 | "bufio" 6 | "bytes" 7 | "encoding/json" 8 | "fmt" 9 | "io" 10 | "mime/multipart" 11 | "net/http" 12 | "os" 13 | "strings" 14 | ) 15 | 16 | func PushBuildData() { 17 | pushURL := os.Getenv("BUILDER_PUSH_URL") 18 | artifactDir := os.Getenv("BUILDER_ARTIFACT_DIR") 19 | 20 | // Read in build JSON data from build artifact directory 21 | metadataJSON, errMetadataRead := os.ReadFile(artifactDir + "/metadata.json") 22 | if errMetadataRead != nil { 23 | spinner.LogMessage("Can't find / open metadata file: "+errMetadataRead.Error(), "fatal") 24 | } 25 | 26 | // Read in logs JSON data from logs directory and add to metadata json 27 | lastSlash := strings.LastIndex(artifactDir, "/") 28 | logsFilePath := artifactDir[0:lastSlash] + "/logs/logs.json" 29 | validLogsJSONString := getLogsJSON(logsFilePath) 30 | 31 | var bodyFormat map[string]interface{} 32 | json.Unmarshal(metadataJSON, &bodyFormat) 33 | 34 | bodyFormat["logs"] = validLogsJSONString 35 | 36 | bodyJSON, errBodyMarshal := json.Marshal(bodyFormat) 37 | if errBodyMarshal != nil { 38 | spinner.LogMessage("Error encoding JSON body: "+errBodyMarshal.Error(), "fatal") 39 | } 40 | 41 | responseBody := bytes.NewBuffer(bodyJSON) 42 | 43 | // Send metadata+logs to user provided url 44 | req, _ := http.NewRequest("POST", pushURL, responseBody) 45 | req.Header.Add("Content-Type", "application/json") 46 | 47 | client := &http.Client{} 48 | resp, errSend := client.Do(req) 49 | if errSend != nil { 50 | spinner.LogMessage("Error sending build metadata and logs: "+errSend.Error(), "fatal") 51 | } else { 52 | spinner.LogMessage("Metadata+logs data pushed to provided url", "info") 53 | } 54 | defer resp.Body.Close() 55 | 56 | // Send artifact(s) to user provided url 57 | artifactList := os.Getenv("BUILDER_ARTIFACT_LIST") 58 | artifactArray := strings.Split(artifactList, ",") 59 | 60 | buf := bytes.NewBuffer(nil) 61 | m := multipart.NewWriter(buf) 62 | 63 | for i, artifact := range artifactArray { 64 | part, err := m.CreateFormFile("artifact"+fmt.Sprint(i), artifact) 65 | if err != nil { 66 | spinner.LogMessage("Error posting artifact(s) to url.", "fatal") 67 | } 68 | 69 | file, err := os.Open(artifactDir + "/" + artifact) 70 | if err != nil { 71 | spinner.LogMessage("Error posting artifact(s) to url. Couldn't open artifact file: "+err.Error(), "fatal") 72 | } 73 | defer file.Close() 74 | if _, err = io.Copy(part, file); err != nil { 75 | return 76 | } 77 | } 78 | m.Close() 79 | 80 | artifactReq, _ := http.NewRequest("POST", pushURL, buf) 81 | req.Header.Add("Content-Type", m.FormDataContentType()) 82 | 83 | artifactResp, errSend := client.Do(artifactReq) 84 | if errSend != nil { 85 | spinner.LogMessage("Error sending artifact(s) to push url: "+errSend.Error(), "fatal") 86 | } 87 | defer artifactResp.Body.Close() 88 | 89 | spinner.LogMessage("artifact(s) pushed to provided url", "info") 90 | } 91 | 92 | func getLogsJSON(path string) string { 93 | logsFile, err := os.Open(path) 94 | if err != nil { 95 | spinner.LogMessage("Can't find / open log file: "+err.Error(), "fatal") 96 | } 97 | defer logsFile.Close() 98 | 99 | var lines []string 100 | scanner := bufio.NewScanner(logsFile) 101 | for scanner.Scan() { 102 | lines = append(lines, scanner.Text()) 103 | } 104 | 105 | // Re-format zap logger output to valid JSON 106 | asString := strings.Join(lines, ",") 107 | 108 | jsonString := "[" + asString + "]" 109 | 110 | return jsonString 111 | } 112 | -------------------------------------------------------------------------------- /yaml/createBuilderYaml.go: -------------------------------------------------------------------------------- 1 | package yaml 2 | 3 | import ( 4 | "Builder/spinner" 5 | "os" 6 | 7 | "gopkg.in/yaml.v2" 8 | ) 9 | 10 | type BuilderYaml struct { 11 | ProjectName string 12 | ProjectPath string 13 | ProjectType string 14 | BuildsDir string 15 | BuildTool string 16 | BuildFile string 17 | PreBuildCmd string 18 | ConfigCmd string 19 | BuildCmd string 20 | ArtifactList string 21 | OutputPath string 22 | RepoBranch string 23 | Docker map[string]interface{} 24 | Push map[string]interface{} 25 | AppIcon string 26 | } 27 | 28 | func CreateBuilderYaml(fullPath string) { 29 | projectName := os.Getenv("BUILDER_DIR_NAME") 30 | projectPath := os.Getenv("BUILDER_DIR_PATH") 31 | projectType := os.Getenv("BUILDER_PROJECT_TYPE") 32 | buildsDir := os.Getenv("BUILDER_BUILDS_DIR") 33 | buildTool := os.Getenv("BUILDER_BUILD_TOOL") 34 | buildFile := os.Getenv("BUILDER_BUILD_FILE") 35 | preBuildCmd := os.Getenv("BUILDER_PREBUILD_COMMAND") 36 | configCmd := os.Getenv("BUILDER_CONFIG_COMMAND") 37 | buildCmd := os.Getenv("BUILDER_BUILD_COMMAND") 38 | artifactList := os.Getenv("BUILDER_ARTIFACT_LIST") 39 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 40 | repoBranch := os.Getenv("REPO_BRANCH") 41 | var docker map[string]interface{} 42 | if os.Getenv("BUILDER_DOCKERFILE") != "" && os.Getenv("BUILDER_DOCKER_REGISTRY") != "" && os.Getenv("BUILDER_DOCKER_VERSION") != "" { 43 | docker = map[string]interface{}{ 44 | "dockerfile": os.Getenv("BUILDER_DOCKERFILE"), 45 | "registry": os.Getenv("BUILDER_DOCKER_REGISTRY"), 46 | "version": os.Getenv("BUILDER_DOCKER_VERSION"), 47 | } 48 | } else if os.Getenv("BUILDER_DOCKERFILE") != "" && os.Getenv("BUILDER_DOCKER_REGISTRY") != "" { 49 | docker = map[string]interface{}{ 50 | "dockerfile": os.Getenv("BUILDER_DOCKERFILE"), 51 | "registry": os.Getenv("BUILDER_DOCKER_REGISTRY"), 52 | } 53 | } else if os.Getenv("BUILDER_DOCKERFILE") != "" && os.Getenv("BUILDER_DOCKER_VERSION") != "" { 54 | docker = map[string]interface{}{ 55 | "dockerfile": os.Getenv("BUILDER_DOCKERFILE"), 56 | "version": os.Getenv("BUILDER_DOCKER_VERSION"), 57 | } 58 | } else if os.Getenv("BUILDER_DOCKER_REGISTRY") != "" && os.Getenv("BUILDER_DOCKER_VERSION") != "" { 59 | docker = map[string]interface{}{ 60 | "registry": os.Getenv("BUILDER_DOCKER_REGISTRY"), 61 | "version": os.Getenv("BUILDER_DOCKER_VERSION"), 62 | } 63 | } else if os.Getenv("BUILDER_DOCKERFILE") != "" { 64 | docker = map[string]interface{}{ 65 | "dockerfile": os.Getenv("BUILDER_DOCKERFILE"), 66 | } 67 | } else if os.Getenv("BUILDER_DOCKER_REGISTRY") != "" { 68 | docker = map[string]interface{}{ 69 | "registry": os.Getenv("BUILDER_DOCKER_REGISTRY"), 70 | } 71 | } else if os.Getenv("BUILDER_DOCKER_VERSION") != "" { 72 | docker = map[string]interface{}{ 73 | "version": os.Getenv("BUILDER_DOCKER_VERSION"), 74 | } 75 | } else { 76 | docker = map[string]interface{}{} 77 | } 78 | 79 | var push map[string]interface{} 80 | if os.Getenv("BUILDER_PUSH_AUTO") != "" { 81 | push = map[string]interface{}{ 82 | "url": os.Getenv("BUILDER_PUSH_URL"), 83 | "auto": os.Getenv("BUILDER_PUSH_AUTO"), 84 | } 85 | } else { 86 | push = map[string]interface{}{ 87 | "url": os.Getenv("BUILDER_PUSH_URL"), 88 | } 89 | } 90 | appIcon := os.Getenv("BUILD_APP_ICON") 91 | 92 | builderData := BuilderYaml{ 93 | ProjectName: projectName, 94 | ProjectPath: projectPath, 95 | ProjectType: projectType, 96 | BuildsDir: buildsDir, 97 | BuildTool: buildTool, 98 | BuildFile: buildFile, 99 | PreBuildCmd: preBuildCmd, 100 | ConfigCmd: configCmd, 101 | BuildCmd: buildCmd, 102 | ArtifactList: artifactList, 103 | OutputPath: outputPath, 104 | RepoBranch: repoBranch, 105 | Docker: docker, 106 | Push: push, 107 | AppIcon: appIcon, 108 | } 109 | 110 | OutputData(fullPath, &builderData) 111 | } 112 | 113 | func UpdateBuilderYaml(fullPath string) { 114 | 115 | projectName := os.Getenv("BUILDER_DIR_NAME") 116 | projectPath := os.Getenv("BUILDER_DIR_PATH") 117 | projectType := os.Getenv("BUILDER_PROJECT_TYPE") 118 | buildsDir := os.Getenv("BUILDER_BUILDS_DIR") 119 | buildTool := os.Getenv("BUILDER_BUILD_TOOL") 120 | buildFile := os.Getenv("BUILDER_BUILD_FILE") 121 | preBuildCmd := os.Getenv("BUILDER_PREBUILD_COMMAND") 122 | configCmd := os.Getenv("BUILDER_CONFIG_COMMAND") 123 | buildCmd := os.Getenv("BUILDER_BUILD_COMMAND") 124 | artifactList := os.Getenv("BUILDER_ARTIFACT_LIST") 125 | outputPath := os.Getenv("BUILDER_OUTPUT_PATH") 126 | repoBranch := os.Getenv("REPO_BRANCH") 127 | docker := map[string]interface{}{ 128 | "dockerfile": os.Getenv("BUILDER_DOCKERFILE"), 129 | "registry": os.Getenv("BUILDER_DOCKER_REGISTRY"), 130 | "version": os.Getenv("BUILDER_DOCKER_VERSION"), 131 | } 132 | 133 | var push map[string]interface{} 134 | if os.Getenv("BUILDER_PUSH_AUTO") == "" { 135 | push = map[string]interface{}{ 136 | "url": os.Getenv("BUILDER_PUSH_URL"), 137 | "auto": "false", 138 | } 139 | } else { 140 | push = map[string]interface{}{ 141 | "url": os.Getenv("BUILDER_PUSH_URL"), 142 | "auto": os.Getenv("BUILDER_PUSH_AUTO"), 143 | } 144 | } 145 | appIcon := os.Getenv("BUILD_APP_ICON") 146 | 147 | builderData := BuilderYaml{ 148 | ProjectName: projectName, 149 | ProjectPath: projectPath, 150 | ProjectType: projectType, 151 | BuildsDir: buildsDir, 152 | BuildTool: buildTool, 153 | BuildFile: buildFile, 154 | PreBuildCmd: preBuildCmd, 155 | ConfigCmd: configCmd, 156 | BuildCmd: buildCmd, 157 | ArtifactList: artifactList, 158 | OutputPath: outputPath, 159 | RepoBranch: repoBranch, 160 | Docker: docker, 161 | Push: push, 162 | AppIcon: appIcon, 163 | } 164 | 165 | _, err := os.Stat(fullPath + "/builder.yaml") 166 | if err == nil { 167 | OutputData(fullPath, &builderData) 168 | spinner.LogMessage("builder.yaml updated ✅", "info") 169 | } 170 | } 171 | 172 | func OutputData(fullPath string, allData *BuilderYaml) { 173 | yamlData, _ := yaml.Marshal(allData) 174 | 175 | err := os.WriteFile(fullPath+"/builder.yaml", yamlData, 0755) 176 | if err != nil { 177 | spinner.LogMessage("builder.yaml creation failed ⛔️: "+err.Error(), "fatal") 178 | } 179 | 180 | spinner.LogMessage("builder.yaml created ✅", "info") 181 | } 182 | -------------------------------------------------------------------------------- /yaml/setConfigEnvs.go: -------------------------------------------------------------------------------- 1 | package yaml 2 | 3 | import ( 4 | "Builder/utils" 5 | "fmt" 6 | "os" 7 | "runtime" 8 | "strings" 9 | ) 10 | 11 | func ConfigEnvs(byi interface{}) { 12 | //change interface{} into map interface{} 13 | bldyml, _ := byi.(map[string]interface{}) 14 | 15 | //~~~Check for specific key and create env var based on value~~~ 16 | 17 | //check for dir name 18 | if val, ok := bldyml["projectname"]; ok { 19 | _, present := os.LookupEnv("BUILDER_DIR_NAME") 20 | if !present { 21 | //convert val interface{} to string to be set as env var 22 | valStr := fmt.Sprintf("%v", val) 23 | os.Setenv("BUILDER_DIR_NAME", valStr) 24 | } 25 | } else { 26 | os.Setenv("BUILDER_DIR_NAME", "") 27 | } 28 | 29 | //check for dir path 30 | if val, ok := bldyml["projectpath"]; ok { 31 | _, present := os.LookupEnv("BUILDER_DIR_PATH") 32 | if !present { 33 | //convert val interface{} to string to be set as env var 34 | valStr := fmt.Sprintf("%v", val) 35 | 36 | // If on windows and they specify a path that begins with '/' append to home dir 37 | if runtime.GOOS == "windows" && strings.HasPrefix(valStr, "/") { 38 | homeDir := utils.GetUserData().HomeDir 39 | os.Setenv("BUILDER_DIR_PATH", homeDir+valStr) 40 | } else { 41 | os.Setenv("BUILDER_DIR_PATH", valStr) 42 | } 43 | } 44 | } else { 45 | os.Setenv("BUILDER_DIR_PATH", "") 46 | } 47 | 48 | //check for project type 49 | if val, ok := bldyml["projecttype"]; ok { 50 | _, present := os.LookupEnv("BUILDER_PROJECT_TYPE") 51 | if !present { 52 | //convert val interface{} to string to be set as env var 53 | valStr := fmt.Sprintf("%v", val) 54 | os.Setenv("BUILDER_PROJECT_TYPE", valStr) 55 | } 56 | } else { 57 | os.Setenv("BUILDER_PROJECT_TYPE", "") 58 | } 59 | 60 | //check for different dir name to store builds 61 | if val, ok := bldyml["buildsdir"]; ok { 62 | _, present := os.LookupEnv("BUILDER_BUILDS_DIR") 63 | if !present { 64 | //convert val interface{} to string to be set as env var 65 | valStr := fmt.Sprintf("%v", val) 66 | os.Setenv("BUILDER_BUILDS_DIR", valStr) 67 | } 68 | } else { 69 | os.Setenv("BUILDER_BUILDS_DIR", "") 70 | } 71 | 72 | //check for build type 73 | if val, ok := bldyml["buildtool"]; ok { 74 | _, present := os.LookupEnv("BUILDER_BUILD_TOOL") 75 | if !present { 76 | //convert val interface{} to string to be set as env var 77 | valStr := fmt.Sprintf("%v", val) 78 | os.Setenv("BUILDER_BUILD_TOOL", valStr) 79 | } 80 | } 81 | 82 | //check for build file 83 | if val, ok := bldyml["buildfile"]; ok { 84 | _, present := os.LookupEnv("BUILDER_BUILD_FILE") 85 | if !present { 86 | //convert val interface{} to string to be set as env var 87 | valStr := fmt.Sprintf("%v", val) 88 | os.Setenv("BUILDER_BUILD_FILE", valStr) 89 | } 90 | } else { 91 | os.Setenv("BUILDER_BUILD_FILE", "") 92 | } 93 | 94 | //check for config cmd 95 | if val, ok := bldyml["prebuildcmd"]; ok { 96 | _, present := os.LookupEnv("BUILDER_PREBUILD_COMMAND") 97 | if !present { 98 | //convert val interface{} to string to be set as env var 99 | valStr := fmt.Sprintf("%v", val) 100 | os.Setenv("BUILDER_PREBUILD_COMMAND", valStr) 101 | } 102 | } 103 | 104 | //check for config cmd 105 | if val, ok := bldyml["configcmd"]; ok { 106 | _, present := os.LookupEnv("BUILDER_CONFIG_COMMAND") 107 | if !present { 108 | //convert val interface{} to string to be set as env var 109 | valStr := fmt.Sprintf("%v", val) 110 | os.Setenv("BUILDER_CONFIG_COMMAND", valStr) 111 | } 112 | } 113 | 114 | //check for build cmd 115 | if val, ok := bldyml["buildcmd"]; ok { 116 | _, present := os.LookupEnv("BUILDER_BUILD_COMMAND") 117 | if !present { 118 | //convert val interface{} to string to be set as env var 119 | valStr := fmt.Sprintf("%v", val) 120 | os.Setenv("BUILDER_BUILD_COMMAND", valStr) 121 | } 122 | } 123 | 124 | //check for output path 125 | if val, ok := bldyml["outputpath"]; ok { 126 | _, present := os.LookupEnv("BUILDER_OUTPUT_PATH") 127 | if !present { 128 | //convert val interface{} to string to be set as env var 129 | valStr := fmt.Sprintf("%v", val) 130 | 131 | // If on windows and they specify a path that begins with '/' append to home dir 132 | if runtime.GOOS == "windows" && strings.HasPrefix(valStr, "/") { 133 | homeDir := utils.GetUserData().HomeDir 134 | os.Setenv("BUILDER_OUTPUT_PATH", homeDir+valStr) 135 | } else { 136 | os.Setenv("BUILDER_OUTPUT_PATH", valStr) 137 | } 138 | } 139 | } 140 | 141 | //check for docker cmd 142 | if val, ok := bldyml["dockercmd"]; ok { 143 | _, present := os.LookupEnv("BUILDER_DOCKER_CMD") 144 | if !present { 145 | //convert val interface{} to string to be set as env var 146 | valStr := fmt.Sprintf("%v", val) 147 | os.Setenv("BUILDER_DOCKER_CMD", valStr) 148 | } 149 | } 150 | 151 | //check for global logs path 152 | if val, ok := bldyml["giturl"]; ok { 153 | _, present := os.LookupEnv("GIT_URL") 154 | if !present { 155 | //convert val interface{} to string to be set as env var 156 | valStr := fmt.Sprintf("%v", val) 157 | os.Setenv("GIT_URL", valStr) 158 | } 159 | } 160 | 161 | //check for an artifacts list 162 | if val, ok := bldyml["artifactlist"]; ok { 163 | _, present := os.LookupEnv("BUILDER_ARTIFACT_LIST") 164 | if !present { 165 | //convert val interface{} to string to be set as env var 166 | valStr := fmt.Sprintf("%v", val) 167 | os.Setenv("BUILDER_ARTIFACT_LIST", valStr) 168 | } 169 | } 170 | 171 | //check for branch repo 172 | if val, ok := bldyml["repobranch"]; ok { 173 | _, present := os.LookupEnv("REPO_BRANCH") 174 | if !present { 175 | //convert val interface{} to string to be set as env var 176 | valStr := fmt.Sprintf("%v", val) 177 | os.Setenv("REPO_BRANCH", valStr) 178 | } 179 | } 180 | 181 | //check for options to build docker image 182 | if val, ok := bldyml["docker"]; ok { 183 | switch v := val.(type) { 184 | case []interface{}: 185 | dockerfile := v[0].(map[string]interface{})["dockerfile"] 186 | registry := v[0].(map[string]interface{})["registry"] 187 | version := v[0].(map[string]interface{})["version"] 188 | 189 | if dockerfile != nil && dockerfile != "" { 190 | os.Setenv("BUILDER_DOCKERFILE", dockerfile.(string)) 191 | } 192 | if registry != nil && registry != "" { 193 | os.Setenv("BUILDER_DOCKER_REGISTRY", registry.(string)) 194 | } 195 | if version != nil && version != "" { 196 | os.Setenv("BUILDER_DOCKER_VERSION", version.(string)) 197 | } 198 | default: // type map[string]interface{} 199 | dockerfile := val.(map[string]interface{})["dockerfile"] 200 | registry := val.(map[string]interface{})["registry"] 201 | version := val.(map[string]interface{})["version"] 202 | 203 | if dockerfile != nil && dockerfile != "" { 204 | os.Setenv("BUILDER_DOCKERFILE", dockerfile.(string)) 205 | } 206 | if registry != nil && registry != "" { 207 | os.Setenv("BUILDER_DOCKER_REGISTRY", registry.(string)) 208 | } 209 | if version != nil && version != "" { 210 | os.Setenv("BUILDER_DOCKER_VERSION", version.(string)) 211 | } 212 | } 213 | } 214 | 215 | //check for options to push resulting build data 216 | if val, ok := bldyml["push"]; ok { 217 | switch v := val.(type) { 218 | case []interface{}: 219 | url := v[0].(map[string]interface{})["url"] 220 | auto := v[0].(map[string]interface{})["auto"] 221 | 222 | if url != nil && url != "" { 223 | os.Setenv("BUILDER_PUSH_URL", url.(string)) 224 | } 225 | if auto != nil { 226 | os.Setenv("BUILDER_PUSH_AUTO", auto.(string)) 227 | } 228 | default: // type map[string]interface{} 229 | url := val.(map[string]interface{})["url"] 230 | auto := val.(map[string]interface{})["auto"] 231 | 232 | if url != nil && url != "" { 233 | os.Setenv("BUILDER_PUSH_URL", url.(string)) 234 | } 235 | if auto != nil { 236 | os.Setenv("BUILDER_PUSH_AUTO", auto.(string)) 237 | } 238 | } 239 | } 240 | 241 | //check for app icon for build 242 | if val, ok := bldyml["appicon"]; ok { 243 | _, present := os.LookupEnv("BUILD_APP_ICON") 244 | if !present { 245 | //convert val interface{} to string to be set as env var 246 | valStr := fmt.Sprintf("%v", val) 247 | os.Setenv("BUILD_APP_ICON", valStr) 248 | } 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /yaml/yamlParser.go: -------------------------------------------------------------------------------- 1 | package yaml 2 | 3 | import ( 4 | "Builder/spinner" 5 | "io/ioutil" 6 | "os" 7 | 8 | "gopkg.in/yaml.v3" 9 | ) 10 | 11 | func YamlParser(yamlPath string) { 12 | // Initial declaration 13 | m := map[string]interface{}{ 14 | "key": "value", 15 | } 16 | // Dynamically add a sub-map 17 | m["sub"] = map[string]interface{}{ 18 | "deepKey": "deepValue", 19 | } 20 | // returns map 21 | var f interface{} 22 | 23 | //takes yaml path and read file 24 | source, err := ioutil.ReadFile(yamlPath) 25 | if err != nil { 26 | removeTempDir() 27 | spinner.LogMessage("failed to read builder yaml: "+err.Error(), "fatal") 28 | } 29 | 30 | //unpacks yaml file in a map int{} 31 | err = yaml.Unmarshal([]byte(source), &f) 32 | if err != nil { 33 | spinner.LogMessage(err.Error(), "error") 34 | } 35 | 36 | //pass map int{} to callback that sets env vars 37 | ConfigEnvs(f) 38 | 39 | // if env var BUILDER_COMMAND != true 40 | removeTempDir() 41 | //else 42 | } 43 | 44 | func removeTempDir() { 45 | //delete tempRepo dir 46 | err := os.RemoveAll("./tempRepo") 47 | if err != nil { 48 | spinner.LogMessage("Failed to delete tempRepo directory: "+err.Error(), "fatal") 49 | } 50 | } 51 | --------------------------------------------------------------------------------