github.com/goreleaser/goreleaser@v1.25.1/internal/pipe/aur/aur_test.go (about) 1 package aur 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "testing" 8 9 "github.com/goreleaser/goreleaser/internal/artifact" 10 "github.com/goreleaser/goreleaser/internal/client" 11 "github.com/goreleaser/goreleaser/internal/git" 12 "github.com/goreleaser/goreleaser/internal/golden" 13 "github.com/goreleaser/goreleaser/internal/skips" 14 "github.com/goreleaser/goreleaser/internal/testctx" 15 "github.com/goreleaser/goreleaser/internal/testlib" 16 "github.com/goreleaser/goreleaser/pkg/config" 17 "github.com/goreleaser/goreleaser/pkg/context" 18 "github.com/stretchr/testify/require" 19 ) 20 21 func TestContinueOnError(t *testing.T) { 22 require.True(t, Pipe{}.ContinueOnError()) 23 } 24 25 func TestDescription(t *testing.T) { 26 require.NotEmpty(t, Pipe{}.String()) 27 } 28 29 func createTemplateData() templateData { 30 return templateData{ 31 Name: "test-bin", 32 Desc: "Some desc", 33 Homepage: "https://example.com", 34 Conflicts: []string{"nope"}, 35 Depends: []string{"nope"}, 36 Arches: []string{"x86_64", "i686", "aarch64", "armv6h", "armv7h"}, 37 Rel: "1", 38 Provides: []string{"test"}, 39 OptDepends: []string{"nfpm"}, 40 Backup: []string{ 41 "/etc/mypkg.conf", 42 "/var/share/mypkg", 43 }, 44 Maintainers: []string{ 45 "Ciclano <ciclano@example.com>", 46 "Cicrano <cicrano@example.com>", 47 }, 48 Contributors: []string{ 49 "Fulano <fulano@example.com>", 50 "Beltrano <beltrano@example.com>", 51 }, 52 License: "MIT", 53 Version: "0.1.3", 54 Package: `# bin 55 install -Dm755 "./goreleaser" "${pkgdir}/usr/bin/goreleaser" 56 57 # license 58 install -Dm644 "./LICENSE.md" "${pkgdir}/usr/share/licenses/goreleaser/LICENSE" 59 60 # completions 61 mkdir -p "${pkgdir}/usr/share/bash-completion/completions/" 62 mkdir -p "${pkgdir}/usr/share/zsh/site-functions/" 63 mkdir -p "${pkgdir}/usr/share/fish/vendor_completions.d/" 64 install -Dm644 "./completions/goreleaser.bash" "${pkgdir}/usr/share/bash-completion/completions/goreleaser" 65 install -Dm644 "./completions/goreleaser.zsh" "${pkgdir}/usr/share/zsh/site-functions/_goreleaser" 66 install -Dm644 "./completions/goreleaser.fish" "${pkgdir}/usr/share/fish/vendor_completions.d/goreleaser.fish" 67 68 # man pages 69 install -Dm644 "./manpages/goreleaser.1.gz" "${pkgdir}/usr/share/man/man1/goreleaser.1.gz"`, 70 ReleasePackages: []releasePackage{ 71 { 72 Arch: "x86_64", 73 DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz", 74 SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", 75 Format: "tar.gz", 76 }, 77 { 78 Arch: "armv6h", 79 DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_Arm6.tar.gz", 80 SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", 81 Format: "tar.gz", 82 }, 83 { 84 Arch: "aarch64", 85 DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_Arm64.tar.gz", 86 SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", 87 Format: "tar.gz", 88 }, 89 { 90 Arch: "i686", 91 DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_386.tar.gz", 92 SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", 93 Format: "tar.gz", 94 }, 95 { 96 Arch: "armv7h", 97 DownloadURL: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_arm7.tar.gz", 98 SHA256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67", 99 Format: "tar.gz", 100 }, 101 }, 102 } 103 } 104 105 func TestFullAur(t *testing.T) { 106 data := createTemplateData() 107 pkg, err := applyTemplate(testctx.NewWithCfg(config.Project{ 108 ProjectName: "foo", 109 }), aurTemplateData, data) 110 require.NoError(t, err) 111 112 golden.RequireEqual(t, []byte(pkg)) 113 } 114 115 func TestAurSimple(t *testing.T) { 116 pkg, err := applyTemplate(testctx.New(), aurTemplateData, createTemplateData()) 117 require.NoError(t, err) 118 require.Contains(t, pkg, `# Maintainer: Ciclano <ciclano@example.com>`) 119 require.Contains(t, pkg, `# Maintainer: Cicrano <cicrano@example.com>`) 120 require.Contains(t, pkg, `# Contributor: Fulano <fulano@example.com>`) 121 require.Contains(t, pkg, `# Contributor: Beltrano <beltrano@example.com>`) 122 require.Contains(t, pkg, `pkgname='test-bin'`) 123 require.Contains(t, pkg, `url='https://example.com'`) 124 require.Contains(t, pkg, `source_x86_64=("${pkgname}_${pkgver}_x86_64.tar.gz::https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz")`) 125 require.Contains(t, pkg, `sha256sums_x86_64=('1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67')`) 126 require.Contains(t, pkg, `pkgver=0.1.3`) 127 } 128 129 func TestFullSrcInfo(t *testing.T) { 130 data := createTemplateData() 131 data.License = "MIT" 132 pkg, err := applyTemplate(testctx.NewWithCfg(config.Project{ 133 ProjectName: "foo", 134 }), srcInfoTemplate, data) 135 require.NoError(t, err) 136 137 golden.RequireEqual(t, []byte(pkg)) 138 } 139 140 func TestSrcInfoSimple(t *testing.T) { 141 pkg, err := applyTemplate(testctx.New(), srcInfoTemplate, createTemplateData()) 142 require.NoError(t, err) 143 require.Contains(t, pkg, `pkgbase = test-bin`) 144 require.Contains(t, pkg, `pkgname = test-bin`) 145 require.Contains(t, pkg, `url = https://example.com`) 146 require.Contains(t, pkg, `source_x86_64 = https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz`) 147 require.Contains(t, pkg, `sha256sums_x86_64 = 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67`) 148 require.Contains(t, pkg, `pkgver = 0.1.3`) 149 } 150 151 func TestFullPipe(t *testing.T) { 152 type testcase struct { 153 prepare func(ctx *context.Context) 154 expectedRunError string 155 expectedRunErrorCheck func(testing.TB, error) 156 expectedPublishError string 157 expectedPublishErrorIs error 158 expectedPublishErrorCheck func(testing.TB, error) 159 } 160 for name, tt := range map[string]testcase{ 161 "default": { 162 prepare: func(ctx *context.Context) { 163 ctx.TokenType = context.TokenTypeGitHub 164 ctx.Config.AURs[0].Homepage = "https://github.com/goreleaser" 165 }, 166 }, 167 "custom-dir": { 168 prepare: func(ctx *context.Context) { 169 ctx.TokenType = context.TokenTypeGitHub 170 ctx.Config.AURs[0].Homepage = "https://github.com/goreleaser" 171 ctx.Config.AURs[0].Directory = "foo" 172 }, 173 }, 174 "with-more-opts": { 175 prepare: func(ctx *context.Context) { 176 ctx.TokenType = context.TokenTypeGitHub 177 ctx.Config.AURs[0].Homepage = "https://github.com/goreleaser" 178 ctx.Config.AURs[0].Maintainers = []string{"me"} 179 ctx.Config.AURs[0].Contributors = []string{"me as well"} 180 ctx.Config.AURs[0].Depends = []string{"curl", "bash"} 181 ctx.Config.AURs[0].OptDepends = []string{"wget: stuff", "foo: bar"} 182 ctx.Config.AURs[0].Provides = []string{"git", "svn"} 183 ctx.Config.AURs[0].Conflicts = []string{"libcurl", "cvs", "blah"} 184 }, 185 }, 186 "default-gitlab": { 187 prepare: func(ctx *context.Context) { 188 ctx.TokenType = context.TokenTypeGitLab 189 ctx.Config.AURs[0].Homepage = "https://gitlab.com/goreleaser" 190 }, 191 }, 192 "invalid-name-template": { 193 prepare: func(ctx *context.Context) { 194 ctx.Config.AURs[0].Name = "{{ .Asdsa }" 195 }, 196 expectedRunErrorCheck: testlib.RequireTemplateError, 197 }, 198 "invalid-package-template": { 199 prepare: func(ctx *context.Context) { 200 ctx.Config.AURs[0].Package = "{{ .Asdsa }" 201 }, 202 expectedRunErrorCheck: testlib.RequireTemplateError, 203 }, 204 "invalid-commit-template": { 205 prepare: func(ctx *context.Context) { 206 ctx.Config.AURs[0].CommitMessageTemplate = "{{ .Asdsa }" 207 }, 208 expectedPublishErrorCheck: testlib.RequireTemplateError, 209 }, 210 "invalid-key-template": { 211 prepare: func(ctx *context.Context) { 212 ctx.Config.AURs[0].PrivateKey = "{{ .Asdsa }" 213 }, 214 expectedPublishErrorCheck: testlib.RequireTemplateError, 215 }, 216 "no-key": { 217 prepare: func(ctx *context.Context) { 218 ctx.Config.AURs[0].PrivateKey = "" 219 }, 220 expectedPublishError: `private_key is empty`, 221 }, 222 "key-not-found": { 223 prepare: func(ctx *context.Context) { 224 ctx.Config.AURs[0].PrivateKey = "testdata/nope" 225 }, 226 expectedPublishErrorIs: os.ErrNotExist, 227 }, 228 "invalid-git-url-template": { 229 prepare: func(ctx *context.Context) { 230 ctx.Config.AURs[0].GitURL = "{{ .Asdsa }" 231 }, 232 expectedPublishErrorCheck: testlib.RequireTemplateError, 233 }, 234 "no-git-url": { 235 prepare: func(ctx *context.Context) { 236 ctx.Config.AURs[0].GitURL = "" 237 }, 238 expectedPublishError: `url is empty`, 239 }, 240 "invalid-ssh-cmd-template": { 241 prepare: func(ctx *context.Context) { 242 ctx.Config.AURs[0].GitSSHCommand = "{{ .Asdsa }" 243 }, 244 expectedPublishErrorCheck: testlib.RequireTemplateError, 245 }, 246 "invalid-commit-author-template": { 247 prepare: func(ctx *context.Context) { 248 ctx.Config.AURs[0].CommitAuthor.Name = "{{ .Asdsa }" 249 }, 250 expectedPublishErrorCheck: testlib.RequireTemplateError, 251 }, 252 } { 253 t.Run(name, func(t *testing.T) { 254 url := testlib.GitMakeBareRepository(t) 255 key := testlib.MakeNewSSHKey(t, "") 256 257 folder := t.TempDir() 258 ctx := testctx.NewWithCfg( 259 config.Project{ 260 Dist: folder, 261 ProjectName: name, 262 AURs: []config.AUR{ 263 { 264 Name: name, 265 IDs: []string{"foo"}, 266 PrivateKey: key, 267 License: "MIT", 268 GitURL: url, 269 Description: "A run pipe test fish food and FOO={{ .Env.FOO }}", 270 }, 271 }, 272 Env: []string{"FOO=foo_is_bar"}, 273 }, 274 testctx.WithCurrentTag("v1.0.1-foo"), 275 testctx.WithSemver(1, 0, 1, "foo"), 276 testctx.WithVersion("1.0.1-foo"), 277 ) 278 279 tt.prepare(ctx) 280 ctx.Artifacts.Add(&artifact.Artifact{ 281 Name: "should-be-ignored.tar.gz", 282 Path: "doesnt matter", 283 Goos: "linux", 284 Goarch: "amd64", 285 Goamd64: "v3", 286 Type: artifact.UploadableArchive, 287 Extra: map[string]interface{}{ 288 artifact.ExtraID: "bar", 289 artifact.ExtraFormat: "tar.gz", 290 artifact.ExtraBinaries: []string{"bar"}, 291 }, 292 }) 293 ctx.Artifacts.Add(&artifact.Artifact{ 294 Name: "bar_bin.tar.gz", 295 Path: "doesnt matter", 296 Goos: "linux", 297 Goarch: "amd64", 298 Goamd64: "v1", 299 Type: artifact.UploadableArchive, 300 Extra: map[string]interface{}{ 301 artifact.ExtraID: "bar", 302 artifact.ExtraFormat: "tar.gz", 303 artifact.ExtraBinaries: []string{"bar"}, 304 }, 305 }) 306 path := filepath.Join(folder, "bin.tar.gz") 307 ctx.Artifacts.Add(&artifact.Artifact{ 308 Name: "bin.tar.gz", 309 Path: path, 310 Goos: "linux", 311 Goarch: "amd64", 312 Goamd64: "v1", 313 Type: artifact.UploadableArchive, 314 Extra: map[string]interface{}{ 315 artifact.ExtraID: "foo", 316 artifact.ExtraFormat: "tar.gz", 317 artifact.ExtraBinaries: []string{"name"}, 318 }, 319 }) 320 321 f, err := os.Create(path) 322 require.NoError(t, err) 323 require.NoError(t, f.Close()) 324 client := client.NewMock() 325 326 require.NoError(t, Pipe{}.Default(ctx)) 327 328 if tt.expectedRunError != "" { 329 require.EqualError(t, runAll(ctx, client), tt.expectedRunError) 330 return 331 } 332 if tt.expectedRunErrorCheck != nil { 333 tt.expectedRunErrorCheck(t, runAll(ctx, client)) 334 return 335 } 336 require.NoError(t, runAll(ctx, client)) 337 338 if tt.expectedPublishError != "" { 339 require.EqualError(t, Pipe{}.Publish(ctx), tt.expectedPublishError) 340 return 341 } 342 343 if tt.expectedPublishErrorIs != nil { 344 require.ErrorIs(t, Pipe{}.Publish(ctx), tt.expectedPublishErrorIs) 345 return 346 } 347 348 if tt.expectedPublishErrorCheck != nil { 349 tt.expectedPublishErrorCheck(t, Pipe{}.Publish(ctx)) 350 return 351 } 352 353 require.NoError(t, Pipe{}.Publish(ctx)) 354 355 requireEqualRepoFiles(t, folder, ctx.Config.AURs[0].Directory, name, url) 356 }) 357 } 358 } 359 360 func TestRunPipe(t *testing.T) { 361 url := testlib.GitMakeBareRepository(t) 362 key := testlib.MakeNewSSHKey(t, "") 363 364 folder := t.TempDir() 365 ctx := testctx.NewWithCfg( 366 config.Project{ 367 Dist: folder, 368 ProjectName: "foo", 369 AURs: []config.AUR{ 370 { 371 License: "MIT", 372 Description: "A run pipe test aur and FOO={{ .Env.FOO }}", 373 Homepage: "https://github.com/goreleaser", 374 IDs: []string{"foo"}, 375 GitURL: url, 376 PrivateKey: key, 377 }, 378 }, 379 GitHubURLs: config.GitHubURLs{ 380 Download: "https://github.com", 381 }, 382 Release: config.Release{ 383 GitHub: config.Repo{ 384 Owner: "test", 385 Name: "test", 386 }, 387 }, 388 Env: []string{"FOO=foo_is_bar"}, 389 }, 390 testctx.GitHubTokenType, 391 testctx.WithCurrentTag("v1.0.1"), 392 testctx.WithSemver(1, 0, 1, ""), 393 testctx.WithVersion("1.0.1"), 394 ) 395 396 for _, a := range []struct { 397 name string 398 goos string 399 goarch string 400 goarm string 401 }{ 402 { 403 name: "bin", 404 goos: "darwin", 405 goarch: "amd64", 406 }, 407 { 408 name: "bin", 409 goos: "darwin", 410 goarch: "arm64", 411 }, 412 { 413 name: "bin", 414 goos: "windows", 415 goarch: "arm64", 416 }, 417 { 418 name: "bin", 419 goos: "windows", 420 goarch: "amd64", 421 }, 422 { 423 name: "bin", 424 goos: "linux", 425 goarch: "386", 426 }, 427 { 428 name: "bin", 429 goos: "linux", 430 goarch: "amd64", 431 }, 432 { 433 name: "arm64", 434 goos: "linux", 435 goarch: "arm64", 436 }, 437 { 438 name: "armv5", 439 goos: "linux", 440 goarch: "arm", 441 goarm: "5", 442 }, 443 { 444 name: "armv6", 445 goos: "linux", 446 goarch: "arm", 447 goarm: "6", 448 }, 449 { 450 name: "armv7", 451 goos: "linux", 452 goarch: "arm", 453 goarm: "7", 454 }, 455 } { 456 path := filepath.Join(folder, fmt.Sprintf("%s.tar.gz", a.name)) 457 ctx.Artifacts.Add(&artifact.Artifact{ 458 Name: fmt.Sprintf("%s.tar.gz", a.name), 459 Path: path, 460 Goos: a.goos, 461 Goarch: a.goarch, 462 Goarm: a.goarm, 463 Goamd64: "v1", 464 Type: artifact.UploadableArchive, 465 Extra: map[string]interface{}{ 466 artifact.ExtraID: "foo", 467 artifact.ExtraFormat: "tar.gz", 468 artifact.ExtraBinaries: []string{"foo"}, 469 }, 470 }) 471 f, err := os.Create(path) 472 require.NoError(t, err) 473 require.NoError(t, f.Close()) 474 } 475 476 client := client.NewMock() 477 478 require.NoError(t, Pipe{}.Default(ctx)) 479 require.NoError(t, runAll(ctx, client)) 480 require.NoError(t, Pipe{}.Publish(ctx)) 481 482 requireEqualRepoFiles(t, folder, ".", "foo", url) 483 } 484 485 func TestRunPipeMultipleConfigurations(t *testing.T) { 486 url := testlib.GitMakeBareRepository(t) 487 key := testlib.MakeNewSSHKey(t, "") 488 489 folder := t.TempDir() 490 ctx := testctx.NewWithCfg( 491 config.Project{ 492 Dist: folder, 493 ProjectName: "foo", 494 AURs: []config.AUR{ 495 { 496 Name: "foo", 497 IDs: []string{"foo"}, 498 PrivateKey: key, 499 License: "MIT", 500 GitURL: url, 501 Description: "The foo aur", 502 Directory: "foo", 503 }, 504 { 505 Name: "bar", 506 IDs: []string{"bar"}, 507 PrivateKey: key, 508 License: "MIT", 509 GitURL: url, 510 Description: "The bar aur", 511 Directory: "bar", 512 }, 513 }, 514 }, 515 testctx.WithCurrentTag("v1.0.1-foo"), 516 testctx.WithSemver(1, 0, 1, "foo"), 517 testctx.WithVersion("1.0.1-foo"), 518 ) 519 520 path := filepath.Join(folder, "bin.tar.gz") 521 ctx.Artifacts.Add(&artifact.Artifact{ 522 Name: "bar_bin.tar.gz", 523 Path: path, 524 Goos: "linux", 525 Goarch: "amd64", 526 Goamd64: "v1", 527 Type: artifact.UploadableArchive, 528 Extra: map[string]interface{}{ 529 artifact.ExtraID: "bar", 530 artifact.ExtraFormat: "tar.gz", 531 artifact.ExtraBinaries: []string{"bar"}, 532 }, 533 }) 534 ctx.Artifacts.Add(&artifact.Artifact{ 535 Name: "bin.tar.gz", 536 Path: path, 537 Goos: "linux", 538 Goarch: "amd64", 539 Goamd64: "v1", 540 Type: artifact.UploadableArchive, 541 Extra: map[string]interface{}{ 542 artifact.ExtraID: "foo", 543 artifact.ExtraFormat: "tar.gz", 544 artifact.ExtraBinaries: []string{"name"}, 545 }, 546 }) 547 548 f, err := os.Create(path) 549 require.NoError(t, err) 550 require.NoError(t, f.Close()) 551 client := client.NewMock() 552 553 require.NoError(t, Pipe{}.Default(ctx)) 554 require.NoError(t, runAll(ctx, client)) 555 require.NoError(t, Pipe{}.Publish(ctx)) 556 557 dir := t.TempDir() 558 _, err = git.Run(testctx.New(), "-C", dir, "clone", url, "repo") 559 require.NoError(t, err) 560 561 require.FileExists(t, filepath.Join(dir, "repo", "foo", ".SRCINFO")) 562 require.FileExists(t, filepath.Join(dir, "repo", "foo", "PKGBUILD")) 563 require.FileExists(t, filepath.Join(dir, "repo", "bar", ".SRCINFO")) 564 require.FileExists(t, filepath.Join(dir, "repo", "bar", "PKGBUILD")) 565 } 566 567 func TestRunPipeNoBuilds(t *testing.T) { 568 ctx := testctx.NewWithCfg(config.Project{ 569 ProjectName: "foo", 570 AURs: []config.AUR{{}}, 571 }, testctx.GitHubTokenType) 572 client := client.NewMock() 573 require.NoError(t, Pipe{}.Default(ctx)) 574 require.Equal(t, ErrNoArchivesFound, runAll(ctx, client)) 575 require.False(t, client.CreatedFile) 576 } 577 578 func TestRunPipeWrappedInDirectory(t *testing.T) { 579 url := testlib.GitMakeBareRepository(t) 580 key := testlib.MakeNewSSHKey(t, "") 581 folder := t.TempDir() 582 ctx := testctx.NewWithCfg( 583 config.Project{ 584 Dist: folder, 585 ProjectName: "foo", 586 AURs: []config.AUR{{ 587 GitURL: url, 588 PrivateKey: key, 589 }}, 590 }, 591 testctx.WithVersion("1.2.1"), 592 testctx.WithCurrentTag("v1.2.1"), 593 testctx.WithSemver(1, 2, 1, ""), 594 ) 595 596 path := filepath.Join(folder, "dist/foo_linux_amd64/foo") 597 ctx.Artifacts.Add(&artifact.Artifact{ 598 Name: "foo.tar.gz", 599 Path: path, 600 Goos: "linux", 601 Goarch: "amd64", 602 Goamd64: "v1", 603 Type: artifact.UploadableArchive, 604 Extra: map[string]interface{}{ 605 artifact.ExtraID: "foo", 606 artifact.ExtraFormat: "tar.gz", 607 artifact.ExtraBinaries: []string{"foo"}, 608 artifact.ExtraWrappedIn: "foo", 609 }, 610 }) 611 612 require.NoError(t, Pipe{}.Default(ctx)) 613 require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) 614 f, err := os.Create(path) 615 require.NoError(t, err) 616 require.NoError(t, f.Close()) 617 618 client := client.NewMock() 619 require.NoError(t, runAll(ctx, client)) 620 require.NoError(t, Pipe{}.Publish(ctx)) 621 622 requireEqualRepoFiles(t, folder, ".", "foo", url) 623 } 624 625 func TestRunPipeBinaryRelease(t *testing.T) { 626 url := testlib.GitMakeBareRepository(t) 627 key := testlib.MakeNewSSHKey(t, "") 628 folder := t.TempDir() 629 ctx := testctx.NewWithCfg( 630 config.Project{ 631 Dist: folder, 632 ProjectName: "foo", 633 AURs: []config.AUR{{ 634 GitURL: url, 635 PrivateKey: key, 636 }}, 637 }, 638 testctx.WithVersion("1.2.1"), 639 testctx.WithCurrentTag("v1.2.1"), 640 testctx.WithSemver(1, 2, 1, ""), 641 ) 642 643 path := filepath.Join(folder, "dist/foo_linux_amd64/foo") 644 ctx.Artifacts.Add(&artifact.Artifact{ 645 Name: "foo_linux_amd64", 646 Path: path, 647 Goos: "linux", 648 Goarch: "amd64", 649 Goamd64: "v1", 650 Type: artifact.UploadableBinary, 651 Extra: map[string]interface{}{ 652 artifact.ExtraID: "foo", 653 artifact.ExtraFormat: "binary", 654 artifact.ExtraBinary: "foo", 655 }, 656 }) 657 658 require.NoError(t, Pipe{}.Default(ctx)) 659 require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755)) 660 f, err := os.Create(path) 661 require.NoError(t, err) 662 require.NoError(t, f.Close()) 663 664 client := client.NewMock() 665 require.NoError(t, runAll(ctx, client)) 666 require.NoError(t, Pipe{}.Publish(ctx)) 667 668 requireEqualRepoFiles(t, folder, ".", "foo", url) 669 } 670 671 func TestRunPipeNoUpload(t *testing.T) { 672 folder := t.TempDir() 673 testPublish := func(tb testing.TB, modifier func(ctx *context.Context)) { 674 tb.Helper() 675 ctx := testctx.NewWithCfg( 676 config.Project{ 677 Dist: folder, 678 ProjectName: "foo", 679 Release: config.Release{}, 680 AURs: []config.AUR{{}}, 681 }, 682 testctx.GitHubTokenType, 683 testctx.WithCurrentTag("v1.0.1"), 684 testctx.WithSemver(1, 0, 1, ""), 685 ) 686 687 path := filepath.Join(folder, "whatever.tar.gz") 688 f, err := os.Create(path) 689 require.NoError(t, err) 690 require.NoError(t, f.Close()) 691 ctx.Artifacts.Add(&artifact.Artifact{ 692 Name: "bin", 693 Path: path, 694 Goos: "linux", 695 Goarch: "amd64", 696 Goamd64: "v1", 697 Type: artifact.UploadableArchive, 698 Extra: map[string]interface{}{ 699 artifact.ExtraID: "foo", 700 artifact.ExtraFormat: "tar.gz", 701 artifact.ExtraBinaries: []string{"foo"}, 702 }, 703 }) 704 705 modifier(ctx) 706 707 require.NoError(t, Pipe{}.Default(ctx)) 708 client := client.NewMock() 709 require.NoError(t, runAll(ctx, client)) 710 t.Log(Pipe{}.Publish(ctx)) 711 testlib.AssertSkipped(t, Pipe{}.Publish(ctx)) 712 require.False(t, client.CreatedFile) 713 } 714 715 t.Run("skip upload true", func(t *testing.T) { 716 testPublish(t, func(ctx *context.Context) { 717 ctx.Config.AURs[0].SkipUpload = "true" 718 ctx.Semver.Prerelease = "" 719 }) 720 }) 721 t.Run("skip upload auto", func(t *testing.T) { 722 testPublish(t, func(ctx *context.Context) { 723 ctx.Config.AURs[0].SkipUpload = "auto" 724 ctx.Semver.Prerelease = "beta1" 725 }) 726 }) 727 } 728 729 func TestRunEmptyTokenType(t *testing.T) { 730 folder := t.TempDir() 731 ctx := testctx.NewWithCfg( 732 config.Project{ 733 Dist: folder, 734 ProjectName: "foo", 735 Release: config.Release{}, 736 AURs: []config.AUR{ 737 {}, 738 }, 739 }, 740 testctx.WithGitInfo(context.GitInfo{CurrentTag: "v1.0.1"}), 741 testctx.WithSemver(1, 0, 1, ""), 742 ) 743 path := filepath.Join(folder, "whatever.tar.gz") 744 f, err := os.Create(path) 745 require.NoError(t, err) 746 require.NoError(t, f.Close()) 747 ctx.Artifacts.Add(&artifact.Artifact{ 748 Name: "bin", 749 Path: path, 750 Goos: "linux", 751 Goarch: "amd64", 752 Type: artifact.UploadableArchive, 753 Extra: map[string]interface{}{ 754 artifact.ExtraID: "foo", 755 artifact.ExtraFormat: "tar.gz", 756 artifact.ExtraBinaries: []string{"foo"}, 757 }, 758 }) 759 client := client.NewMock() 760 require.NoError(t, runAll(ctx, client)) 761 } 762 763 func TestDefault(t *testing.T) { 764 t.Run("empty", func(t *testing.T) { 765 ctx := testctx.NewWithCfg(config.Project{ 766 ProjectName: "myproject", 767 AURs: []config.AUR{{}}, 768 }, testctx.GitHubTokenType) 769 require.NoError(t, Pipe{}.Default(ctx)) 770 require.Equal(t, config.AUR{ 771 Name: "myproject-bin", 772 Conflicts: []string{"myproject"}, 773 Provides: []string{"myproject"}, 774 Rel: "1", 775 CommitMessageTemplate: defaultCommitMsg, 776 Goamd64: "v1", 777 CommitAuthor: config.CommitAuthor{ 778 Name: "goreleaserbot", 779 Email: "bot@goreleaser.com", 780 }, 781 }, ctx.Config.AURs[0]) 782 }) 783 784 t.Run("name-without-bin-suffix", func(t *testing.T) { 785 ctx := testctx.NewWithCfg(config.Project{ 786 ProjectName: "myproject", 787 AURs: []config.AUR{ 788 { 789 Name: "foo", 790 }, 791 }, 792 }, testctx.GitHubTokenType) 793 require.NoError(t, Pipe{}.Default(ctx)) 794 require.Equal(t, config.AUR{ 795 Name: "foo-bin", 796 Conflicts: []string{"myproject"}, 797 Provides: []string{"myproject"}, 798 Rel: "1", 799 CommitMessageTemplate: defaultCommitMsg, 800 Goamd64: "v1", 801 CommitAuthor: config.CommitAuthor{ 802 Name: "goreleaserbot", 803 Email: "bot@goreleaser.com", 804 }, 805 }, ctx.Config.AURs[0]) 806 }) 807 808 t.Run("partial", func(t *testing.T) { 809 ctx := testctx.NewWithCfg(config.Project{ 810 ProjectName: "myproject", 811 AURs: []config.AUR{ 812 { 813 Conflicts: []string{"somethingelse"}, 814 Goamd64: "v3", 815 }, 816 }, 817 }, testctx.GitHubTokenType) 818 require.NoError(t, Pipe{}.Default(ctx)) 819 require.Equal(t, config.AUR{ 820 Name: "myproject-bin", 821 Conflicts: []string{"somethingelse"}, 822 Provides: []string{"myproject"}, 823 Rel: "1", 824 CommitMessageTemplate: defaultCommitMsg, 825 Goamd64: "v3", 826 CommitAuthor: config.CommitAuthor{ 827 Name: "goreleaserbot", 828 Email: "bot@goreleaser.com", 829 }, 830 }, ctx.Config.AURs[0]) 831 }) 832 } 833 834 func TestSkip(t *testing.T) { 835 t.Run("skip", func(t *testing.T) { 836 require.True(t, Pipe{}.Skip(testctx.New())) 837 }) 838 t.Run("skip flag", func(t *testing.T) { 839 ctx := testctx.NewWithCfg(config.Project{ 840 AURs: []config.AUR{ 841 {}, 842 }, 843 }, testctx.Skip(skips.AUR)) 844 require.True(t, Pipe{}.Skip(ctx)) 845 }) 846 t.Run("dont skip", func(t *testing.T) { 847 ctx := testctx.NewWithCfg(config.Project{ 848 AURs: []config.AUR{ 849 {}, 850 }, 851 }) 852 require.False(t, Pipe{}.Skip(ctx)) 853 }) 854 } 855 856 func requireEqualRepoFiles(tb testing.TB, distDir, repoDir, name, url string) { 857 tb.Helper() 858 dir := tb.TempDir() 859 _, err := git.Run(testctx.New(), "-C", dir, "clone", url, "repo") 860 require.NoError(tb, err) 861 862 for reponame, ext := range map[string]string{ 863 "PKGBUILD": ".pkgbuild", 864 ".SRCINFO": ".srcinfo", 865 } { 866 path := filepath.Join(distDir, "aur", name+"-bin"+ext) 867 bts, err := os.ReadFile(path) 868 require.NoError(tb, err) 869 golden.RequireEqualExt(tb, bts, ext) 870 871 bts, err = os.ReadFile(filepath.Join(dir, "repo", repoDir, reponame)) 872 require.NoError(tb, err) 873 golden.RequireEqualExt(tb, bts, ext) 874 } 875 }