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