You've already forked goreleaser
							
							
				mirror of
				https://github.com/goreleaser/goreleaser.git
				synced 2025-10-30 23:58:09 +02:00 
			
		
		
		
	fixes for multiple builds
This commit is contained in:
		| @@ -43,8 +43,7 @@ var foldersLock sync.Mutex | ||||
| func (ctx *Context) AddArtifact(file string) { | ||||
| 	artifactsLock.Lock() | ||||
| 	defer artifactsLock.Unlock() | ||||
| 	file = strings.TrimPrefix(file, ctx.Config.Dist) | ||||
| 	file = strings.Replace(file, "/", "", -1) | ||||
| 	file = strings.TrimPrefix(file, ctx.Config.Dist+"/") | ||||
| 	ctx.Artifacts = append(ctx.Artifacts, file) | ||||
| 	log.WithField("artifact", file).Info("new artifact") | ||||
| } | ||||
|   | ||||
| @@ -6,6 +6,7 @@ import ( | ||||
| 	"bytes" | ||||
| 	"text/template" | ||||
|  | ||||
| 	"github.com/goreleaser/goreleaser/config" | ||||
| 	"github.com/goreleaser/goreleaser/context" | ||||
| ) | ||||
|  | ||||
| @@ -19,9 +20,25 @@ type nameData struct { | ||||
| 	ProjectName string | ||||
| } | ||||
|  | ||||
| func ForBuild(ctx *context.Context, build config.Build, goos, goarch, goarm string) (string, error) { | ||||
| 	return apply( | ||||
| 		nameData{ | ||||
| 			Os:          replace(ctx.Config.Archive.Replacements, goos), | ||||
| 			Arch:        replace(ctx.Config.Archive.Replacements, goarch), | ||||
| 			Arm:         replace(ctx.Config.Archive.Replacements, goarm), | ||||
| 			Version:     ctx.Version, | ||||
| 			Tag:         ctx.Git.CurrentTag, | ||||
| 			Binary:      build.Binary, | ||||
| 			ProjectName: build.Binary, | ||||
| 		}, | ||||
| 		ctx.Config.Archive.NameTemplate, | ||||
| 	) | ||||
| } | ||||
|  | ||||
| // For returns the name for the given context, goos, goarch and goarm. | ||||
| func For(ctx *context.Context, goos, goarch, goarm string) (string, error) { | ||||
| 	var data = nameData{ | ||||
| 	return apply( | ||||
| 		nameData{ | ||||
| 			Os:          replace(ctx.Config.Archive.Replacements, goos), | ||||
| 			Arch:        replace(ctx.Config.Archive.Replacements, goarch), | ||||
| 			Arm:         replace(ctx.Config.Archive.Replacements, goarm), | ||||
| @@ -29,10 +46,14 @@ func For(ctx *context.Context, goos, goarch, goarm string) (string, error) { | ||||
| 			Tag:         ctx.Git.CurrentTag, | ||||
| 			Binary:      ctx.Config.ProjectName, | ||||
| 			ProjectName: ctx.Config.ProjectName, | ||||
| 	} | ||||
| 		}, | ||||
| 		ctx.Config.Archive.NameTemplate, | ||||
| 	) | ||||
| } | ||||
|  | ||||
| func apply(data nameData, templateStr string) (string, error) { | ||||
| 	var out bytes.Buffer | ||||
| 	t, err := template.New(data.Binary).Parse(ctx.Config.Archive.NameTemplate) | ||||
| 	t, err := template.New(data.ProjectName).Parse(templateStr) | ||||
| 	if err != nil { | ||||
| 		return "", err | ||||
| 	} | ||||
|   | ||||
| @@ -12,7 +12,6 @@ import ( | ||||
| 	"github.com/goreleaser/archive" | ||||
| 	"github.com/goreleaser/goreleaser/context" | ||||
| 	"github.com/goreleaser/goreleaser/internal/archiveformat" | ||||
| 	"github.com/goreleaser/goreleaser/internal/ext" | ||||
| 	"github.com/mattn/go-zglob" | ||||
| 	"golang.org/x/sync/errgroup" | ||||
| ) | ||||
| @@ -33,9 +32,9 @@ func (Pipe) Run(ctx *context.Context) error { | ||||
| 		platform := platform | ||||
| 		g.Go(func() error { | ||||
| 			if ctx.Config.Archive.Format == "binary" { | ||||
| 				return skip(ctx, platform, archive) | ||||
| 				return skip(ctx, platform, folder) | ||||
| 			} | ||||
| 			return create(ctx, platform, archive) | ||||
| 			return create(ctx, platform, folder) | ||||
| 		}) | ||||
| 	} | ||||
| 	return g.Wait() | ||||
| @@ -77,10 +76,16 @@ func create(ctx *context.Context, platform, name string) error { | ||||
| } | ||||
|  | ||||
| func skip(ctx *context.Context, platform, name string) error { | ||||
| 	b := name + ext.For(platform) | ||||
| 	log.WithField("binary", b).Info("skip archiving") | ||||
| 	var binary = filepath.Join(ctx.Config.Dist, b) | ||||
| 	ctx.AddArtifact(binary) | ||||
| 	var path = filepath.Join(ctx.Config.Dist, name) | ||||
| 	binaries, err := ioutil.ReadDir(path) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	for _, binary := range binaries { | ||||
| 		log.WithField("binary", binary.Name()).Info("skip archiving") | ||||
| 		log.Infof("path: %v %v", path, binary.Name()) | ||||
| 		ctx.AddArtifact(filepath.Join(path+"/", binary.Name())) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -80,7 +80,15 @@ func doBuild(ctx *context.Context, build config.Build, target buildTarget) error | ||||
| 		build.Binary+ext.For(target.goos), | ||||
| 	) | ||||
| 	if ctx.Config.Archive.Format == "binary" { | ||||
| 		binary = filepath.Join(ctx.Config.Dist, build.Binary+ext.For(target.goos)) | ||||
| 		bin, err := name.ForBuild(ctx, build, target.goos, target.goarch, target.goarm) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		binary = filepath.Join( | ||||
| 			ctx.Config.Dist, | ||||
| 			folder, | ||||
| 			bin+ext.For(target.goos), | ||||
| 		) | ||||
| 	} | ||||
| 	log.WithField("binary", binary).Info("building") | ||||
| 	cmd := []string{"go", "build"} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user