You've already forked goreleaser
							
							
				mirror of
				https://github.com/goreleaser/goreleaser.git
				synced 2025-10-30 23:58:09 +02:00 
			
		
		
		
	feat: skip formula upload
This commit is contained in:
		
				
					committed by
					
						 Carlos Alexandro Becker
						Carlos Alexandro Becker
					
				
			
			
				
	
			
			
			
						parent
						
							43c65c19c1
						
					
				
				
					commit
					4d71720b67
				
			| @@ -50,6 +50,7 @@ type Homebrew struct { | ||||
| 	Conflicts    []string     `yaml:",omitempty"` | ||||
| 	Description  string       `yaml:",omitempty"` | ||||
| 	Homepage     string       `yaml:",omitempty"` | ||||
| 	SkipUpload   bool         `yaml:"skip_upload,omitempty"` | ||||
|  | ||||
| 	// Capture all undefined fields and should be empty after loading | ||||
| 	XXX map[string]interface{} `yaml:",inline"` | ||||
|   | ||||
| @@ -42,6 +42,11 @@ brew: | ||||
|   # Default is empty. | ||||
|   description: "Software to create fast and easy drum rolls." | ||||
|  | ||||
|   # Setting this will prevent goreleaser to actually try to commit the updated | ||||
|   # formula - instead, the formula file will be stored on the dist folder only, | ||||
|   # leaving the responsibility of publishing it to the user. | ||||
|   skip_upload: true | ||||
|  | ||||
|   # Packages your package depends on. | ||||
|   dependencies: | ||||
|     - git | ||||
|   | ||||
| @@ -10,5 +10,5 @@ import ( | ||||
| // AssertSkipped asserts that a pipe was skipped | ||||
| func AssertSkipped(t *testing.T, err error) { | ||||
| 	_, ok := err.(pipeline.ErrSkip) | ||||
| 	assert.True(t, ok) | ||||
| 	assert.True(t, ok, "expected a pipeline.ErrSkip but got %v", err) | ||||
| } | ||||
|   | ||||
| @@ -109,7 +109,7 @@ func (Pipe) Run(ctx *context.Context) error { | ||||
|  | ||||
| func doRun(ctx *context.Context) error { | ||||
| 	if !ctx.Publish { | ||||
| 		return pipeline.Skip("--skip-publish is set") | ||||
| 		return pipeline.ErrSkipPublish | ||||
| 	} | ||||
|  | ||||
| 	// Handle every configured artifactory instance | ||||
|   | ||||
| @@ -616,7 +616,7 @@ func TestRunPipe_SkipWhenPublishFalse(t *testing.T) { | ||||
|  | ||||
| 	err := Pipe{}.Run(ctx) | ||||
| 	assert.True(t, pipeline.IsSkip(err)) | ||||
| 	assert.Equal(t, err.Error(), "--skip-publish is set") | ||||
| 	assert.EqualError(t, err, pipeline.ErrSkipPublish.Error()) | ||||
| } | ||||
|  | ||||
| func TestRunPipe_DirUpload(t *testing.T) { | ||||
|   | ||||
| @@ -85,15 +85,9 @@ func contains(ss []string, s string) bool { | ||||
| } | ||||
|  | ||||
| func doRun(ctx *context.Context, client client.Client) error { | ||||
| 	if !ctx.Publish { | ||||
| 		return pipeline.Skip("--skip-publish is set") | ||||
| 	} | ||||
| 	if ctx.Config.Brew.GitHub.Name == "" { | ||||
| 		return pipeline.Skip("brew section is not configured") | ||||
| 	} | ||||
| 	if ctx.Config.Release.Draft { | ||||
| 		return pipeline.Skip("release is marked as draft") | ||||
| 	} | ||||
| 	if ctx.Config.Archive.Format == "binary" { | ||||
| 		return pipeline.Skip("archive format is binary") | ||||
| 	} | ||||
| @@ -125,6 +119,16 @@ func doRun(ctx *context.Context, client client.Client) error { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if ctx.Config.Brew.SkipUpload { | ||||
| 		return pipeline.Skip("brew.skip_upload is set") | ||||
| 	} | ||||
| 	if !ctx.Publish { | ||||
| 		return pipeline.ErrSkipPublish | ||||
| 	} | ||||
| 	if ctx.Config.Release.Draft { | ||||
| 		return pipeline.Skip("release is marked as draft") | ||||
| 	} | ||||
|  | ||||
| 	path = filepath.Join(ctx.Config.Brew.Folder, filename) | ||||
| 	log.WithField("formula", path). | ||||
| 		WithField("repo", ctx.Config.Brew.GitHub.String()). | ||||
|   | ||||
| @@ -272,33 +272,50 @@ func TestRunPipeBinaryRelease(t *testing.T) { | ||||
| 	assert.False(t, client.CreatedFile) | ||||
| } | ||||
|  | ||||
| func TestRunPipeNoPublish(t *testing.T) { | ||||
| 	var ctx = &context.Context{ | ||||
| 		Publish: false, | ||||
| 	} | ||||
| 	client := &DummyClient{} | ||||
| 	testlib.AssertSkipped(t, doRun(ctx, client)) | ||||
| 	assert.False(t, client.CreatedFile) | ||||
| } | ||||
|  | ||||
| func TestRunPipeDraftRelease(t *testing.T) { | ||||
| 	var ctx = &context.Context{ | ||||
| 		Publish: true, | ||||
| 		Config: config.Project{ | ||||
| 			Release: config.Release{ | ||||
| 				Draft: true, | ||||
| 			}, | ||||
| 			Brew: config.Homebrew{ | ||||
| 				GitHub: config.Repo{ | ||||
| 					Owner: "test", | ||||
| 					Name:  "test", | ||||
| 				}, | ||||
| func TestRunPipeNoUpload(t *testing.T) { | ||||
| 	folder, err := ioutil.TempDir("", "goreleasertest") | ||||
| 	assert.NoError(t, err) | ||||
| 	var ctx = context.New(config.Project{ | ||||
| 		Dist:        folder, | ||||
| 		ProjectName: "foo", | ||||
| 		Release:     config.Release{}, | ||||
| 		Brew: config.Homebrew{ | ||||
| 			GitHub: config.Repo{ | ||||
| 				Owner: "test", | ||||
| 				Name:  "test", | ||||
| 			}, | ||||
| 		}, | ||||
| 	} | ||||
| 	}) | ||||
| 	var path = filepath.Join(folder, "whatever.tar.gz") | ||||
| 	_, err = os.Create(path) | ||||
| 	assert.NoError(t, err) | ||||
| 	ctx.Artifacts.Add(artifact.Artifact{ | ||||
| 		Name:   "bin", | ||||
| 		Path:   path, | ||||
| 		Goos:   "darwin", | ||||
| 		Goarch: "amd64", | ||||
| 		Type:   artifact.UploadableArchive, | ||||
| 	}) | ||||
| 	client := &DummyClient{} | ||||
| 	testlib.AssertSkipped(t, doRun(ctx, client)) | ||||
| 	assert.False(t, client.CreatedFile) | ||||
|  | ||||
| 	var assertNoPublish = func(t *testing.T) { | ||||
| 		testlib.AssertSkipped(t, doRun(ctx, client)) | ||||
| 		assert.False(t, client.CreatedFile) | ||||
| 	} | ||||
| 	t.Run("skip upload", func(tt *testing.T) { | ||||
| 		ctx.Publish = true | ||||
| 		ctx.Config.Brew.SkipUpload = true | ||||
| 		assertNoPublish(tt) | ||||
| 	}) | ||||
| 	t.Run("skip publish", func(tt *testing.T) { | ||||
| 		ctx.Publish = false | ||||
| 		assertNoPublish(tt) | ||||
| 	}) | ||||
| 	t.Run("draft release", func(tt *testing.T) { | ||||
| 		ctx.Publish = true | ||||
| 		ctx.Config.Release.Draft = true | ||||
| 		assertNoPublish(tt) | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func TestRunPipeFormatBinary(t *testing.T) { | ||||
|   | ||||
| @@ -14,6 +14,10 @@ type Piper interface { | ||||
| 	Run(ctx *context.Context) error | ||||
| } | ||||
|  | ||||
| // ErrSkipPublish happens when skip publish is set and a pipe is refusing | ||||
| // to proceed because of that. | ||||
| var ErrSkipPublish = Skip("--skip-publish is set") | ||||
|  | ||||
| // IsSkip returns true if the error is an ErrSkip | ||||
| func IsSkip(err error) bool { | ||||
| 	_, ok := err.(ErrSkip) | ||||
|   | ||||
| @@ -46,7 +46,7 @@ func (Pipe) Run(ctx *context.Context) error { | ||||
|  | ||||
| func doRun(ctx *context.Context, c client.Client) error { | ||||
| 	if !ctx.Publish { | ||||
| 		return pipeline.Skip("--skip-publish is set") | ||||
| 		return pipeline.ErrSkipPublish | ||||
| 	} | ||||
| 	log.WithField("tag", ctx.Git.CurrentTag). | ||||
| 		WithField("repo", ctx.Config.Release.GitHub.String()). | ||||
|   | ||||
		Reference in New Issue
	
	Block a user