You've already forked goreleaser
							
							
				mirror of
				https://github.com/goreleaser/goreleaser.git
				synced 2025-10-30 23:58:09 +02:00 
			
		
		
		
	refactor: scoop defaults
This commit is contained in:
		| @@ -41,6 +41,14 @@ func (Pipe) Default(ctx *context.Context) error { | |||||||
| 	if ctx.Config.Scoop.CommitAuthor.Email == "" { | 	if ctx.Config.Scoop.CommitAuthor.Email == "" { | ||||||
| 		ctx.Config.Scoop.CommitAuthor.Email = "goreleaser@carlosbecker.com" | 		ctx.Config.Scoop.CommitAuthor.Email = "goreleaser@carlosbecker.com" | ||||||
| 	} | 	} | ||||||
|  | 	if ctx.Config.Scoop.URLTemplate == "" { | ||||||
|  | 		ctx.Config.Scoop.URLTemplate = fmt.Sprintf( | ||||||
|  | 			"%s/%s/%s/releases/download/{{ .Tag }}/{{ .ArtifactName }}", | ||||||
|  | 			ctx.Config.GitHubURLs.Download, | ||||||
|  | 			ctx.Config.Release.GitHub.Owner, | ||||||
|  | 			ctx.Config.Release.GitHub.Name, | ||||||
|  | 		) | ||||||
|  | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -101,8 +109,9 @@ type Resource struct { | |||||||
| 	Bin string `json:"bin"` // name of binary inside the archive | 	Bin string `json:"bin"` // name of binary inside the archive | ||||||
| } | } | ||||||
|  |  | ||||||
| func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (result bytes.Buffer, err error) { | func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (bytes.Buffer, error) { | ||||||
| 	manifest := Manifest{ | 	var result bytes.Buffer | ||||||
|  | 	var manifest = Manifest{ | ||||||
| 		Version:      ctx.Version, | 		Version:      ctx.Version, | ||||||
| 		Architecture: make(map[string]Resource), | 		Architecture: make(map[string]Resource), | ||||||
| 		Homepage:     ctx.Config.Scoop.Homepage, | 		Homepage:     ctx.Config.Scoop.Homepage, | ||||||
| @@ -110,23 +119,17 @@ func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (result | |||||||
| 		Description:  ctx.Config.Scoop.Description, | 		Description:  ctx.Config.Scoop.Description, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var url string |  | ||||||
| 	if ctx.Config.Scoop.URLTemplate == "" { |  | ||||||
| 		ctx.Config.Scoop.URLTemplate = fmt.Sprintf("%s/%s/%s/releases/download/{{ .Tag }}/{{ .ArtifactName }}", |  | ||||||
| 			ctx.Config.GitHubURLs.Download, |  | ||||||
| 			ctx.Config.Release.GitHub.Owner, |  | ||||||
| 			ctx.Config.Release.GitHub.Name) |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	for _, artifact := range artifacts { | 	for _, artifact := range artifacts { | ||||||
| 		var arch = "64bit" | 		var arch = "64bit" | ||||||
| 		if artifact.Goarch == "386" { | 		if artifact.Goarch == "386" { | ||||||
| 			arch = "32bit" | 			arch = "32bit" | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		url, err = tmpl.New(ctx).WithArtifact(artifact, map[string]string{}).Apply(ctx.Config.Scoop.URLTemplate) | 		url, err := tmpl.New(ctx). | ||||||
|  | 			WithArtifact(artifact, map[string]string{}). | ||||||
|  | 			Apply(ctx.Config.Scoop.URLTemplate) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return | 			return result, err | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		manifest.Architecture[arch] = Resource{ | 		manifest.Architecture[arch] = Resource{ | ||||||
| @@ -137,8 +140,8 @@ func buildManifest(ctx *context.Context, artifacts []artifact.Artifact) (result | |||||||
|  |  | ||||||
| 	data, err := json.MarshalIndent(manifest, "", "    ") | 	data, err := json.MarshalIndent(manifest, "", "    ") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return | 		return result, err | ||||||
| 	} | 	} | ||||||
| 	_, err = result.Write(data) | 	_, err = result.Write(data) | ||||||
| 	return | 	return result, err | ||||||
| } | } | ||||||
|   | |||||||
| @@ -14,6 +14,7 @@ import ( | |||||||
| 	"github.com/goreleaser/goreleaser/pkg/config" | 	"github.com/goreleaser/goreleaser/pkg/config" | ||||||
| 	"github.com/goreleaser/goreleaser/pkg/context" | 	"github.com/goreleaser/goreleaser/pkg/context" | ||||||
| 	"github.com/stretchr/testify/assert" | 	"github.com/stretchr/testify/assert" | ||||||
|  | 	"github.com/stretchr/testify/require" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| var update = flag.Bool("update", false, "update .golden files") | var update = flag.Bool("update", false, "update .golden files") | ||||||
| @@ -361,10 +362,12 @@ func Test_doRun(t *testing.T) { | |||||||
| 	} | 	} | ||||||
| 	for _, tt := range tests { | 	for _, tt := range tests { | ||||||
| 		t.Run(tt.name, func(t *testing.T) { | 		t.Run(tt.name, func(t *testing.T) { | ||||||
|  | 			var ctx = tt.args.ctx | ||||||
| 			for _, a := range tt.artifacts { | 			for _, a := range tt.artifacts { | ||||||
| 				tt.args.ctx.Artifacts.Add(a) | 				ctx.Artifacts.Add(a) | ||||||
| 			} | 			} | ||||||
| 			tt.assertError(t, doRun(tt.args.ctx, tt.args.client)) | 			require.NoError(t, Pipe{}.Default(ctx)) | ||||||
|  | 			tt.assertError(t, doRun(ctx, tt.args.client)) | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @@ -452,19 +455,21 @@ func Test_buildManifest(t *testing.T) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, tt := range tests { | 	for _, tt := range tests { | ||||||
| 		out, err := buildManifest(tt.ctx, []artifact.Artifact{ | 		var ctx = tt.ctx | ||||||
|  | 		Pipe{}.Default(ctx) | ||||||
|  | 		out, err := buildManifest(ctx, []artifact.Artifact{ | ||||||
| 			{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64"}, | 			{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64"}, | ||||||
| 			{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386"}, | 			{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386"}, | ||||||
| 		}) | 		}) | ||||||
|  |  | ||||||
| 		assert.NoError(t, err) | 		require.NoError(t, err) | ||||||
|  |  | ||||||
| 		if *update { | 		if *update { | ||||||
| 			ioutil.WriteFile(tt.filename, out.Bytes(), 0655) | 			require.NoError(t, ioutil.WriteFile(tt.filename, out.Bytes(), 0655)) | ||||||
| 		} | 		} | ||||||
| 		bts, err := ioutil.ReadFile(tt.filename) | 		bts, err := ioutil.ReadFile(tt.filename) | ||||||
| 		assert.NoError(t, err) | 		require.NoError(t, err) | ||||||
| 		assert.Equal(t, string(bts), out.String()) | 		require.Equal(t, string(bts), out.String()) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user