| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | package defaults | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2017-01-14 19:12:20 +01:00
										 |  |  | 	"errors" | 
					
						
							| 
									
										
										
										
											2017-01-14 14:29:01 -02:00
										 |  |  | 	"io/ioutil" | 
					
						
							| 
									
										
										
										
											2017-03-22 21:01:29 -03:00
										 |  |  | 	"log" | 
					
						
							| 
									
										
										
										
											2017-01-14 14:29:01 -02:00
										 |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-14 20:01:32 -02:00
										 |  |  | 	"github.com/goreleaser/goreleaser/context" | 
					
						
							| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-14 15:16:29 -02:00
										 |  |  | var defaultFiles = []string{"licence", "license", "readme", "changelog"} | 
					
						
							| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Pipe for brew deployment | 
					
						
							|  |  |  | type Pipe struct{} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-14 19:41:32 +01:00
										 |  |  | // Description of the pipe | 
					
						
							| 
									
										
										
										
											2017-01-14 15:14:35 -02:00
										 |  |  | func (Pipe) Description() string { | 
					
						
							| 
									
										
										
										
											2017-01-19 10:04:41 +01:00
										 |  |  | 	return "Setting defaults" | 
					
						
							| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Run the pipe | 
					
						
							| 
									
										
										
										
											2017-01-14 19:41:32 +01:00
										 |  |  | func (Pipe) Run(ctx *context.Context) error { | 
					
						
							| 
									
										
										
										
											2017-03-22 21:01:29 -03:00
										 |  |  | 	// TODO: remove this block in next release cycle | 
					
						
							|  |  |  | 	if ctx.Config.Release.Repo != "" { | 
					
						
							|  |  |  | 		log.Println("The `release.repo` syntax is deprecated and will soon be removed. Please check the README for more info.") | 
					
						
							|  |  |  | 		ctx.Config.Release.GitHub = toRepo(ctx.Config.Release.Repo) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ctx.Config.Release.GitHub.Name == "" { | 
					
						
							| 
									
										
										
										
											2017-01-14 19:12:20 +01:00
										 |  |  | 		repo, err := remoteRepo() | 
					
						
							| 
									
										
										
										
											2017-03-22 21:01:29 -03:00
										 |  |  | 		ctx.Config.Release.GitHub = repo | 
					
						
							| 
									
										
										
										
											2017-01-14 19:12:20 +01:00
										 |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2017-01-14 19:47:15 -02:00
										 |  |  | 			return errors.New("failed reading repo from git: " + err.Error()) | 
					
						
							| 
									
										
										
										
											2017-01-14 19:12:20 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-22 21:06:37 -03:00
										 |  |  | 	// TODO: remove this block in next release cycle | 
					
						
							|  |  |  | 	if ctx.Config.Build.BinaryName != "" { | 
					
						
							|  |  |  | 		log.Println("The `build.binary_name` syntax is deprecated and will soon be removed. Please check the README for more info.") | 
					
						
							|  |  |  | 		ctx.Config.Build.Binary = ctx.Config.Build.BinaryName | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if ctx.Config.Build.Binary == "" { | 
					
						
							|  |  |  | 		ctx.Config.Build.Binary = ctx.Config.Release.GitHub.Name | 
					
						
							| 
									
										
										
										
											2017-01-14 19:29:30 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-14 14:06:57 -02:00
										 |  |  | 	if ctx.Config.Build.Main == "" { | 
					
						
							| 
									
										
										
										
											2017-02-26 13:01:48 -03:00
										 |  |  | 		ctx.Config.Build.Main = "." | 
					
						
							| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-14 19:47:15 -02:00
										 |  |  | 	if len(ctx.Config.Build.Goos) == 0 { | 
					
						
							|  |  |  | 		ctx.Config.Build.Goos = []string{"linux", "darwin"} | 
					
						
							| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-14 19:47:15 -02:00
										 |  |  | 	if len(ctx.Config.Build.Goarch) == 0 { | 
					
						
							|  |  |  | 		ctx.Config.Build.Goarch = []string{"amd64", "386"} | 
					
						
							| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-14 14:06:57 -02:00
										 |  |  | 	if ctx.Config.Build.Ldflags == "" { | 
					
						
							| 
									
										
										
										
											2017-03-25 20:24:38 -03:00
										 |  |  | 		ctx.Config.Build.Ldflags = "-s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}" | 
					
						
							| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-14 19:47:15 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-14 14:06:57 -02:00
										 |  |  | 	if ctx.Config.Archive.NameTemplate == "" { | 
					
						
							| 
									
										
										
										
											2017-03-22 21:25:41 -03:00
										 |  |  | 		ctx.Config.Archive.NameTemplate = "{{.Binary}}_{{.Os}}_{{.Arch}}" | 
					
						
							| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-14 14:06:57 -02:00
										 |  |  | 	if ctx.Config.Archive.Format == "" { | 
					
						
							|  |  |  | 		ctx.Config.Archive.Format = "tar.gz" | 
					
						
							| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-14 14:06:57 -02:00
										 |  |  | 	if len(ctx.Config.Archive.Replacements) == 0 { | 
					
						
							|  |  |  | 		ctx.Config.Archive.Replacements = map[string]string{ | 
					
						
							| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | 			"darwin":  "Darwin", | 
					
						
							|  |  |  | 			"linux":   "Linux", | 
					
						
							|  |  |  | 			"freebsd": "FreeBSD", | 
					
						
							|  |  |  | 			"openbsd": "OpenBSD", | 
					
						
							|  |  |  | 			"netbsd":  "NetBSD", | 
					
						
							|  |  |  | 			"windows": "Windows", | 
					
						
							|  |  |  | 			"386":     "i386", | 
					
						
							|  |  |  | 			"amd64":   "x86_64", | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-14 19:47:15 -02:00
										 |  |  | 	if len(ctx.Config.Archive.Files) == 0 { | 
					
						
							|  |  |  | 		files, err := findFiles() | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							|  |  |  | 			return err | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		ctx.Config.Archive.Files = files | 
					
						
							| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-09 16:33:17 -03:00
										 |  |  | 	if ctx.Config.Brew.Install == "" { | 
					
						
							| 
									
										
										
										
											2017-03-22 21:25:41 -03:00
										 |  |  | 		ctx.Config.Brew.Install = "bin.install \"" + ctx.Config.Build.Binary + "\"" | 
					
						
							| 
									
										
										
										
											2017-03-09 16:33:17 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-25 21:31:16 -03:00
										 |  |  | 	ctx.Config.Dist = "dist" | 
					
						
							| 
									
										
										
										
											2017-01-14 19:41:32 +01:00
										 |  |  | 	return nil | 
					
						
							| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-14 14:38:48 -02:00
										 |  |  | func findFiles() (files []string, err error) { | 
					
						
							|  |  |  | 	all, err := ioutil.ReadDir(".") | 
					
						
							| 
									
										
										
										
											2017-01-14 14:29:01 -02:00
										 |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | 		return | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-14 14:29:01 -02:00
										 |  |  | 	for _, file := range all { | 
					
						
							| 
									
										
										
										
											2017-01-14 14:38:48 -02:00
										 |  |  | 		if accept(file.Name()) { | 
					
						
							|  |  |  | 			files = append(files, file.Name()) | 
					
						
							| 
									
										
										
										
											2017-01-14 14:29:01 -02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-14 12:34:22 -02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-01-14 14:38:48 -02:00
										 |  |  | 
 | 
					
						
							|  |  |  | func accept(file string) bool { | 
					
						
							|  |  |  | 	for _, accepted := range defaultFiles { | 
					
						
							| 
									
										
										
										
											2017-01-14 15:16:29 -02:00
										 |  |  | 		if strings.HasPrefix(strings.ToLower(file), accepted) { | 
					
						
							| 
									
										
										
										
											2017-01-14 14:38:48 -02:00
										 |  |  | 			return true | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return false | 
					
						
							|  |  |  | } |