You've already forked goreleaser
							
							
				mirror of
				https://github.com/goreleaser/goreleaser.git
				synced 2025-10-30 23:58:09 +02:00 
			
		
		
		
	Add option to skip archive.
See #243. Upload binaries directly instead of creating archive. This option, however currently doesn't work together with brew and fpm since they both require archived artifacts.
This commit is contained in:
		| @@ -250,6 +250,12 @@ build: | ||||
| ```yml | ||||
| # goreleaser.yml | ||||
| archive: | ||||
|   # If set, no archives are created and the binaries are instead uploaded directly. | ||||
|   # In that case name_template is used to name the binary | ||||
|   # and the below specified files are ignored. | ||||
|   # Default is false | ||||
|   skip: true | ||||
|  | ||||
|   # You can change the name of the archive. | ||||
|   # This is parsed with Golang template engine and the following variables | ||||
|   # are available: | ||||
|   | ||||
| @@ -67,6 +67,7 @@ type FormatOverride struct { | ||||
|  | ||||
| // Archive config used for the archive | ||||
| type Archive struct { | ||||
| 	Skip            bool              `yaml:",omitempty"` | ||||
| 	Format          string            `yaml:",omitempty"` | ||||
| 	FormatOverrides []FormatOverride  `yaml:"format_overrides,omitempty"` | ||||
| 	NameTemplate    string            `yaml:"name_template,omitempty"` | ||||
|   | ||||
| @@ -32,6 +32,9 @@ func (Pipe) Run(ctx *context.Context) error { | ||||
| 		archive := archive | ||||
| 		platform := platform | ||||
| 		g.Go(func() error { | ||||
| 			if ctx.Config.Archive.Skip { | ||||
| 				return skip(ctx, platform, archive) | ||||
| 			} | ||||
| 			return create(ctx, platform, archive) | ||||
| 		}) | ||||
| 	} | ||||
| @@ -73,6 +76,13 @@ func create(ctx *context.Context, platform, name string) error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func skip(ctx *context.Context, platform, name string) error { | ||||
| 	log.Println("Skip archiving") | ||||
| 	var binary = filepath.Join(ctx.Config.Dist, name+ext.For(platform)) | ||||
| 	ctx.AddArtifact(binary) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func findFiles(ctx *context.Context) (result []string, err error) { | ||||
| 	for _, glob := range ctx.Config.Archive.Files { | ||||
| 		files, err := zglob.Glob(glob) | ||||
|   | ||||
| @@ -65,6 +65,44 @@ func TestRunPipe(t *testing.T) { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestRunPipeSkip(t *testing.T) { | ||||
| 	var assert = assert.New(t) | ||||
| 	folder, err := ioutil.TempDir("", "archivetest") | ||||
| 	assert.NoError(err) | ||||
| 	current, err := os.Getwd() | ||||
| 	assert.NoError(err) | ||||
| 	assert.NoError(os.Chdir(folder)) | ||||
| 	defer func() { | ||||
| 		assert.NoError(os.Chdir(current)) | ||||
| 	}() | ||||
| 	var dist = filepath.Join(folder, "dist") | ||||
| 	assert.NoError(os.Mkdir(dist, 0755)) | ||||
| 	assert.NoError(os.Mkdir(filepath.Join(dist, "mybin"), 0755)) | ||||
| 	_, err = os.Create(filepath.Join(dist, "mybin", "mybin")) | ||||
| 	assert.NoError(err) | ||||
| 	_, err = os.Create(filepath.Join(dist, "mybin", "mybin.exe")) | ||||
| 	assert.NoError(err) | ||||
| 	_, err = os.Create(filepath.Join(folder, "README.md")) | ||||
| 	assert.NoError(err) | ||||
| 	var ctx = &context.Context{ | ||||
| 		Archives: map[string]string{ | ||||
| 			"darwinamd64":  "mybin", | ||||
| 			"windowsamd64": "mybin", | ||||
| 		}, | ||||
| 		Config: config.Project{ | ||||
| 			Dist: dist, | ||||
| 			Build: config.Build{ | ||||
| 				Binary: "mybin", | ||||
| 			}, | ||||
| 			Archive: config.Archive{ | ||||
| 				Skip: true, | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| 	assert.NoError(Pipe{}.Run(ctx)) | ||||
| 	assert.Equal([]string{"mybin.exe", "mybin"}, ctx.Artifacts) | ||||
| } | ||||
|  | ||||
| func TestRunPipeDistRemoved(t *testing.T) { | ||||
| 	var assert = assert.New(t) | ||||
| 	var ctx = &context.Context{ | ||||
|   | ||||
| @@ -106,6 +106,10 @@ func doRun(ctx *context.Context, client client.Client) error { | ||||
| 		log.Println("Skipped because release is marked as draft") | ||||
| 		return nil | ||||
| 	} | ||||
| 	if ctx.Config.Archive.Skip { | ||||
| 		log.Println("Skipped because archiving is skipped") | ||||
| 		return nil | ||||
| 	} | ||||
| 	path := filepath.Join(ctx.Config.Brew.Folder, ctx.Config.Build.Binary+".rb") | ||||
| 	log.Println("Pushing", path, "to", ctx.Config.Brew.GitHub.String()) | ||||
| 	content, err := buildFormula(ctx, client) | ||||
|   | ||||
| @@ -67,6 +67,9 @@ func build(ctx *context.Context, name string, target buildTarget) error { | ||||
| 		name, | ||||
| 		ctx.Config.Build.Binary+ext.For(target.goos), | ||||
| 	) | ||||
| 	if ctx.Config.Archive.Skip { | ||||
| 		output = filepath.Join(ctx.Config.Dist, name+ext.For(target.goos)) | ||||
| 	} | ||||
| 	log.Println("Building", output) | ||||
| 	cmd := []string{"go", "build"} | ||||
| 	if ctx.Config.Build.Flags != "" { | ||||
|   | ||||
| @@ -33,6 +33,10 @@ func (Pipe) Run(ctx *context.Context) error { | ||||
| 		log.Println("No output formats configured, skipping") | ||||
| 		return nil | ||||
| 	} | ||||
| 	if ctx.Config.Archive.Skip { | ||||
| 		log.Println("Skipped because archiving is skipped") | ||||
| 		return nil | ||||
| 	} | ||||
| 	_, err := exec.LookPath("fpm") | ||||
| 	if err != nil { | ||||
| 		return ErrNoFPM | ||||
|   | ||||
		Reference in New Issue
	
	Block a user