github.com/amane3/goreleaser@v0.182.0/internal/pipe/scoop/scoop_test.go (about)

     1  package scoop
     2  
     3  import (
     4  	ctx "context"
     5  	"flag"
     6  	"io/ioutil"
     7  	"os"
     8  	"path/filepath"
     9  	"testing"
    10  
    11  	"github.com/amane3/goreleaser/internal/artifact"
    12  	"github.com/amane3/goreleaser/internal/client"
    13  	"github.com/amane3/goreleaser/internal/pipe"
    14  	"github.com/amane3/goreleaser/internal/testlib"
    15  	"github.com/amane3/goreleaser/pkg/config"
    16  	"github.com/amane3/goreleaser/pkg/context"
    17  	"github.com/stretchr/testify/require"
    18  )
    19  
    20  var update = flag.Bool("update", false, "update .golden files")
    21  
    22  func TestDescription(t *testing.T) {
    23  	require.NotEmpty(t, Pipe{}.String())
    24  }
    25  
    26  func TestDefault(t *testing.T) {
    27  	testlib.Mktmp(t)
    28  
    29  	var ctx = &context.Context{
    30  		TokenType: context.TokenTypeGitHub,
    31  		Config: config.Project{
    32  			ProjectName: "barr",
    33  			Builds: []config.Build{
    34  				{
    35  					Binary: "foo",
    36  					Goos:   []string{"linux", "darwin"},
    37  					Goarch: []string{"386", "amd64"},
    38  				},
    39  				{
    40  					Binary: "bar",
    41  					Goos:   []string{"linux", "darwin"},
    42  					Goarch: []string{"386", "amd64"},
    43  					Ignore: []config.IgnoredBuild{
    44  						{Goos: "darwin", Goarch: "amd64"},
    45  					},
    46  				},
    47  				{
    48  					Binary: "foobar",
    49  					Goos:   []string{"linux"},
    50  					Goarch: []string{"amd64"},
    51  				},
    52  			},
    53  		},
    54  	}
    55  	require.NoError(t, Pipe{}.Default(ctx))
    56  	require.Equal(t, ctx.Config.ProjectName, ctx.Config.Scoop.Name)
    57  	require.NotEmpty(t, ctx.Config.Scoop.CommitAuthor.Name)
    58  	require.NotEmpty(t, ctx.Config.Scoop.CommitAuthor.Email)
    59  	require.NotEmpty(t, ctx.Config.Scoop.CommitMessageTemplate)
    60  }
    61  
    62  func Test_doRun(t *testing.T) {
    63  	var folder = testlib.Mktmp(t)
    64  	var file = filepath.Join(folder, "archive")
    65  	require.NoError(t, ioutil.WriteFile(file, []byte("lorem ipsum"), 0644))
    66  
    67  	type errChecker func(*testing.T, error)
    68  	var shouldErr = func(msg string) errChecker {
    69  		return func(t *testing.T, err error) {
    70  			require.Error(t, err)
    71  			require.EqualError(t, err, msg)
    72  		}
    73  	}
    74  	var shouldNotErr = func(t *testing.T, err error) {
    75  		require.NoError(t, err)
    76  	}
    77  	type args struct {
    78  		ctx    *context.Context
    79  		client client.Client
    80  	}
    81  	tests := []struct {
    82  		name        string
    83  		args        args
    84  		artifacts   []*artifact.Artifact
    85  		assertError errChecker
    86  	}{
    87  		{
    88  			"valid public github",
    89  			args{
    90  				&context.Context{
    91  					TokenType: context.TokenTypeGitHub,
    92  					Git: context.GitInfo{
    93  						CurrentTag: "v1.0.1",
    94  					},
    95  					Version:   "1.0.1",
    96  					Artifacts: artifact.New(),
    97  					Config: config.Project{
    98  						Builds: []config.Build{
    99  							{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
   100  						},
   101  						Dist:        ".",
   102  						ProjectName: "run-pipe",
   103  						Archives: []config.Archive{
   104  							{Format: "tar.gz"},
   105  						},
   106  						Release: config.Release{
   107  							GitHub: config.Repo{
   108  								Owner: "test",
   109  								Name:  "test",
   110  							},
   111  						},
   112  						Scoop: config.Scoop{
   113  							Bucket: config.RepoRef{
   114  								Owner: "test",
   115  								Name:  "test",
   116  							},
   117  							Description: "A run pipe test formula",
   118  							Homepage:    "https://github.com/goreleaser",
   119  						},
   120  					},
   121  				},
   122  				&DummyClient{},
   123  			},
   124  			[]*artifact.Artifact{
   125  				{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
   126  				{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
   127  			},
   128  			shouldNotErr,
   129  		},
   130  		{
   131  			"wrap in directory",
   132  			args{
   133  				&context.Context{
   134  					TokenType: context.TokenTypeGitHub,
   135  					Git: context.GitInfo{
   136  						CurrentTag: "v1.0.1",
   137  					},
   138  					Version:   "1.0.1",
   139  					Artifacts: artifact.New(),
   140  					Config: config.Project{
   141  						Builds: []config.Build{
   142  							{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
   143  						},
   144  						Dist:        ".",
   145  						ProjectName: "run-pipe",
   146  						Archives: []config.Archive{
   147  							{Format: "tar.gz", WrapInDirectory: "true"},
   148  						},
   149  						Release: config.Release{
   150  							GitHub: config.Repo{
   151  								Owner: "test",
   152  								Name:  "test",
   153  							},
   154  						},
   155  						Scoop: config.Scoop{
   156  							Bucket: config.RepoRef{
   157  								Owner: "test",
   158  								Name:  "test",
   159  							},
   160  							Description: "A run pipe test formula",
   161  							Homepage:    "https://github.com/goreleaser",
   162  						},
   163  					},
   164  				},
   165  				&DummyClient{},
   166  			},
   167  			[]*artifact.Artifact{
   168  				{
   169  					Name:   "foo_1.0.1_windows_amd64.tar.gz",
   170  					Goos:   "windows",
   171  					Goarch: "amd64",
   172  					Path:   file,
   173  					Extra: map[string]interface{}{
   174  						"Wrap": "foo_1.0.1_windows_amd64",
   175  					},
   176  				},
   177  				{
   178  					Name:   "foo_1.0.1_windows_386.tar.gz",
   179  					Goos:   "windows",
   180  					Goarch: "386",
   181  					Path:   file,
   182  					Extra: map[string]interface{}{
   183  						"Wrap": "foo_1.0.1_windows_386",
   184  					},
   185  				},
   186  			},
   187  			shouldNotErr,
   188  		},
   189  		{
   190  			"valid enterprise github",
   191  			args{
   192  				&context.Context{
   193  					TokenType: context.TokenTypeGitHub,
   194  					Git: context.GitInfo{
   195  						CurrentTag: "v1.0.1",
   196  					},
   197  					Version:   "1.0.1",
   198  					Artifacts: artifact.New(),
   199  					Config: config.Project{
   200  						GitHubURLs: config.GitHubURLs{Download: "https://api.custom.github.enterprise.com"},
   201  						Builds: []config.Build{
   202  							{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
   203  						},
   204  						Dist:        ".",
   205  						ProjectName: "run-pipe",
   206  						Archives: []config.Archive{
   207  							{Format: "tar.gz"},
   208  						},
   209  						Release: config.Release{
   210  							GitHub: config.Repo{
   211  								Owner: "test",
   212  								Name:  "test",
   213  							},
   214  						},
   215  						Scoop: config.Scoop{
   216  							Bucket: config.RepoRef{
   217  								Owner: "test",
   218  								Name:  "test",
   219  							},
   220  							Description: "A run pipe test formula",
   221  							Homepage:    "https://github.com/goreleaser",
   222  						},
   223  					},
   224  				},
   225  				&DummyClient{},
   226  			},
   227  			[]*artifact.Artifact{
   228  				{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
   229  				{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
   230  			},
   231  			shouldNotErr,
   232  		},
   233  		{
   234  			"valid public gitlab",
   235  			args{
   236  				&context.Context{
   237  					TokenType: context.TokenTypeGitLab,
   238  					Git: context.GitInfo{
   239  						CurrentTag: "v1.0.1",
   240  					},
   241  					Version:   "1.0.1",
   242  					Artifacts: artifact.New(),
   243  					Config: config.Project{
   244  						Builds: []config.Build{
   245  							{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
   246  						},
   247  						Dist:        ".",
   248  						ProjectName: "run-pipe",
   249  						Archives: []config.Archive{
   250  							{Format: "tar.gz"},
   251  						},
   252  						Release: config.Release{
   253  							GitLab: config.Repo{
   254  								Owner: "test",
   255  								Name:  "test",
   256  							},
   257  						},
   258  						Scoop: config.Scoop{
   259  							Bucket: config.RepoRef{
   260  								Owner: "test",
   261  								Name:  "test",
   262  							},
   263  							Description: "A run pipe test formula",
   264  							Homepage:    "https://gitlab.com/goreleaser",
   265  						},
   266  					},
   267  				},
   268  				&DummyClient{},
   269  			},
   270  			[]*artifact.Artifact{
   271  				{
   272  					Name:   "foo_1.0.1_windows_amd64.tar.gz",
   273  					Goos:   "windows",
   274  					Goarch: "amd64",
   275  					Path:   file,
   276  					Extra: map[string]interface{}{
   277  						"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
   278  					},
   279  				},
   280  				{
   281  					Name:   "foo_1.0.1_windows_386.tar.gz",
   282  					Goos:   "windows",
   283  					Goarch: "386",
   284  					Path:   file,
   285  					Extra: map[string]interface{}{
   286  						"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
   287  					},
   288  				},
   289  			},
   290  			shouldNotErr,
   291  		},
   292  		{
   293  			"valid enterprise gitlab",
   294  			args{
   295  				&context.Context{
   296  					TokenType: context.TokenTypeGitLab,
   297  					Git: context.GitInfo{
   298  						CurrentTag: "v1.0.1",
   299  					},
   300  					Version:   "1.0.1",
   301  					Artifacts: artifact.New(),
   302  					Config: config.Project{
   303  						GitHubURLs: config.GitHubURLs{Download: "https://api.custom.gitlab.enterprise.com"},
   304  						Builds: []config.Build{
   305  							{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
   306  						},
   307  						Dist:        ".",
   308  						ProjectName: "run-pipe",
   309  						Archives: []config.Archive{
   310  							{Format: "tar.gz"},
   311  						},
   312  						Release: config.Release{
   313  							GitHub: config.Repo{
   314  								Owner: "test",
   315  								Name:  "test",
   316  							},
   317  						},
   318  						Scoop: config.Scoop{
   319  							Bucket: config.RepoRef{
   320  								Owner: "test",
   321  								Name:  "test",
   322  							},
   323  							Description: "A run pipe test formula",
   324  							Homepage:    "https://gitlab.com/goreleaser",
   325  						},
   326  					},
   327  				},
   328  				&DummyClient{},
   329  			},
   330  			[]*artifact.Artifact{
   331  				{
   332  					Name:   "foo_1.0.1_windows_amd64.tar.gz",
   333  					Goos:   "windows",
   334  					Goarch: "amd64",
   335  					Path:   file,
   336  					Extra: map[string]interface{}{
   337  						"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
   338  					},
   339  				},
   340  				{
   341  					Name:   "foo_1.0.1_windows_386.tar.gz",
   342  					Goos:   "windows",
   343  					Goarch: "386",
   344  					Path:   file,
   345  					Extra: map[string]interface{}{
   346  						"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
   347  					},
   348  				},
   349  			},
   350  			shouldNotErr,
   351  		},
   352  		{
   353  			"token type not implemented for pipe",
   354  			args{
   355  				&context.Context{
   356  					Git: context.GitInfo{
   357  						CurrentTag: "v1.0.1",
   358  					},
   359  					Version:   "1.0.1",
   360  					Artifacts: artifact.New(),
   361  					Config: config.Project{
   362  						Builds: []config.Build{
   363  							{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
   364  						},
   365  						Dist:        ".",
   366  						ProjectName: "run-pipe",
   367  						Archives: []config.Archive{
   368  							{Format: "tar.gz"},
   369  						},
   370  						Release: config.Release{
   371  							GitHub: config.Repo{
   372  								Owner: "test",
   373  								Name:  "test",
   374  							},
   375  						},
   376  						Scoop: config.Scoop{
   377  							Bucket: config.RepoRef{
   378  								Owner: "test",
   379  								Name:  "test",
   380  							},
   381  							Description: "A run pipe test formula",
   382  							Homepage:    "https://github.com/goreleaser",
   383  						},
   384  					},
   385  				},
   386  				&DummyClient{NotImplemented: true},
   387  			},
   388  			[]*artifact.Artifact{
   389  				{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
   390  				{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
   391  			},
   392  			shouldErr(ErrTokenTypeNotImplementedForScoop.Error()),
   393  		},
   394  		{
   395  			"no windows build",
   396  			args{
   397  				&context.Context{
   398  					TokenType: context.TokenTypeGitHub,
   399  					Git: context.GitInfo{
   400  						CurrentTag: "v1.0.1",
   401  					},
   402  					Version:   "1.0.1",
   403  					Artifacts: artifact.New(),
   404  					Config: config.Project{
   405  						Builds: []config.Build{
   406  							{Binary: "test"},
   407  						},
   408  						Dist:        ".",
   409  						ProjectName: "run-pipe",
   410  						Archives: []config.Archive{
   411  							{Format: "tar.gz"},
   412  						},
   413  						Release: config.Release{
   414  							GitHub: config.Repo{
   415  								Owner: "test",
   416  								Name:  "test",
   417  							},
   418  						},
   419  						Scoop: config.Scoop{
   420  							Bucket: config.RepoRef{
   421  								Owner: "test",
   422  								Name:  "test",
   423  							},
   424  							Description: "A run pipe test formula",
   425  							Homepage:    "https://github.com/goreleaser",
   426  						},
   427  					},
   428  				},
   429  				&DummyClient{},
   430  			},
   431  			[]*artifact.Artifact{
   432  				{Name: "foo_1.0.1_linux_amd64.tar.gz", Goos: "linux", Goarch: "amd64"},
   433  				{Name: "foo_1.0.1_linux_386.tar.gz", Goos: "linux", Goarch: "386"},
   434  			},
   435  			shouldErr("scoop requires a windows build"),
   436  		},
   437  		{
   438  			"no scoop",
   439  			args{
   440  				&context.Context{
   441  					TokenType: context.TokenTypeGitHub,
   442  					Git: context.GitInfo{
   443  						CurrentTag: "v1.0.1",
   444  					},
   445  					Version:   "1.0.1",
   446  					Artifacts: artifact.New(),
   447  					Config: config.Project{
   448  						Builds: []config.Build{
   449  							{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
   450  						},
   451  						Dist:        ".",
   452  						ProjectName: "run-pipe",
   453  						Archives: []config.Archive{
   454  							{Format: "tar.gz"},
   455  						},
   456  						Release: config.Release{
   457  							GitHub: config.Repo{
   458  								Owner: "test",
   459  								Name:  "test",
   460  							},
   461  						},
   462  					},
   463  				},
   464  				&DummyClient{},
   465  			},
   466  			[]*artifact.Artifact{
   467  				{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64"},
   468  				{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386"},
   469  			},
   470  			shouldErr("scoop section is not configured"),
   471  		},
   472  		{
   473  			"no publish",
   474  			args{
   475  				&context.Context{
   476  					TokenType: context.TokenTypeGitHub,
   477  					Git: context.GitInfo{
   478  						CurrentTag: "v1.0.1",
   479  					},
   480  					Version:   "1.0.1",
   481  					Artifacts: artifact.New(),
   482  					Config: config.Project{
   483  						Builds: []config.Build{
   484  							{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
   485  						},
   486  						Dist:        ".",
   487  						ProjectName: "run-pipe",
   488  						Archives: []config.Archive{
   489  							{Format: "tar.gz"},
   490  						},
   491  						Release: config.Release{
   492  							GitHub: config.Repo{
   493  								Owner: "test",
   494  								Name:  "test",
   495  							},
   496  						},
   497  						Scoop: config.Scoop{
   498  							Bucket: config.RepoRef{
   499  								Owner: "test",
   500  								Name:  "test",
   501  							},
   502  							Description: "A run pipe test formula",
   503  							Homepage:    "https://github.com/goreleaser",
   504  						},
   505  					},
   506  					SkipPublish: true,
   507  				},
   508  				&DummyClient{},
   509  			},
   510  			[]*artifact.Artifact{
   511  				{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
   512  				{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
   513  			},
   514  			shouldErr(pipe.ErrSkipPublishEnabled.Error()),
   515  		},
   516  		{
   517  			"is draft",
   518  			args{
   519  				&context.Context{
   520  					TokenType: context.TokenTypeGitHub,
   521  					Git: context.GitInfo{
   522  						CurrentTag: "v1.0.1",
   523  					},
   524  					Version:   "1.0.1",
   525  					Artifacts: artifact.New(),
   526  					Config: config.Project{
   527  						Builds: []config.Build{
   528  							{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
   529  						},
   530  						Dist:        ".",
   531  						ProjectName: "run-pipe",
   532  						Archives: []config.Archive{
   533  							{Format: "tar.gz"},
   534  						},
   535  						Release: config.Release{
   536  							Draft: true,
   537  						},
   538  						Scoop: config.Scoop{
   539  							Bucket: config.RepoRef{
   540  								Owner: "test",
   541  								Name:  "test",
   542  							},
   543  							Description: "A run pipe test formula",
   544  							Homepage:    "https://github.com/goreleaser",
   545  						},
   546  					},
   547  				},
   548  				&DummyClient{},
   549  			},
   550  			[]*artifact.Artifact{
   551  				{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
   552  				{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
   553  			},
   554  			shouldErr("release is marked as draft"),
   555  		},
   556  		{
   557  			"is prerelease and skip upload set to auto",
   558  			args{
   559  				&context.Context{
   560  					TokenType: context.TokenTypeGitHub,
   561  					Git: context.GitInfo{
   562  						CurrentTag: "v1.0.1-pre.1",
   563  					},
   564  					Semver: context.Semver{
   565  						Major:      1,
   566  						Minor:      0,
   567  						Patch:      1,
   568  						Prerelease: "-pre.1",
   569  					},
   570  					Version:   "1.0.1-pre.1",
   571  					Artifacts: artifact.New(),
   572  					Config: config.Project{
   573  						Builds: []config.Build{
   574  							{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
   575  						},
   576  						Dist:        ".",
   577  						ProjectName: "run-pipe",
   578  						Archives: []config.Archive{
   579  							{Format: "tar.gz"},
   580  						},
   581  						Release: config.Release{
   582  							GitHub: config.Repo{
   583  								Owner: "test",
   584  								Name:  "test",
   585  							},
   586  						},
   587  						Scoop: config.Scoop{
   588  							SkipUpload: "auto",
   589  							Bucket: config.RepoRef{
   590  								Owner: "test",
   591  								Name:  "test",
   592  							},
   593  							Description: "A run pipe test formula",
   594  							Homepage:    "https://github.com/goreleaser",
   595  						},
   596  					},
   597  				},
   598  				&DummyClient{},
   599  			},
   600  			[]*artifact.Artifact{
   601  				{Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
   602  				{Name: "foo_1.0.1-pre.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
   603  			},
   604  			shouldErr("release is prerelease"),
   605  		},
   606  		{
   607  			"skip upload set to true",
   608  			args{
   609  				&context.Context{
   610  					TokenType: context.TokenTypeGitHub,
   611  					Git: context.GitInfo{
   612  						CurrentTag: "v1.0.1",
   613  					},
   614  					Version:   "1.0.1",
   615  					Artifacts: artifact.New(),
   616  					Config: config.Project{
   617  						Builds: []config.Build{
   618  							{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
   619  						},
   620  						Dist:        ".",
   621  						ProjectName: "run-pipe",
   622  						Archives: []config.Archive{
   623  							{Format: "tar.gz"},
   624  						},
   625  						Release: config.Release{
   626  							GitHub: config.Repo{
   627  								Owner: "test",
   628  								Name:  "test",
   629  							},
   630  						},
   631  						Scoop: config.Scoop{
   632  							SkipUpload: "true",
   633  							Bucket: config.RepoRef{
   634  								Owner: "test",
   635  								Name:  "test",
   636  							},
   637  							Description: "A run pipe test formula",
   638  							Homepage:    "https://github.com/goreleaser",
   639  						},
   640  					},
   641  				},
   642  				&DummyClient{},
   643  			},
   644  			[]*artifact.Artifact{
   645  				{Name: "foo_1.0.1-pre.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
   646  				{Name: "foo_1.0.1-pre.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
   647  			},
   648  			shouldErr("scoop.skip_upload is true"),
   649  		},
   650  		{
   651  			"release is disabled",
   652  			args{
   653  				&context.Context{
   654  					TokenType: context.TokenTypeGitHub,
   655  					Git: context.GitInfo{
   656  						CurrentTag: "v1.0.1",
   657  					},
   658  					Version:   "1.0.1",
   659  					Artifacts: artifact.New(),
   660  					Config: config.Project{
   661  						Builds: []config.Build{
   662  							{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
   663  						},
   664  						Dist:        ".",
   665  						ProjectName: "run-pipe",
   666  						Archives: []config.Archive{
   667  							{Format: "tar.gz"},
   668  						},
   669  						Release: config.Release{
   670  							Disable: true,
   671  						},
   672  						Scoop: config.Scoop{
   673  							Bucket: config.RepoRef{
   674  								Owner: "test",
   675  								Name:  "test",
   676  							},
   677  							Description: "A run pipe test formula",
   678  							Homepage:    "https://github.com/goreleaser",
   679  						},
   680  					},
   681  				},
   682  				&DummyClient{},
   683  			},
   684  			[]*artifact.Artifact{
   685  				{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
   686  				{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
   687  			},
   688  			shouldErr("release is disabled"),
   689  		},
   690  		{
   691  			"no archive",
   692  			args{
   693  				&context.Context{
   694  					TokenType: context.TokenTypeGitHub,
   695  					Git: context.GitInfo{
   696  						CurrentTag: "v1.0.1",
   697  					},
   698  					Version:   "1.0.1",
   699  					Artifacts: artifact.New(),
   700  					Config: config.Project{
   701  						Builds: []config.Build{
   702  							{Binary: "test", Goarch: []string{"amd64"}, Goos: []string{"windows"}},
   703  						},
   704  						Dist:        ".",
   705  						ProjectName: "run-pipe",
   706  						Archives: []config.Archive{
   707  							{Format: "binary"},
   708  						},
   709  						Release: config.Release{
   710  							Draft: true,
   711  						},
   712  						Scoop: config.Scoop{
   713  							Bucket: config.RepoRef{
   714  								Owner: "test",
   715  								Name:  "test",
   716  							},
   717  							Description: "A run pipe test formula",
   718  							Homepage:    "https://github.com/goreleaser",
   719  						},
   720  					},
   721  				},
   722  				&DummyClient{},
   723  			},
   724  			[]*artifact.Artifact{
   725  				{Name: "foo_1.0.1_windows_amd64.tar.gz", Goos: "windows", Goarch: "amd64", Path: file},
   726  				{Name: "foo_1.0.1_windows_386.tar.gz", Goos: "windows", Goarch: "386", Path: file},
   727  			},
   728  			shouldErr("archive format is binary"),
   729  		},
   730  	}
   731  	for _, tt := range tests {
   732  		t.Run(tt.name, func(t *testing.T) {
   733  			var ctx = tt.args.ctx
   734  			for _, a := range tt.artifacts {
   735  				ctx.Artifacts.Add(a)
   736  			}
   737  			require.NoError(t, Pipe{}.Default(ctx))
   738  
   739  			tt.assertError(t, doRun(ctx, tt.args.client))
   740  		})
   741  	}
   742  }
   743  
   744  func Test_buildManifest(t *testing.T) {
   745  	var folder = t.TempDir()
   746  	var file = filepath.Join(folder, "archive")
   747  	require.NoError(t, ioutil.WriteFile(file, []byte("lorem ipsum"), 0644))
   748  
   749  	tests := []struct {
   750  		filename string
   751  		ctx      *context.Context
   752  	}{
   753  		{
   754  			"testdata/test_buildmanifest.json.golden",
   755  			&context.Context{
   756  				Context:   ctx.Background(),
   757  				TokenType: context.TokenTypeGitHub,
   758  				Git: context.GitInfo{
   759  					CurrentTag: "v1.0.1",
   760  				},
   761  				Version:   "1.0.1",
   762  				Artifacts: artifact.New(),
   763  				Config: config.Project{
   764  					GitHubURLs: config.GitHubURLs{
   765  						Download: "https://github.com",
   766  					},
   767  					Dist:        ".",
   768  					ProjectName: "run-pipe",
   769  					Archives: []config.Archive{
   770  						{Format: "tar.gz"},
   771  					},
   772  					Release: config.Release{
   773  						GitHub: config.Repo{
   774  							Owner: "test",
   775  							Name:  "test",
   776  						},
   777  					},
   778  					Scoop: config.Scoop{
   779  						Bucket: config.RepoRef{
   780  							Owner: "test",
   781  							Name:  "test",
   782  						},
   783  						Description: "A run pipe test formula",
   784  						Homepage:    "https://github.com/goreleaser",
   785  						Persist:     []string{"data", "config", "test.ini"},
   786  					},
   787  				},
   788  			},
   789  		},
   790  		{
   791  			"testdata/test_buildmanifest_pre_post_install.json.golden",
   792  			&context.Context{
   793  				Context:   ctx.Background(),
   794  				TokenType: context.TokenTypeGitHub,
   795  				Git: context.GitInfo{
   796  					CurrentTag: "v1.0.1",
   797  				},
   798  				Version:   "1.0.1",
   799  				Artifacts: artifact.New(),
   800  				Config: config.Project{
   801  					GitHubURLs: config.GitHubURLs{
   802  						Download: "https://github.com",
   803  					},
   804  					Dist:        ".",
   805  					ProjectName: "run-pipe",
   806  					Archives: []config.Archive{
   807  						{Format: "tar.gz"},
   808  					},
   809  					Release: config.Release{
   810  						GitHub: config.Repo{
   811  							Owner: "test",
   812  							Name:  "test",
   813  						},
   814  					},
   815  					Scoop: config.Scoop{
   816  						Bucket: config.RepoRef{
   817  							Owner: "test",
   818  							Name:  "test",
   819  						},
   820  						Description: "A run pipe test formula",
   821  						Homepage:    "https://github.com/goreleaser",
   822  						Persist:     []string{"data", "config", "test.ini"},
   823  						PreInstall:  []string{"Write-Host 'Running preinstall command'"},
   824  						PostInstall: []string{"Write-Host 'Running postinstall command'"},
   825  					},
   826  				},
   827  			},
   828  		},
   829  		{
   830  			"testdata/test_buildmanifest_url_template.json.golden",
   831  			&context.Context{
   832  				Context:   ctx.Background(),
   833  				TokenType: context.TokenTypeGitHub,
   834  				Git: context.GitInfo{
   835  					CurrentTag: "v1.0.1",
   836  				},
   837  				Version:   "1.0.1",
   838  				Artifacts: artifact.New(),
   839  				Config: config.Project{
   840  					GitHubURLs: config.GitHubURLs{
   841  						Download: "https://github.com",
   842  					},
   843  					Builds: []config.Build{
   844  						{Binary: "test"},
   845  					},
   846  					Dist:        ".",
   847  					ProjectName: "run-pipe",
   848  					Archives: []config.Archive{
   849  						{Format: "tar.gz"},
   850  					},
   851  					Release: config.Release{
   852  						GitHub: config.Repo{
   853  							Owner: "test",
   854  							Name:  "test",
   855  						},
   856  					},
   857  					Scoop: config.Scoop{
   858  						Bucket: config.RepoRef{
   859  							Owner: "test",
   860  							Name:  "test",
   861  						},
   862  						Description:           "A run pipe test formula",
   863  						Homepage:              "https://github.com/goreleaser",
   864  						URLTemplate:           "http://github.mycompany.com/foo/bar/{{ .Tag }}/{{ .ArtifactName }}",
   865  						CommitMessageTemplate: "chore(scoop): update {{ .ProjectName }} version {{ .Tag }}",
   866  						Persist:               []string{"data.cfg", "etc"},
   867  					},
   868  				},
   869  			},
   870  		},
   871  		{
   872  			"testdata/test_buildmanifest_gitlab_url_template.json.golden",
   873  			&context.Context{
   874  				Context:   ctx.Background(),
   875  				TokenType: context.TokenTypeGitLab,
   876  				Git: context.GitInfo{
   877  					CurrentTag: "v1.0.1",
   878  				},
   879  				Version:   "1.0.1",
   880  				Artifacts: artifact.New(),
   881  				Config: config.Project{
   882  					GitLabURLs: config.GitLabURLs{
   883  						Download: "https://gitlab.com",
   884  					},
   885  					Builds: []config.Build{
   886  						{Binary: "test"},
   887  					},
   888  					Dist:        ".",
   889  					ProjectName: "run-pipe",
   890  					Archives: []config.Archive{
   891  						{Format: "tar.gz"},
   892  					},
   893  					Release: config.Release{
   894  						GitHub: config.Repo{
   895  							Owner: "test",
   896  							Name:  "test",
   897  						},
   898  					},
   899  					Scoop: config.Scoop{
   900  						Bucket: config.RepoRef{
   901  							Owner: "test",
   902  							Name:  "test",
   903  						},
   904  						Description:           "A run pipe test formula",
   905  						Homepage:              "https://gitlab.com/goreleaser",
   906  						URLTemplate:           "http://gitlab.mycompany.com/foo/bar/uploads/{{ .ArtifactUploadHash }}/{{ .ArtifactName }}",
   907  						CommitMessageTemplate: "chore(scoop): update {{ .ProjectName }} version {{ .Tag }}",
   908  						Persist:               []string{"data.cfg", "etc"},
   909  					},
   910  				},
   911  			},
   912  		},
   913  	}
   914  
   915  	for _, tt := range tests {
   916  		t.Run(tt.filename, func(t *testing.T) {
   917  			var ctx = tt.ctx
   918  			err := Pipe{}.Default(ctx)
   919  			require.NoError(t, err)
   920  
   921  			cl, err := client.New(ctx)
   922  			require.NoError(t, err)
   923  
   924  			mf, err := dataFor(ctx, cl, []*artifact.Artifact{
   925  				{
   926  					Name:   "foo_1.0.1_windows_amd64.tar.gz",
   927  					Goos:   "windows",
   928  					Goarch: "amd64",
   929  					Path:   file,
   930  					Extra: map[string]interface{}{
   931  						"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
   932  						"Builds": []*artifact.Artifact{
   933  							{
   934  								Name: "foo.exe",
   935  							},
   936  							{
   937  								Name: "bar.exe",
   938  							},
   939  						},
   940  					},
   941  				},
   942  				{
   943  					Name:   "foo_1.0.1_windows_386.tar.gz",
   944  					Goos:   "windows",
   945  					Goarch: "386",
   946  					Path:   file,
   947  					Extra: map[string]interface{}{
   948  						"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
   949  						"Builds": []*artifact.Artifact{
   950  							{
   951  								Name: "foo.exe",
   952  							},
   953  							{
   954  								Name: "bar.exe",
   955  							},
   956  						},
   957  					},
   958  				},
   959  			})
   960  			require.NoError(t, err)
   961  
   962  			out, err := doBuildManifest(mf)
   963  			require.NoError(t, err)
   964  
   965  			if *update {
   966  				require.NoError(t, ioutil.WriteFile(tt.filename, out.Bytes(), 0655))
   967  			}
   968  			bts, err := ioutil.ReadFile(tt.filename)
   969  			require.NoError(t, err)
   970  			require.Equal(t, string(bts), out.String())
   971  		})
   972  	}
   973  }
   974  
   975  func TestWrapInDirectory(t *testing.T) {
   976  	var folder = t.TempDir()
   977  	var file = filepath.Join(folder, "archive")
   978  	require.NoError(t, ioutil.WriteFile(file, []byte("lorem ipsum"), 0644))
   979  	var ctx = &context.Context{
   980  		TokenType: context.TokenTypeGitLab,
   981  		Git: context.GitInfo{
   982  			CurrentTag: "v1.0.1",
   983  		},
   984  		Version:   "1.0.1",
   985  		Artifacts: artifact.New(),
   986  		Config: config.Project{
   987  			GitLabURLs: config.GitLabURLs{
   988  				Download: "https://gitlab.com",
   989  			},
   990  			Builds: []config.Build{
   991  				{Binary: "test"},
   992  			},
   993  			Dist:        ".",
   994  			ProjectName: "run-pipe",
   995  			Archives: []config.Archive{
   996  				{Format: "tar.gz", WrapInDirectory: "true"},
   997  			},
   998  			Release: config.Release{
   999  				GitHub: config.Repo{
  1000  					Owner: "test",
  1001  					Name:  "test",
  1002  				},
  1003  			},
  1004  			Scoop: config.Scoop{
  1005  				Bucket: config.RepoRef{
  1006  					Owner: "test",
  1007  					Name:  "test",
  1008  				},
  1009  				Description:           "A run pipe test formula",
  1010  				Homepage:              "https://gitlab.com/goreleaser",
  1011  				URLTemplate:           "http://gitlab.mycompany.com/foo/bar/uploads/{{ .ArtifactUploadHash }}/{{ .ArtifactName }}",
  1012  				CommitMessageTemplate: "chore(scoop): update {{ .ProjectName }} version {{ .Tag }}",
  1013  				Persist:               []string{"data.cfg", "etc"},
  1014  			},
  1015  		},
  1016  	}
  1017  	require.NoError(t, Pipe{}.Default(ctx))
  1018  	cl, err := client.New(ctx)
  1019  	require.NoError(t, err)
  1020  	mf, err := dataFor(ctx, cl, []*artifact.Artifact{
  1021  		{
  1022  			Name:   "foo_1.0.1_windows_amd64.tar.gz",
  1023  			Goos:   "windows",
  1024  			Goarch: "amd64",
  1025  			Path:   file,
  1026  			Extra: map[string]interface{}{
  1027  				"ArtifactUploadHash": "820ead5d9d2266c728dce6d4d55b6460",
  1028  				"WrappedIn":          "foo_1.0.1_windows_amd64",
  1029  				"Builds": []*artifact.Artifact{
  1030  					{
  1031  						Name: "foo.exe",
  1032  					},
  1033  					{
  1034  						Name: "bar.exe",
  1035  					},
  1036  				},
  1037  			},
  1038  		},
  1039  	})
  1040  	require.NoError(t, err)
  1041  
  1042  	out, err := doBuildManifest(mf)
  1043  	require.NoError(t, err)
  1044  
  1045  	var golden = "testdata/test_buildmanifest_wrap.json.golden"
  1046  	if *update {
  1047  		require.NoError(t, ioutil.WriteFile(golden, out.Bytes(), 0655))
  1048  	}
  1049  	bts, err := ioutil.ReadFile(golden)
  1050  	require.NoError(t, err)
  1051  	require.Equal(t, string(bts), out.String())
  1052  }
  1053  
  1054  type DummyClient struct {
  1055  	CreatedFile    bool
  1056  	Content        string
  1057  	NotImplemented bool
  1058  }
  1059  
  1060  func (dc *DummyClient) CloseMilestone(ctx *context.Context, repo client.Repo, title string) error {
  1061  	return nil
  1062  }
  1063  
  1064  func (dc *DummyClient) CreateRelease(ctx *context.Context, body string) (releaseID string, err error) {
  1065  	return
  1066  }
  1067  
  1068  func (dc *DummyClient) ReleaseURLTemplate(ctx *context.Context) (string, error) {
  1069  	if dc.NotImplemented {
  1070  		return "", client.NotImplementedError{}
  1071  	}
  1072  	return "", nil
  1073  }
  1074  
  1075  func (dc *DummyClient) CreateFile(ctx *context.Context, commitAuthor config.CommitAuthor, repo client.Repo, content []byte, path, msg string) (err error) {
  1076  	dc.CreatedFile = true
  1077  	dc.Content = string(content)
  1078  	return
  1079  }
  1080  
  1081  func (dc *DummyClient) Upload(ctx *context.Context, releaseID string, artifact *artifact.Artifact, file *os.File) (err error) {
  1082  	return
  1083  }