You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-11-06 09:09:29 +02:00
feat: krew support (#2639)
* feat: krew support * fix: adds it to the pipe * chore: fmt * test: improvements * fix: rm unused code * fix: stringer * fix: tmpl * test: improvements * fix: lint issues * fix: only allow 1 binary per archive * fix: validate * chore: comment * fix: renamed to manifest * fix: krew plugin manifest * fix: name * fix: godoc * fix: install validate-krew-manifest on ci * fix: helper * fix: ensure order * fix: testing * docs: guidelines * fix: flag
This commit is contained in:
committed by
GitHub
parent
c958e4cc5e
commit
52cf951c30
3
.github/workflows/build.yml
vendored
3
.github/workflows/build.yml
vendored
@@ -62,6 +62,9 @@ jobs:
|
|||||||
-
|
-
|
||||||
name: Setup Sigstore
|
name: Setup Sigstore
|
||||||
uses: sigstore/cosign-installer@v1.3.0
|
uses: sigstore/cosign-installer@v1.3.0
|
||||||
|
- # TODO: replace this once https://github.com/kubernetes-sigs/krew/pull/736 is merged
|
||||||
|
name: Install validate-krew-manifest
|
||||||
|
run: go install github.com/caarlos0/krew/cmd/validate-krew-manifest@fork
|
||||||
-
|
-
|
||||||
name: build and test
|
name: build and test
|
||||||
run: task ci
|
run: task ci
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ const (
|
|||||||
BrewTap
|
BrewTap
|
||||||
// GoFishRig is an uploadable Rigs rig food file.
|
// GoFishRig is an uploadable Rigs rig food file.
|
||||||
GoFishRig
|
GoFishRig
|
||||||
|
// KrewPluginManifest is a krew plugin manifest file.
|
||||||
|
KrewPluginManifest
|
||||||
// ScoopManifest is an uploadable scoop manifest file.
|
// ScoopManifest is an uploadable scoop manifest file.
|
||||||
ScoopManifest
|
ScoopManifest
|
||||||
)
|
)
|
||||||
@@ -84,6 +86,8 @@ func (t Type) String() string {
|
|||||||
return "Brew Tap"
|
return "Brew Tap"
|
||||||
case GoFishRig:
|
case GoFishRig:
|
||||||
return "GoFish Rig"
|
return "GoFish Rig"
|
||||||
|
case KrewPluginManifest:
|
||||||
|
return "Krew Plugin Manifest"
|
||||||
case ScoopManifest:
|
case ScoopManifest:
|
||||||
return "Scoop Manifest"
|
return "Scoop Manifest"
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -362,6 +362,7 @@ func TestTypeToString(t *testing.T) {
|
|||||||
UploadableSourceArchive,
|
UploadableSourceArchive,
|
||||||
BrewTap,
|
BrewTap,
|
||||||
GoFishRig,
|
GoFishRig,
|
||||||
|
KrewPluginManifest,
|
||||||
ScoopManifest,
|
ScoopManifest,
|
||||||
} {
|
} {
|
||||||
t.Run(a.String(), func(t *testing.T) {
|
t.Run(a.String(), func(t *testing.T) {
|
||||||
|
|||||||
@@ -12,40 +12,47 @@ import (
|
|||||||
|
|
||||||
var update = flag.Bool("update", false, "update .golden files")
|
var update = flag.Bool("update", false, "update .golden files")
|
||||||
|
|
||||||
|
const golden = ".golden"
|
||||||
|
|
||||||
func RequireEqual(tb testing.TB, out []byte) {
|
func RequireEqual(tb testing.TB, out []byte) {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
doRequireEqual(tb, out, "")
|
doRequireEqual(tb, out, "", golden)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequireEqualTxt(tb testing.TB, out []byte) {
|
func RequireEqualTxt(tb testing.TB, out []byte) {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
doRequireEqual(tb, out, ".txt")
|
doRequireEqual(tb, out, ".txt", golden)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequireEqualJSON(tb testing.TB, out []byte) {
|
func RequireEqualJSON(tb testing.TB, out []byte) {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
doRequireEqual(tb, out, ".json")
|
doRequireEqual(tb, out, ".json", golden)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequireEqualRb(tb testing.TB, out []byte) {
|
func RequireEqualRb(tb testing.TB, out []byte) {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
doRequireEqual(tb, out, ".rb")
|
doRequireEqual(tb, out, ".rb", golden)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequireEqualLua(tb testing.TB, out []byte) {
|
func RequireEqualLua(tb testing.TB, out []byte) {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
doRequireEqual(tb, out, ".lua")
|
doRequireEqual(tb, out, ".lua", golden)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequireEqualYaml(tb testing.TB, out []byte) {
|
func RequireEqualYaml(tb testing.TB, out []byte) {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
doRequireEqual(tb, out, ".yml")
|
doRequireEqual(tb, out, ".yml", golden)
|
||||||
}
|
}
|
||||||
|
|
||||||
func doRequireEqual(tb testing.TB, out []byte, ext string) {
|
func RequireEqualNakedYaml(tb testing.TB, out []byte) {
|
||||||
|
tb.Helper()
|
||||||
|
doRequireEqual(tb, out, ".yaml", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func doRequireEqual(tb testing.TB, out []byte, ext, suffix string) {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
golden := "testdata/" + tb.Name() + ext + ".golden"
|
golden := "testdata/" + tb.Name() + ext + suffix
|
||||||
if *update {
|
if *update {
|
||||||
require.NoError(tb, os.MkdirAll(filepath.Dir(golden), 0o755))
|
require.NoError(tb, os.MkdirAll(filepath.Dir(golden), 0o755))
|
||||||
require.NoError(tb, os.WriteFile(golden, out, 0o655))
|
require.NoError(tb, os.WriteFile(golden, out, 0o655))
|
||||||
|
|||||||
354
internal/pipe/krew/krew.go
Normal file
354
internal/pipe/krew/krew.go
Normal file
@@ -0,0 +1,354 @@
|
|||||||
|
// Package krew implements Piper and Publisher, providing krew plugin manifest
|
||||||
|
// creation and upload to a repository (aka krew plugin index).
|
||||||
|
package krew
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/apex/log"
|
||||||
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||||
|
"github.com/goreleaser/goreleaser/internal/client"
|
||||||
|
"github.com/goreleaser/goreleaser/internal/pipe"
|
||||||
|
"github.com/goreleaser/goreleaser/internal/tmpl"
|
||||||
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
krewConfigExtra = "KrewConfig"
|
||||||
|
manifestsFolder = "plugins"
|
||||||
|
kind = "Plugin"
|
||||||
|
apiVersion = "krew.googlecontainertools.github.com/v1alpha2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ErrNoArchivesFound = errors.New("no archives found")
|
||||||
|
|
||||||
|
// Pipe for krew manifest deployment.
|
||||||
|
type Pipe struct{}
|
||||||
|
|
||||||
|
func (Pipe) String() string { return "krew plugin manifest" }
|
||||||
|
func (Pipe) Skip(ctx *context.Context) bool { return len(ctx.Config.Krews) == 0 }
|
||||||
|
|
||||||
|
func (Pipe) Default(ctx *context.Context) error {
|
||||||
|
for i := range ctx.Config.Krews {
|
||||||
|
krew := &ctx.Config.Krews[i]
|
||||||
|
|
||||||
|
if krew.CommitAuthor.Name == "" {
|
||||||
|
krew.CommitAuthor.Name = "goreleaserbot"
|
||||||
|
}
|
||||||
|
if krew.CommitAuthor.Email == "" {
|
||||||
|
krew.CommitAuthor.Email = "goreleaser@carlosbecker.com"
|
||||||
|
}
|
||||||
|
if krew.CommitMessageTemplate == "" {
|
||||||
|
krew.CommitMessageTemplate = "Krew manifest update for {{ .ProjectName }} version {{ .Tag }}"
|
||||||
|
}
|
||||||
|
if krew.Name == "" {
|
||||||
|
krew.Name = ctx.Config.ProjectName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Pipe) Run(ctx *context.Context) error {
|
||||||
|
cli, err := client.New(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return runAll(ctx, cli)
|
||||||
|
}
|
||||||
|
|
||||||
|
func runAll(ctx *context.Context, cli client.Client) error {
|
||||||
|
for _, krew := range ctx.Config.Krews {
|
||||||
|
err := doRun(ctx, krew, cli)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func doRun(ctx *context.Context, krew config.Krew, cl client.Client) error {
|
||||||
|
if krew.Name == "" {
|
||||||
|
return pipe.Skip("krew: manifest name is not set")
|
||||||
|
}
|
||||||
|
if krew.Description == "" {
|
||||||
|
return fmt.Errorf("krew: manifest description is not set")
|
||||||
|
}
|
||||||
|
if krew.ShortDescription == "" {
|
||||||
|
return fmt.Errorf("krew: manifest short description is not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
filters := []artifact.Filter{
|
||||||
|
artifact.Or(
|
||||||
|
artifact.ByGoos("darwin"),
|
||||||
|
artifact.ByGoos("linux"),
|
||||||
|
artifact.ByGoos("windows"),
|
||||||
|
),
|
||||||
|
artifact.Or(
|
||||||
|
artifact.ByGoarch("amd64"),
|
||||||
|
artifact.ByGoarch("arm64"),
|
||||||
|
artifact.ByGoarch("all"),
|
||||||
|
artifact.And(
|
||||||
|
artifact.ByGoarch("arm"),
|
||||||
|
artifact.ByGoarm(krew.Goarm),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
artifact.ByType(artifact.UploadableArchive),
|
||||||
|
}
|
||||||
|
if len(krew.IDs) > 0 {
|
||||||
|
filters = append(filters, artifact.ByIDs(krew.IDs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
archives := ctx.Artifacts.Filter(artifact.And(filters...)).List()
|
||||||
|
if len(archives) == 0 {
|
||||||
|
return ErrNoArchivesFound
|
||||||
|
}
|
||||||
|
|
||||||
|
krew, err := templateFields(ctx, krew)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := buildmanifest(ctx, krew, cl, archives)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
filename := krew.Name + ".yaml"
|
||||||
|
yamlPath := filepath.Join(ctx.Config.Dist, filename)
|
||||||
|
log.WithField("manifest", yamlPath).Info("writing")
|
||||||
|
if err := os.WriteFile(yamlPath, []byte(content), 0o644); err != nil { //nolint: gosec
|
||||||
|
return fmt.Errorf("failed to write krew manifest: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: filename,
|
||||||
|
Path: yamlPath,
|
||||||
|
Type: artifact.KrewPluginManifest,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
krewConfigExtra: krew,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func templateFields(ctx *context.Context, krew config.Krew) (config.Krew, error) {
|
||||||
|
t := tmpl.New(ctx)
|
||||||
|
var err error
|
||||||
|
krew.Name, err = t.Apply(krew.Name)
|
||||||
|
if err != nil {
|
||||||
|
return config.Krew{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
krew.Homepage, err = t.Apply(krew.Homepage)
|
||||||
|
if err != nil {
|
||||||
|
return config.Krew{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
krew.Description, err = t.Apply(krew.Description)
|
||||||
|
if err != nil {
|
||||||
|
return config.Krew{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
krew.Caveats, err = t.Apply(krew.Caveats)
|
||||||
|
if err != nil {
|
||||||
|
return config.Krew{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
krew.ShortDescription, err = t.Apply(krew.ShortDescription)
|
||||||
|
if err != nil {
|
||||||
|
return config.Krew{}, err
|
||||||
|
}
|
||||||
|
return krew, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildmanifest(ctx *context.Context, krew config.Krew, client client.Client, artifacts []*artifact.Artifact) (string, error) {
|
||||||
|
data, err := manifestFor(ctx, krew, client, artifacts)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return doBuildManifest(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func doBuildManifest(data Manifest) (string, error) {
|
||||||
|
out, err := yaml.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("krew: failed to marshal yaml: %w", err)
|
||||||
|
}
|
||||||
|
return string(out), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func manifestFor(ctx *context.Context, cfg config.Krew, cl client.Client, artifacts []*artifact.Artifact) (Manifest, error) {
|
||||||
|
result := Manifest{
|
||||||
|
APIVersion: apiVersion,
|
||||||
|
Kind: kind,
|
||||||
|
Metadata: Metadata{
|
||||||
|
Name: cfg.Name,
|
||||||
|
},
|
||||||
|
Spec: Spec{
|
||||||
|
Homepage: cfg.Homepage,
|
||||||
|
Version: "v" + ctx.Version,
|
||||||
|
ShortDescription: cfg.ShortDescription,
|
||||||
|
Description: cfg.Description,
|
||||||
|
Caveats: cfg.Caveats,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, art := range artifacts {
|
||||||
|
sum, err := art.Checksum("sha256")
|
||||||
|
if err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.URLTemplate == "" {
|
||||||
|
url, err := cl.ReleaseURLTemplate(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
cfg.URLTemplate = url
|
||||||
|
}
|
||||||
|
url, err := tmpl.New(ctx).WithArtifact(art, map[string]string{}).Apply(cfg.URLTemplate)
|
||||||
|
if err != nil {
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
|
||||||
|
goarch := []string{art.Goarch}
|
||||||
|
if art.Goarch == "all" {
|
||||||
|
goarch = []string{"amd64", "arm64"}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, arch := range goarch {
|
||||||
|
bins := art.ExtraOr(artifact.ExtraBinaries, []string{}).([]string)
|
||||||
|
if len(bins) != 1 {
|
||||||
|
return result, fmt.Errorf("krew: only one binary per archive allowed, got %d on %q", len(bins), art.Name)
|
||||||
|
}
|
||||||
|
result.Spec.Platforms = append(result.Spec.Platforms, Platform{
|
||||||
|
Bin: bins[0],
|
||||||
|
URI: url,
|
||||||
|
Sha256: sum,
|
||||||
|
Selector: Selector{
|
||||||
|
MatchLabels: MatchLabels{
|
||||||
|
Os: art.Goos,
|
||||||
|
Arch: arch,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(result.Spec.Platforms, func(i, j int) bool {
|
||||||
|
return result.Spec.Platforms[i].URI > result.Spec.Platforms[j].URI
|
||||||
|
})
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Publish krew manifest.
|
||||||
|
func (Pipe) Publish(ctx *context.Context) error {
|
||||||
|
cli, err := client.New(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return publishAll(ctx, cli)
|
||||||
|
}
|
||||||
|
|
||||||
|
func publishAll(ctx *context.Context, cli client.Client) error {
|
||||||
|
skips := pipe.SkipMemento{}
|
||||||
|
for _, manifest := range ctx.Artifacts.Filter(artifact.ByType(artifact.KrewPluginManifest)).List() {
|
||||||
|
err := doPublish(ctx, manifest, cli)
|
||||||
|
if err != nil && pipe.IsSkip(err) {
|
||||||
|
skips.Remember(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return skips.Evaluate()
|
||||||
|
}
|
||||||
|
|
||||||
|
func doPublish(ctx *context.Context, manifest *artifact.Artifact, cl client.Client) error {
|
||||||
|
cfg := manifest.Extra[krewConfigExtra].(config.Krew)
|
||||||
|
var err error
|
||||||
|
cl, err = client.NewIfToken(ctx, cl, cfg.Index.Token)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(cfg.SkipUpload) == "true" {
|
||||||
|
return pipe.Skip("krews.skip_upload is set")
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(cfg.SkipUpload) == "auto" && ctx.Semver.Prerelease != "" {
|
||||||
|
return pipe.Skip("prerelease detected with 'auto' upload, skipping krew publish")
|
||||||
|
}
|
||||||
|
|
||||||
|
repo := client.RepoFromRef(cfg.Index)
|
||||||
|
|
||||||
|
gpath := buildManifestPath(manifestsFolder, manifest.Name)
|
||||||
|
log.WithField("manifest", gpath).
|
||||||
|
WithField("repo", repo.String()).
|
||||||
|
Info("pushing")
|
||||||
|
|
||||||
|
msg, err := tmpl.New(ctx).Apply(cfg.CommitMessageTemplate)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := os.ReadFile(manifest.Path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return cl.CreateFile(ctx, cfg.CommitAuthor, repo, content, gpath, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildManifestPath(folder, filename string) string {
|
||||||
|
return path.Join(folder, filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Manifest struct {
|
||||||
|
APIVersion string `yaml:"apiVersion,omitempty"`
|
||||||
|
Kind string `yaml:"kind,omitempty"`
|
||||||
|
Metadata Metadata `yaml:"metadata,omitempty"`
|
||||||
|
Spec Spec `yaml:"spec,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Metadata struct {
|
||||||
|
Name string `yaml:"name,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type MatchLabels struct {
|
||||||
|
Os string `yaml:"os,omitempty"`
|
||||||
|
Arch string `yaml:"arch,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Selector struct {
|
||||||
|
MatchLabels MatchLabels `yaml:"matchLabels,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Platform struct {
|
||||||
|
Bin string `yaml:"bin,omitempty"`
|
||||||
|
URI string `yaml:"uri,omitempty"`
|
||||||
|
Sha256 string `yaml:"sha256,omitempty"`
|
||||||
|
Selector Selector `yaml:"selector,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Spec struct {
|
||||||
|
Version string `yaml:"version,omitempty"`
|
||||||
|
Platforms []Platform `yaml:"platforms,omitempty"`
|
||||||
|
ShortDescription string `yaml:"shortDescription,omitempty"`
|
||||||
|
Homepage string `yaml:"homepage,omitempty"`
|
||||||
|
Caveats string `yaml:"caveats,omitempty"`
|
||||||
|
Description string `yaml:"description,omitempty"`
|
||||||
|
}
|
||||||
846
internal/pipe/krew/krew_test.go
Normal file
846
internal/pipe/krew/krew_test.go
Normal file
@@ -0,0 +1,846 @@
|
|||||||
|
package krew
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||||
|
"github.com/goreleaser/goreleaser/internal/client"
|
||||||
|
"github.com/goreleaser/goreleaser/internal/golden"
|
||||||
|
"github.com/goreleaser/goreleaser/internal/testlib"
|
||||||
|
"github.com/goreleaser/goreleaser/pkg/config"
|
||||||
|
"github.com/goreleaser/goreleaser/pkg/context"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDescription(t *testing.T) {
|
||||||
|
require.NotEmpty(t, Pipe{}.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func createTemplateData() Manifest {
|
||||||
|
return Manifest{
|
||||||
|
APIVersion: apiVersion,
|
||||||
|
Kind: kind,
|
||||||
|
Metadata: Metadata{
|
||||||
|
Name: "Test",
|
||||||
|
},
|
||||||
|
Spec: Spec{
|
||||||
|
Description: "Some desc",
|
||||||
|
Homepage: "https://google.com",
|
||||||
|
Version: "v0.1.3",
|
||||||
|
ShortDescription: "Short desc",
|
||||||
|
Caveats: "some caveat",
|
||||||
|
Platforms: []Platform{
|
||||||
|
{
|
||||||
|
Selector: Selector{
|
||||||
|
MatchLabels: MatchLabels{
|
||||||
|
Arch: "amd64",
|
||||||
|
Os: "darwin",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
URI: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz",
|
||||||
|
Sha256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68",
|
||||||
|
Bin: "test",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Selector: Selector{
|
||||||
|
MatchLabels: MatchLabels{
|
||||||
|
Arch: "arm64",
|
||||||
|
Os: "darwin",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
URI: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_arm64.tar.gz",
|
||||||
|
Sha256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68",
|
||||||
|
Bin: "test",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Selector: Selector{
|
||||||
|
MatchLabels: MatchLabels{
|
||||||
|
Arch: "amd64",
|
||||||
|
Os: "linux",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
URI: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz",
|
||||||
|
Sha256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
|
||||||
|
Bin: "test",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Selector: Selector{
|
||||||
|
MatchLabels: MatchLabels{
|
||||||
|
Arch: "arm",
|
||||||
|
Os: "linux",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
URI: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz",
|
||||||
|
Sha256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
|
||||||
|
Bin: "test",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Selector: Selector{
|
||||||
|
MatchLabels: MatchLabels{
|
||||||
|
Arch: "arm64",
|
||||||
|
Os: "linux",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
URI: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz",
|
||||||
|
Sha256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
|
||||||
|
Bin: "test",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Selector: Selector{
|
||||||
|
MatchLabels: MatchLabels{
|
||||||
|
Arch: "amd64",
|
||||||
|
Os: "windows",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
URI: "https://github.com/caarlos0/test/releases/download/v0.1.3/test_windows_amd64.zip",
|
||||||
|
Sha256: "1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67",
|
||||||
|
Bin: "test.exe",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFullManifest(t *testing.T) {
|
||||||
|
data := createTemplateData()
|
||||||
|
data.Metadata.Name = manifestName(t)
|
||||||
|
manifest, err := doBuildManifest(data)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
golden.RequireEqualNakedYaml(t, []byte(manifest))
|
||||||
|
requireValidManifest(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSimple(t *testing.T) {
|
||||||
|
data := createTemplateData()
|
||||||
|
data.Metadata.Name = manifestName(t)
|
||||||
|
manifest, err := doBuildManifest(data)
|
||||||
|
require.NoError(t, err)
|
||||||
|
golden.RequireEqualNakedYaml(t, []byte(manifest))
|
||||||
|
requireValidManifest(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFullPipe(t *testing.T) {
|
||||||
|
type testcase struct {
|
||||||
|
prepare func(ctx *context.Context)
|
||||||
|
expectedRunError string
|
||||||
|
expectedPublishError string
|
||||||
|
}
|
||||||
|
for name, tt := range map[string]testcase{
|
||||||
|
"default": {
|
||||||
|
prepare: func(ctx *context.Context) {
|
||||||
|
ctx.TokenType = context.TokenTypeGitHub
|
||||||
|
ctx.Config.Krews[0].Index.Owner = "test"
|
||||||
|
ctx.Config.Krews[0].Index.Name = "test"
|
||||||
|
ctx.Config.Krews[0].Homepage = "https://github.com/goreleaser"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"default_gitlab": {
|
||||||
|
prepare: func(ctx *context.Context) {
|
||||||
|
ctx.TokenType = context.TokenTypeGitLab
|
||||||
|
ctx.Config.Krews[0].Index.Owner = "test"
|
||||||
|
ctx.Config.Krews[0].Index.Name = "test"
|
||||||
|
ctx.Config.Krews[0].Homepage = "https://gitlab.com/goreleaser"
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"invalid_commit_template": {
|
||||||
|
prepare: func(ctx *context.Context) {
|
||||||
|
ctx.Config.Krews[0].Index.Owner = "test"
|
||||||
|
ctx.Config.Krews[0].Index.Name = "test"
|
||||||
|
ctx.Config.Krews[0].CommitMessageTemplate = "{{ .Asdsa }"
|
||||||
|
},
|
||||||
|
expectedPublishError: `template: tmpl:1: unexpected "}" in operand`,
|
||||||
|
},
|
||||||
|
"invalid desc": {
|
||||||
|
prepare: func(ctx *context.Context) {
|
||||||
|
ctx.Config.Krews[0].Index.Owner = "test"
|
||||||
|
ctx.Config.Krews[0].Index.Name = "test"
|
||||||
|
ctx.Config.Krews[0].Description = "{{ .Asdsa }"
|
||||||
|
},
|
||||||
|
expectedRunError: `template: tmpl:1: unexpected "}" in operand`,
|
||||||
|
},
|
||||||
|
"invalid short desc": {
|
||||||
|
prepare: func(ctx *context.Context) {
|
||||||
|
ctx.Config.Krews[0].Index.Owner = "test"
|
||||||
|
ctx.Config.Krews[0].Index.Name = "test"
|
||||||
|
ctx.Config.Krews[0].ShortDescription = "{{ .Asdsa }"
|
||||||
|
},
|
||||||
|
expectedRunError: `template: tmpl:1: unexpected "}" in operand`,
|
||||||
|
},
|
||||||
|
"invalid homepage": {
|
||||||
|
prepare: func(ctx *context.Context) {
|
||||||
|
ctx.Config.Krews[0].Index.Owner = "test"
|
||||||
|
ctx.Config.Krews[0].Index.Name = "test"
|
||||||
|
ctx.Config.Krews[0].Homepage = "{{ .Asdsa }"
|
||||||
|
},
|
||||||
|
expectedRunError: `template: tmpl:1: unexpected "}" in operand`,
|
||||||
|
},
|
||||||
|
"invalid name": {
|
||||||
|
prepare: func(ctx *context.Context) {
|
||||||
|
ctx.Config.Krews[0].Index.Owner = "test"
|
||||||
|
ctx.Config.Krews[0].Index.Name = "test"
|
||||||
|
ctx.Config.Krews[0].Name = "{{ .Asdsa }"
|
||||||
|
},
|
||||||
|
expectedRunError: `template: tmpl:1: unexpected "}" in operand`,
|
||||||
|
},
|
||||||
|
"invalid caveats": {
|
||||||
|
prepare: func(ctx *context.Context) {
|
||||||
|
ctx.Config.Krews[0].Index.Owner = "test"
|
||||||
|
ctx.Config.Krews[0].Index.Name = "test"
|
||||||
|
ctx.Config.Krews[0].Caveats = "{{ .Asdsa }"
|
||||||
|
},
|
||||||
|
expectedRunError: `template: tmpl:1: unexpected "}" in operand`,
|
||||||
|
},
|
||||||
|
"no short desc": {
|
||||||
|
prepare: func(ctx *context.Context) {
|
||||||
|
ctx.Config.Krews[0].Index.Owner = "test"
|
||||||
|
ctx.Config.Krews[0].Index.Name = "test"
|
||||||
|
ctx.Config.Krews[0].Description = "lalala"
|
||||||
|
ctx.Config.Krews[0].ShortDescription = ""
|
||||||
|
},
|
||||||
|
expectedRunError: `krew: manifest short description is not set`,
|
||||||
|
},
|
||||||
|
"no desc": {
|
||||||
|
prepare: func(ctx *context.Context) {
|
||||||
|
ctx.Config.Krews[0].Index.Owner = "test"
|
||||||
|
ctx.Config.Krews[0].Index.Name = "test"
|
||||||
|
ctx.Config.Krews[0].Description = ""
|
||||||
|
ctx.Config.Krews[0].ShortDescription = "lalala"
|
||||||
|
},
|
||||||
|
expectedRunError: `krew: manifest description is not set`,
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
folder := t.TempDir()
|
||||||
|
ctx := &context.Context{
|
||||||
|
Git: context.GitInfo{
|
||||||
|
CurrentTag: "v1.0.1",
|
||||||
|
},
|
||||||
|
Version: "1.0.1",
|
||||||
|
Artifacts: artifact.New(),
|
||||||
|
Env: map[string]string{
|
||||||
|
"FOO": "foo_is_bar",
|
||||||
|
"BAR": "honk",
|
||||||
|
},
|
||||||
|
Config: config.Project{
|
||||||
|
Dist: folder,
|
||||||
|
ProjectName: name,
|
||||||
|
Krews: []config.Krew{
|
||||||
|
{
|
||||||
|
Name: name,
|
||||||
|
IDs: []string{"foo"},
|
||||||
|
Description: "A run pipe test krew manifest and FOO={{ .Env.FOO }}",
|
||||||
|
ShortDescription: "short desc {{.Env.BAR}}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
tt.prepare(ctx)
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "bar_bin.tar.gz",
|
||||||
|
Path: "doesnt matter",
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "amd64",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "bar",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
path := filepath.Join(folder, "bin.tar.gz")
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "bin.tar.gz",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "amd64",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "foo",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"name"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
f, err := os.Create(path)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, f.Close())
|
||||||
|
client := client.NewMock()
|
||||||
|
distFile := filepath.Join(folder, name+".yaml")
|
||||||
|
|
||||||
|
err = runAll(ctx, client)
|
||||||
|
if tt.expectedRunError != "" {
|
||||||
|
require.EqualError(t, err, tt.expectedRunError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
err = publishAll(ctx, client)
|
||||||
|
if tt.expectedPublishError != "" {
|
||||||
|
require.EqualError(t, err, tt.expectedPublishError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, client.CreatedFile)
|
||||||
|
golden.RequireEqualNakedYaml(t, []byte(client.Content))
|
||||||
|
requireValidManifest(t)
|
||||||
|
|
||||||
|
distBts, err := os.ReadFile(distFile)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, client.Content, string(distBts))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunPipeUniversalBinary(t *testing.T) {
|
||||||
|
folder := t.TempDir()
|
||||||
|
ctx := &context.Context{
|
||||||
|
Git: context.GitInfo{
|
||||||
|
CurrentTag: "v1.0.1",
|
||||||
|
},
|
||||||
|
Version: "1.0.1",
|
||||||
|
Artifacts: artifact.New(),
|
||||||
|
Config: config.Project{
|
||||||
|
Dist: folder,
|
||||||
|
ProjectName: "unibin",
|
||||||
|
Krews: []config.Krew{
|
||||||
|
{
|
||||||
|
Name: manifestName(t),
|
||||||
|
Description: "Some desc",
|
||||||
|
ShortDescription: "Short desc",
|
||||||
|
Index: config.RepoRef{
|
||||||
|
Owner: "unibin",
|
||||||
|
Name: "bar",
|
||||||
|
},
|
||||||
|
IDs: []string{
|
||||||
|
"unibin",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
path := filepath.Join(folder, "bin.tar.gz")
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "unibin.tar.gz",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "all",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "unibin",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"unibin"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
f, err := os.Create(path)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, f.Close())
|
||||||
|
client := client.NewMock()
|
||||||
|
distFile := filepath.Join(folder, manifestName(t)+".yaml")
|
||||||
|
|
||||||
|
require.NoError(t, runAll(ctx, client))
|
||||||
|
require.NoError(t, publishAll(ctx, client))
|
||||||
|
require.True(t, client.CreatedFile)
|
||||||
|
golden.RequireEqualNakedYaml(t, []byte(client.Content))
|
||||||
|
requireValidManifest(t)
|
||||||
|
distBts, err := os.ReadFile(distFile)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, client.Content, string(distBts))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunPipeNameTemplate(t *testing.T) {
|
||||||
|
folder := t.TempDir()
|
||||||
|
ctx := &context.Context{
|
||||||
|
Git: context.GitInfo{
|
||||||
|
CurrentTag: "v1.0.1",
|
||||||
|
},
|
||||||
|
Version: "1.0.1",
|
||||||
|
Artifacts: artifact.New(),
|
||||||
|
Env: map[string]string{
|
||||||
|
"FOO_BAR": t.Name(),
|
||||||
|
},
|
||||||
|
Config: config.Project{
|
||||||
|
Dist: folder,
|
||||||
|
ProjectName: "foo",
|
||||||
|
Krews: []config.Krew{
|
||||||
|
{
|
||||||
|
Name: "{{ .Env.FOO_BAR }}",
|
||||||
|
Description: "Some desc",
|
||||||
|
ShortDescription: "Short desc",
|
||||||
|
Index: config.RepoRef{
|
||||||
|
Owner: "foo",
|
||||||
|
Name: "bar",
|
||||||
|
},
|
||||||
|
IDs: []string{
|
||||||
|
"foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
path := filepath.Join(folder, "bin.tar.gz")
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "bin.tar.gz",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "amd64",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "foo",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"foo"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
f, err := os.Create(path)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, f.Close())
|
||||||
|
client := client.NewMock()
|
||||||
|
distFile := filepath.Join(folder, t.Name()+".yaml")
|
||||||
|
|
||||||
|
require.NoError(t, runAll(ctx, client))
|
||||||
|
require.NoError(t, publishAll(ctx, client))
|
||||||
|
require.True(t, client.CreatedFile)
|
||||||
|
golden.RequireEqualNakedYaml(t, []byte(client.Content))
|
||||||
|
requireValidManifest(t)
|
||||||
|
distBts, err := os.ReadFile(distFile)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, client.Content, string(distBts))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunPipeMultipleKrewWithSkip(t *testing.T) {
|
||||||
|
folder := t.TempDir()
|
||||||
|
ctx := &context.Context{
|
||||||
|
Git: context.GitInfo{
|
||||||
|
CurrentTag: "v1.0.1",
|
||||||
|
},
|
||||||
|
Version: "1.0.1",
|
||||||
|
Artifacts: artifact.New(),
|
||||||
|
Env: map[string]string{
|
||||||
|
"FOO_BAR": "is_bar",
|
||||||
|
},
|
||||||
|
Config: config.Project{
|
||||||
|
Dist: folder,
|
||||||
|
ProjectName: "foo",
|
||||||
|
Krews: []config.Krew{
|
||||||
|
{
|
||||||
|
Name: "foo",
|
||||||
|
Description: "Some desc",
|
||||||
|
ShortDescription: "Short desc",
|
||||||
|
Index: config.RepoRef{
|
||||||
|
Owner: "foo",
|
||||||
|
Name: "bar",
|
||||||
|
},
|
||||||
|
IDs: []string{
|
||||||
|
"foo",
|
||||||
|
},
|
||||||
|
SkipUpload: "true",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "bar",
|
||||||
|
Description: "Some desc",
|
||||||
|
ShortDescription: "Short desc",
|
||||||
|
Index: config.RepoRef{
|
||||||
|
Owner: "foo",
|
||||||
|
Name: "bar",
|
||||||
|
},
|
||||||
|
IDs: []string{
|
||||||
|
"foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "foobar",
|
||||||
|
Description: "Some desc",
|
||||||
|
ShortDescription: "Short desc",
|
||||||
|
Index: config.RepoRef{
|
||||||
|
Owner: "foo",
|
||||||
|
Name: "bar",
|
||||||
|
},
|
||||||
|
IDs: []string{
|
||||||
|
"foo",
|
||||||
|
},
|
||||||
|
SkipUpload: "true",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
path := filepath.Join(folder, "bin.tar.gz")
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "bin.tar.gz",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "amd64",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "foo",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"foo"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
f, err := os.Create(path)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, f.Close())
|
||||||
|
|
||||||
|
cli := client.NewMock()
|
||||||
|
require.NoError(t, runAll(ctx, cli))
|
||||||
|
require.EqualError(t, publishAll(ctx, cli), `krews.skip_upload is set`)
|
||||||
|
require.True(t, cli.CreatedFile)
|
||||||
|
|
||||||
|
for _, manifest := range ctx.Config.Krews {
|
||||||
|
distFile := filepath.Join(folder, manifest.Name+".yaml")
|
||||||
|
_, err := os.Stat(distFile)
|
||||||
|
require.NoError(t, err, "file should exist: "+distFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunPipeForMultipleArmVersions(t *testing.T) {
|
||||||
|
for name, fn := range map[string]func(ctx *context.Context){
|
||||||
|
"multiple_armv5": func(ctx *context.Context) {
|
||||||
|
ctx.Config.Krews[0].Goarm = "5"
|
||||||
|
},
|
||||||
|
"multiple_armv6": func(ctx *context.Context) {
|
||||||
|
ctx.Config.Krews[0].Goarm = "6"
|
||||||
|
},
|
||||||
|
"multiple_armv7": func(ctx *context.Context) {
|
||||||
|
ctx.Config.Krews[0].Goarm = "7"
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
folder := t.TempDir()
|
||||||
|
ctx := &context.Context{
|
||||||
|
TokenType: context.TokenTypeGitHub,
|
||||||
|
Git: context.GitInfo{
|
||||||
|
CurrentTag: "v1.0.1",
|
||||||
|
},
|
||||||
|
Version: "1.0.1",
|
||||||
|
Artifacts: artifact.New(),
|
||||||
|
Env: map[string]string{
|
||||||
|
"FOO": "foo_is_bar",
|
||||||
|
},
|
||||||
|
Config: config.Project{
|
||||||
|
Dist: folder,
|
||||||
|
ProjectName: name,
|
||||||
|
Krews: []config.Krew{
|
||||||
|
{
|
||||||
|
Name: name,
|
||||||
|
ShortDescription: "Short desc",
|
||||||
|
Description: "A run pipe test krew manifest and FOO={{ .Env.FOO }}",
|
||||||
|
Index: config.RepoRef{
|
||||||
|
Owner: "test",
|
||||||
|
Name: "test",
|
||||||
|
},
|
||||||
|
Homepage: "https://github.com/goreleaser",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
GitHubURLs: config.GitHubURLs{
|
||||||
|
Download: "https://github.com",
|
||||||
|
},
|
||||||
|
Release: config.Release{
|
||||||
|
GitHub: config.Repo{
|
||||||
|
Owner: "test",
|
||||||
|
Name: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
fn(ctx)
|
||||||
|
for _, a := range []struct {
|
||||||
|
name string
|
||||||
|
goos string
|
||||||
|
goarch string
|
||||||
|
goarm string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "bin",
|
||||||
|
goos: "darwin",
|
||||||
|
goarch: "amd64",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "arm64",
|
||||||
|
goos: "linux",
|
||||||
|
goarch: "arm64",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "armv5",
|
||||||
|
goos: "linux",
|
||||||
|
goarch: "arm",
|
||||||
|
goarm: "5",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "armv6",
|
||||||
|
goos: "linux",
|
||||||
|
goarch: "arm",
|
||||||
|
goarm: "6",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "armv7",
|
||||||
|
goos: "linux",
|
||||||
|
goarch: "arm",
|
||||||
|
goarm: "7",
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
path := filepath.Join(folder, fmt.Sprintf("%s.tar.gz", a.name))
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: fmt.Sprintf("%s.tar.gz", a.name),
|
||||||
|
Path: path,
|
||||||
|
Goos: a.goos,
|
||||||
|
Goarch: a.goarch,
|
||||||
|
Goarm: a.goarm,
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: a.name,
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"foo"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
f, err := os.Create(path)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, f.Close())
|
||||||
|
}
|
||||||
|
|
||||||
|
client := client.NewMock()
|
||||||
|
distFile := filepath.Join(folder, name+".yaml")
|
||||||
|
|
||||||
|
require.NoError(t, runAll(ctx, client))
|
||||||
|
require.NoError(t, publishAll(ctx, client))
|
||||||
|
require.True(t, client.CreatedFile)
|
||||||
|
golden.RequireEqualNakedYaml(t, []byte(client.Content))
|
||||||
|
requireValidManifest(t)
|
||||||
|
|
||||||
|
distBts, err := os.ReadFile(distFile)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, client.Content, string(distBts))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunPipeNoBuilds(t *testing.T) {
|
||||||
|
ctx := &context.Context{
|
||||||
|
TokenType: context.TokenTypeGitHub,
|
||||||
|
Config: config.Project{
|
||||||
|
Krews: []config.Krew{
|
||||||
|
{
|
||||||
|
Name: manifestName(t),
|
||||||
|
Description: "Some desc",
|
||||||
|
ShortDescription: "Short desc",
|
||||||
|
Index: config.RepoRef{
|
||||||
|
Owner: "test",
|
||||||
|
Name: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
client := client.NewMock()
|
||||||
|
require.Equal(t, ErrNoArchivesFound, runAll(ctx, client))
|
||||||
|
require.False(t, client.CreatedFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunPipeNoUpload(t *testing.T) {
|
||||||
|
folder := t.TempDir()
|
||||||
|
ctx := context.New(config.Project{
|
||||||
|
Dist: folder,
|
||||||
|
ProjectName: "foo",
|
||||||
|
Release: config.Release{},
|
||||||
|
Krews: []config.Krew{
|
||||||
|
{
|
||||||
|
Name: manifestName(t),
|
||||||
|
Description: "Some desc",
|
||||||
|
ShortDescription: "Short desc",
|
||||||
|
Index: config.RepoRef{
|
||||||
|
Owner: "test",
|
||||||
|
Name: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
ctx.TokenType = context.TokenTypeGitHub
|
||||||
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
|
||||||
|
path := filepath.Join(folder, "whatever.tar.gz")
|
||||||
|
f, err := os.Create(path)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, f.Close())
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "bin",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "amd64",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "foo",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"foo"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
client := client.NewMock()
|
||||||
|
|
||||||
|
assertNoPublish := func(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
|
require.NoError(t, runAll(ctx, client))
|
||||||
|
testlib.AssertSkipped(t, publishAll(ctx, client))
|
||||||
|
require.False(t, client.CreatedFile)
|
||||||
|
}
|
||||||
|
t.Run("skip upload true", func(t *testing.T) {
|
||||||
|
ctx.Config.Krews[0].SkipUpload = "true"
|
||||||
|
ctx.Semver.Prerelease = ""
|
||||||
|
assertNoPublish(t)
|
||||||
|
})
|
||||||
|
t.Run("skip upload auto", func(t *testing.T) {
|
||||||
|
ctx.Config.Krews[0].SkipUpload = "auto"
|
||||||
|
ctx.Semver.Prerelease = "beta1"
|
||||||
|
assertNoPublish(t)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunEmptyTokenType(t *testing.T) {
|
||||||
|
folder := t.TempDir()
|
||||||
|
ctx := context.New(config.Project{
|
||||||
|
Dist: folder,
|
||||||
|
ProjectName: "foo",
|
||||||
|
Release: config.Release{},
|
||||||
|
Krews: []config.Krew{
|
||||||
|
{
|
||||||
|
Name: manifestName(t),
|
||||||
|
Description: "Some desc",
|
||||||
|
ShortDescription: "Short desc",
|
||||||
|
Index: config.RepoRef{
|
||||||
|
Owner: "test",
|
||||||
|
Name: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
|
||||||
|
path := filepath.Join(folder, "whatever.tar.gz")
|
||||||
|
f, err := os.Create(path)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, f.Close())
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "bin",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "amd64",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "foo",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"bin"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
client := client.NewMock()
|
||||||
|
require.NoError(t, runAll(ctx, client))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunMultipleBinaries(t *testing.T) {
|
||||||
|
folder := t.TempDir()
|
||||||
|
ctx := context.New(config.Project{
|
||||||
|
Dist: folder,
|
||||||
|
ProjectName: "foo",
|
||||||
|
Release: config.Release{},
|
||||||
|
Krews: []config.Krew{
|
||||||
|
{
|
||||||
|
Name: manifestName(t),
|
||||||
|
Description: "Some desc",
|
||||||
|
ShortDescription: "Short desc",
|
||||||
|
Index: config.RepoRef{
|
||||||
|
Owner: "test",
|
||||||
|
Name: "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
ctx.Git = context.GitInfo{CurrentTag: "v1.0.1"}
|
||||||
|
path := filepath.Join(folder, "whatever.tar.gz")
|
||||||
|
f, err := os.Create(path)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, f.Close())
|
||||||
|
ctx.Artifacts.Add(&artifact.Artifact{
|
||||||
|
Name: "bin.tar.gz",
|
||||||
|
Path: path,
|
||||||
|
Goos: "darwin",
|
||||||
|
Goarch: "amd64",
|
||||||
|
Type: artifact.UploadableArchive,
|
||||||
|
Extra: map[string]interface{}{
|
||||||
|
artifact.ExtraID: "foo",
|
||||||
|
artifact.ExtraFormat: "tar.gz",
|
||||||
|
artifact.ExtraBinaries: []string{"bin1", "bin2"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
client := client.NewMock()
|
||||||
|
require.EqualError(t, runAll(ctx, client), `krew: only one binary per archive allowed, got 2 on "bin.tar.gz"`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDefault(t *testing.T) {
|
||||||
|
testlib.Mktmp(t)
|
||||||
|
|
||||||
|
ctx := &context.Context{
|
||||||
|
TokenType: context.TokenTypeGitHub,
|
||||||
|
Config: config.Project{
|
||||||
|
ProjectName: "myproject",
|
||||||
|
Krews: []config.Krew{
|
||||||
|
{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
require.NoError(t, Pipe{}.Default(ctx))
|
||||||
|
require.Equal(t, ctx.Config.ProjectName, ctx.Config.Krews[0].Name)
|
||||||
|
require.NotEmpty(t, ctx.Config.Krews[0].CommitAuthor.Name)
|
||||||
|
require.NotEmpty(t, ctx.Config.Krews[0].CommitAuthor.Email)
|
||||||
|
require.NotEmpty(t, ctx.Config.Krews[0].CommitMessageTemplate)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGHFolder(t *testing.T) {
|
||||||
|
require.Equal(t, "bar.yaml", buildManifestPath("", "bar.yaml"))
|
||||||
|
require.Equal(t, "fooo/bar.yaml", buildManifestPath("fooo", "bar.yaml"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSkip(t *testing.T) {
|
||||||
|
t.Run("skip", func(t *testing.T) {
|
||||||
|
require.True(t, Pipe{}.Skip(context.New(config.Project{})))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("dont skip", func(t *testing.T) {
|
||||||
|
ctx := context.New(config.Project{
|
||||||
|
Krews: []config.Krew{
|
||||||
|
{},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.False(t, Pipe{}.Skip(ctx))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunSkipNoName(t *testing.T) {
|
||||||
|
ctx := context.New(config.Project{
|
||||||
|
Krews: []config.Krew{{}},
|
||||||
|
})
|
||||||
|
|
||||||
|
client := client.NewMock()
|
||||||
|
testlib.AssertSkipped(t, runAll(ctx, client))
|
||||||
|
}
|
||||||
|
|
||||||
|
func manifestName(tb testing.TB) string {
|
||||||
|
tb.Helper()
|
||||||
|
return path.Base(tb.Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
func requireValidManifest(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
|
t.Run("valid", func(t *testing.T) {
|
||||||
|
// needs to be the one on https://github.com/kubernetes-sigs/krew/pull/736
|
||||||
|
testlib.CheckPath(t, "validate-krew-manifest")
|
||||||
|
out, err := exec.Command(
|
||||||
|
"validate-krew-manifest",
|
||||||
|
"-skip-install",
|
||||||
|
"-manifest=testdata/"+strings.TrimSuffix(t.Name(), "/valid")+".yaml",
|
||||||
|
).CombinedOutput()
|
||||||
|
require.NoError(t, err, string(out))
|
||||||
|
})
|
||||||
|
}
|
||||||
53
internal/pipe/krew/testdata/TestFullManifest.yaml
vendored
Normal file
53
internal/pipe/krew/testdata/TestFullManifest.yaml
vendored
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
apiVersion: krew.googlecontainertools.github.com/v1alpha2
|
||||||
|
kind: Plugin
|
||||||
|
metadata:
|
||||||
|
name: TestFullManifest
|
||||||
|
spec:
|
||||||
|
version: v0.1.3
|
||||||
|
platforms:
|
||||||
|
- bin: test
|
||||||
|
uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz
|
||||||
|
sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: darwin
|
||||||
|
arch: amd64
|
||||||
|
- bin: test
|
||||||
|
uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_arm64.tar.gz
|
||||||
|
sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: darwin
|
||||||
|
arch: arm64
|
||||||
|
- bin: test
|
||||||
|
uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz
|
||||||
|
sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: linux
|
||||||
|
arch: amd64
|
||||||
|
- bin: test
|
||||||
|
uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz
|
||||||
|
sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: linux
|
||||||
|
arch: arm
|
||||||
|
- bin: test
|
||||||
|
uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz
|
||||||
|
sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: linux
|
||||||
|
arch: arm64
|
||||||
|
- bin: test.exe
|
||||||
|
uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_windows_amd64.zip
|
||||||
|
sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: windows
|
||||||
|
arch: amd64
|
||||||
|
shortDescription: Short desc
|
||||||
|
homepage: https://google.com
|
||||||
|
caveats: some caveat
|
||||||
|
description: Some desc
|
||||||
17
internal/pipe/krew/testdata/TestFullPipe/default.yaml
vendored
Normal file
17
internal/pipe/krew/testdata/TestFullPipe/default.yaml
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
apiVersion: krew.googlecontainertools.github.com/v1alpha2
|
||||||
|
kind: Plugin
|
||||||
|
metadata:
|
||||||
|
name: default
|
||||||
|
spec:
|
||||||
|
version: v1.0.1
|
||||||
|
platforms:
|
||||||
|
- bin: name
|
||||||
|
uri: https://dummyhost/download/v1.0.1/bin.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: darwin
|
||||||
|
arch: amd64
|
||||||
|
shortDescription: short desc honk
|
||||||
|
homepage: https://github.com/goreleaser
|
||||||
|
description: A run pipe test krew manifest and FOO=foo_is_bar
|
||||||
17
internal/pipe/krew/testdata/TestFullPipe/default_gitlab.yaml
vendored
Normal file
17
internal/pipe/krew/testdata/TestFullPipe/default_gitlab.yaml
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
apiVersion: krew.googlecontainertools.github.com/v1alpha2
|
||||||
|
kind: Plugin
|
||||||
|
metadata:
|
||||||
|
name: default_gitlab
|
||||||
|
spec:
|
||||||
|
version: v1.0.1
|
||||||
|
platforms:
|
||||||
|
- bin: name
|
||||||
|
uri: https://dummyhost/download/v1.0.1/bin.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: darwin
|
||||||
|
arch: amd64
|
||||||
|
shortDescription: short desc honk
|
||||||
|
homepage: https://gitlab.com/goreleaser
|
||||||
|
description: A run pipe test krew manifest and FOO=foo_is_bar
|
||||||
31
internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv5.yaml
vendored
Normal file
31
internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv5.yaml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
apiVersion: krew.googlecontainertools.github.com/v1alpha2
|
||||||
|
kind: Plugin
|
||||||
|
metadata:
|
||||||
|
name: multiple_armv5
|
||||||
|
spec:
|
||||||
|
version: v1.0.1
|
||||||
|
platforms:
|
||||||
|
- bin: foo
|
||||||
|
uri: https://dummyhost/download/v1.0.1/bin.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: darwin
|
||||||
|
arch: amd64
|
||||||
|
- bin: foo
|
||||||
|
uri: https://dummyhost/download/v1.0.1/armv5.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: linux
|
||||||
|
arch: arm
|
||||||
|
- bin: foo
|
||||||
|
uri: https://dummyhost/download/v1.0.1/arm64.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: linux
|
||||||
|
arch: arm64
|
||||||
|
shortDescription: Short desc
|
||||||
|
homepage: https://github.com/goreleaser
|
||||||
|
description: A run pipe test krew manifest and FOO=foo_is_bar
|
||||||
31
internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv6.yaml
vendored
Normal file
31
internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv6.yaml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
apiVersion: krew.googlecontainertools.github.com/v1alpha2
|
||||||
|
kind: Plugin
|
||||||
|
metadata:
|
||||||
|
name: multiple_armv6
|
||||||
|
spec:
|
||||||
|
version: v1.0.1
|
||||||
|
platforms:
|
||||||
|
- bin: foo
|
||||||
|
uri: https://dummyhost/download/v1.0.1/bin.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: darwin
|
||||||
|
arch: amd64
|
||||||
|
- bin: foo
|
||||||
|
uri: https://dummyhost/download/v1.0.1/armv6.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: linux
|
||||||
|
arch: arm
|
||||||
|
- bin: foo
|
||||||
|
uri: https://dummyhost/download/v1.0.1/arm64.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: linux
|
||||||
|
arch: arm64
|
||||||
|
shortDescription: Short desc
|
||||||
|
homepage: https://github.com/goreleaser
|
||||||
|
description: A run pipe test krew manifest and FOO=foo_is_bar
|
||||||
31
internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv7.yaml
vendored
Normal file
31
internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv7.yaml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
apiVersion: krew.googlecontainertools.github.com/v1alpha2
|
||||||
|
kind: Plugin
|
||||||
|
metadata:
|
||||||
|
name: multiple_armv7
|
||||||
|
spec:
|
||||||
|
version: v1.0.1
|
||||||
|
platforms:
|
||||||
|
- bin: foo
|
||||||
|
uri: https://dummyhost/download/v1.0.1/bin.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: darwin
|
||||||
|
arch: amd64
|
||||||
|
- bin: foo
|
||||||
|
uri: https://dummyhost/download/v1.0.1/armv7.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: linux
|
||||||
|
arch: arm
|
||||||
|
- bin: foo
|
||||||
|
uri: https://dummyhost/download/v1.0.1/arm64.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: linux
|
||||||
|
arch: arm64
|
||||||
|
shortDescription: Short desc
|
||||||
|
homepage: https://github.com/goreleaser
|
||||||
|
description: A run pipe test krew manifest and FOO=foo_is_bar
|
||||||
16
internal/pipe/krew/testdata/TestRunPipeNameTemplate.yaml
vendored
Normal file
16
internal/pipe/krew/testdata/TestRunPipeNameTemplate.yaml
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
apiVersion: krew.googlecontainertools.github.com/v1alpha2
|
||||||
|
kind: Plugin
|
||||||
|
metadata:
|
||||||
|
name: TestRunPipeNameTemplate
|
||||||
|
spec:
|
||||||
|
version: v1.0.1
|
||||||
|
platforms:
|
||||||
|
- bin: foo
|
||||||
|
uri: https://dummyhost/download/v1.0.1/bin.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: darwin
|
||||||
|
arch: amd64
|
||||||
|
shortDescription: Short desc
|
||||||
|
description: Some desc
|
||||||
23
internal/pipe/krew/testdata/TestRunPipeUniversalBinary.yaml
vendored
Normal file
23
internal/pipe/krew/testdata/TestRunPipeUniversalBinary.yaml
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
apiVersion: krew.googlecontainertools.github.com/v1alpha2
|
||||||
|
kind: Plugin
|
||||||
|
metadata:
|
||||||
|
name: TestRunPipeUniversalBinary
|
||||||
|
spec:
|
||||||
|
version: v1.0.1
|
||||||
|
platforms:
|
||||||
|
- bin: unibin
|
||||||
|
uri: https://dummyhost/download/v1.0.1/unibin.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: darwin
|
||||||
|
arch: amd64
|
||||||
|
- bin: unibin
|
||||||
|
uri: https://dummyhost/download/v1.0.1/unibin.tar.gz
|
||||||
|
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: darwin
|
||||||
|
arch: arm64
|
||||||
|
shortDescription: Short desc
|
||||||
|
description: Some desc
|
||||||
53
internal/pipe/krew/testdata/TestSimple.yaml
vendored
Normal file
53
internal/pipe/krew/testdata/TestSimple.yaml
vendored
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
apiVersion: krew.googlecontainertools.github.com/v1alpha2
|
||||||
|
kind: Plugin
|
||||||
|
metadata:
|
||||||
|
name: TestSimple
|
||||||
|
spec:
|
||||||
|
version: v0.1.3
|
||||||
|
platforms:
|
||||||
|
- bin: test
|
||||||
|
uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz
|
||||||
|
sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: darwin
|
||||||
|
arch: amd64
|
||||||
|
- bin: test
|
||||||
|
uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_arm64.tar.gz
|
||||||
|
sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: darwin
|
||||||
|
arch: arm64
|
||||||
|
- bin: test
|
||||||
|
uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz
|
||||||
|
sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: linux
|
||||||
|
arch: amd64
|
||||||
|
- bin: test
|
||||||
|
uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz
|
||||||
|
sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: linux
|
||||||
|
arch: arm
|
||||||
|
- bin: test
|
||||||
|
uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz
|
||||||
|
sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: linux
|
||||||
|
arch: arm64
|
||||||
|
- bin: test.exe
|
||||||
|
uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_windows_amd64.zip
|
||||||
|
sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
os: windows
|
||||||
|
arch: amd64
|
||||||
|
shortDescription: Short desc
|
||||||
|
homepage: https://google.com
|
||||||
|
caveats: some caveat
|
||||||
|
description: Some desc
|
||||||
@@ -4,8 +4,6 @@ package publish
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/gofish"
|
|
||||||
|
|
||||||
"github.com/goreleaser/goreleaser/internal/middleware/errhandler"
|
"github.com/goreleaser/goreleaser/internal/middleware/errhandler"
|
||||||
"github.com/goreleaser/goreleaser/internal/middleware/logging"
|
"github.com/goreleaser/goreleaser/internal/middleware/logging"
|
||||||
"github.com/goreleaser/goreleaser/internal/middleware/skip"
|
"github.com/goreleaser/goreleaser/internal/middleware/skip"
|
||||||
@@ -14,6 +12,8 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/pipe/brew"
|
"github.com/goreleaser/goreleaser/internal/pipe/brew"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/custompublishers"
|
"github.com/goreleaser/goreleaser/internal/pipe/custompublishers"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/docker"
|
"github.com/goreleaser/goreleaser/internal/pipe/docker"
|
||||||
|
"github.com/goreleaser/goreleaser/internal/pipe/gofish"
|
||||||
|
"github.com/goreleaser/goreleaser/internal/pipe/krew"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/milestone"
|
"github.com/goreleaser/goreleaser/internal/pipe/milestone"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/release"
|
"github.com/goreleaser/goreleaser/internal/pipe/release"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/scoop"
|
"github.com/goreleaser/goreleaser/internal/pipe/scoop"
|
||||||
@@ -46,6 +46,7 @@ var publishers = []Publisher{
|
|||||||
// brew and scoop use the release URL, so, they should be last
|
// brew and scoop use the release URL, so, they should be last
|
||||||
brew.Pipe{},
|
brew.Pipe{},
|
||||||
gofish.Pipe{},
|
gofish.Pipe{},
|
||||||
|
krew.Pipe{},
|
||||||
scoop.Pipe{},
|
scoop.Pipe{},
|
||||||
milestone.Pipe{},
|
milestone.Pipe{},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/pipe/git"
|
"github.com/goreleaser/goreleaser/internal/pipe/git"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/gofish"
|
"github.com/goreleaser/goreleaser/internal/pipe/gofish"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/gomod"
|
"github.com/goreleaser/goreleaser/internal/pipe/gomod"
|
||||||
|
"github.com/goreleaser/goreleaser/internal/pipe/krew"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/nfpm"
|
"github.com/goreleaser/goreleaser/internal/pipe/nfpm"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/publish"
|
"github.com/goreleaser/goreleaser/internal/pipe/publish"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/scoop"
|
"github.com/goreleaser/goreleaser/internal/pipe/scoop"
|
||||||
@@ -67,6 +68,7 @@ var Pipeline = append(
|
|||||||
snapcraft.Pipe{}, // archive via snapcraft (snap)
|
snapcraft.Pipe{}, // archive via snapcraft (snap)
|
||||||
brew.Pipe{}, // create brew tap
|
brew.Pipe{}, // create brew tap
|
||||||
gofish.Pipe{}, // create gofish rig
|
gofish.Pipe{}, // create gofish rig
|
||||||
|
krew.Pipe{}, // krew plugins
|
||||||
scoop.Pipe{}, // create scoop buckets
|
scoop.Pipe{}, // create scoop buckets
|
||||||
checksums.Pipe{}, // checksums of the files
|
checksums.Pipe{}, // checksums of the files
|
||||||
sign.Pipe{}, // sign artifacts
|
sign.Pipe{}, // sign artifacts
|
||||||
|
|||||||
@@ -147,6 +147,22 @@ type Homebrew struct {
|
|||||||
Goarm string `yaml:"goarm,omitempty"`
|
Goarm string `yaml:"goarm,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Krew contains the krew section.
|
||||||
|
type Krew struct {
|
||||||
|
IDs []string `yaml:"ids,omitempty"`
|
||||||
|
Name string `yaml:"name,omitempty"`
|
||||||
|
Index RepoRef `yaml:"index,omitempty"`
|
||||||
|
CommitAuthor CommitAuthor `yaml:"commit_author,omitempty"`
|
||||||
|
CommitMessageTemplate string `yaml:"commit_msg_template,omitempty"`
|
||||||
|
Caveats string `yaml:"caveats,omitempty"`
|
||||||
|
ShortDescription string `yaml:"short_description,omitempty"`
|
||||||
|
Description string `yaml:"description,omitempty"`
|
||||||
|
Homepage string `yaml:"homepage,omitempty"`
|
||||||
|
URLTemplate string `yaml:"url_template,omitempty"`
|
||||||
|
Goarm string `yaml:"goarm,omitempty"`
|
||||||
|
SkipUpload string `yaml:"skip_upload,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
// Scoop contains the scoop.sh section.
|
// Scoop contains the scoop.sh section.
|
||||||
type Scoop struct {
|
type Scoop struct {
|
||||||
Name string `yaml:"name,omitempty"`
|
Name string `yaml:"name,omitempty"`
|
||||||
@@ -770,6 +786,7 @@ type Project struct {
|
|||||||
Milestones []Milestone `yaml:"milestones,omitempty"`
|
Milestones []Milestone `yaml:"milestones,omitempty"`
|
||||||
Brews []Homebrew `yaml:"brews,omitempty"`
|
Brews []Homebrew `yaml:"brews,omitempty"`
|
||||||
Rigs []GoFish `yaml:"rigs,omitempty"`
|
Rigs []GoFish `yaml:"rigs,omitempty"`
|
||||||
|
Krews []Krew `yaml:"krews,omitempty"`
|
||||||
Scoop Scoop `yaml:"scoop,omitempty"`
|
Scoop Scoop `yaml:"scoop,omitempty"`
|
||||||
Builds []Build `yaml:"builds,omitempty"`
|
Builds []Build `yaml:"builds,omitempty"`
|
||||||
Archives []Archive `yaml:"archives,omitempty"`
|
Archives []Archive `yaml:"archives,omitempty"`
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/pipe/docker"
|
"github.com/goreleaser/goreleaser/internal/pipe/docker"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/gofish"
|
"github.com/goreleaser/goreleaser/internal/pipe/gofish"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/gomod"
|
"github.com/goreleaser/goreleaser/internal/pipe/gomod"
|
||||||
|
"github.com/goreleaser/goreleaser/internal/pipe/krew"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/linkedin"
|
"github.com/goreleaser/goreleaser/internal/pipe/linkedin"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/mattermost"
|
"github.com/goreleaser/goreleaser/internal/pipe/mattermost"
|
||||||
"github.com/goreleaser/goreleaser/internal/pipe/milestone"
|
"github.com/goreleaser/goreleaser/internal/pipe/milestone"
|
||||||
@@ -66,6 +67,7 @@ var Defaulters = []Defaulter{
|
|||||||
artifactory.Pipe{},
|
artifactory.Pipe{},
|
||||||
blob.Pipe{},
|
blob.Pipe{},
|
||||||
brew.Pipe{},
|
brew.Pipe{},
|
||||||
|
krew.Pipe{},
|
||||||
gofish.Pipe{},
|
gofish.Pipe{},
|
||||||
scoop.Pipe{},
|
scoop.Pipe{},
|
||||||
discord.Pipe{},
|
discord.Pipe{},
|
||||||
|
|||||||
@@ -10,11 +10,6 @@ and the
|
|||||||
[Fish food cookbook](https://gofi.sh/#cookbook)
|
[Fish food cookbook](https://gofi.sh/#cookbook)
|
||||||
for more details.
|
for more details.
|
||||||
|
|
||||||
!!! warning
|
|
||||||
If you have multiple 32-bit arm versions in each `build` section, and
|
|
||||||
you do not specify any `ids` in the rigs section, it will default to all
|
|
||||||
artifacts and GoReleaser will fail.
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# .goreleaser.yml
|
# .goreleaser.yml
|
||||||
rigs:
|
rigs:
|
||||||
@@ -119,3 +114,7 @@ food = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
|
||||||
|
- Only one `GOARM` build is allowed;
|
||||||
|
|||||||
@@ -10,11 +10,6 @@ and the
|
|||||||
[formula cookbook](https://github.com/Homebrew/brew/blob/master/docs/Formula-Cookbook.md)
|
[formula cookbook](https://github.com/Homebrew/brew/blob/master/docs/Formula-Cookbook.md)
|
||||||
for more details.
|
for more details.
|
||||||
|
|
||||||
!!! warning
|
|
||||||
If you have multiple 32-bit arm versions in each `build` section, and
|
|
||||||
you do not specify any `ids` in the brew section, it will default to all
|
|
||||||
artifacts and GoReleaser will fail.
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# .goreleaser.yml
|
# .goreleaser.yml
|
||||||
brews:
|
brews:
|
||||||
@@ -201,3 +196,7 @@ from one software to another.
|
|||||||
|
|
||||||
Our suggestion is to create a `my-app-head.rb` file on your tap following
|
Our suggestion is to create a `my-app-head.rb` file on your tap following
|
||||||
[homebrew's documentation](https://docs.brew.sh/Formula-Cookbook#unstable-versions-head).
|
[homebrew's documentation](https://docs.brew.sh/Formula-Cookbook#unstable-versions-head).
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
|
||||||
|
- Only one `GOARM` build is allowed;
|
||||||
|
|||||||
95
www/docs/customization/krew.md
Normal file
95
www/docs/customization/krew.md
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
# Krew Plugin Manifests
|
||||||
|
|
||||||
|
After releasing to GitHub or GitLab, GoReleaser can generate and publish a _Krew Plugin Manifest_ into a repository that you have access to.
|
||||||
|
|
||||||
|
Check their [website](https://krew.sigs.k8s.io) for more information.
|
||||||
|
|
||||||
|
The `krews` section specifies how the plugins should be created:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# .goreleaser.yml
|
||||||
|
krews:
|
||||||
|
-
|
||||||
|
# Name template of the recipe
|
||||||
|
# Default to project name
|
||||||
|
name: myproject
|
||||||
|
|
||||||
|
# IDs of the archives to use.
|
||||||
|
# Defaults to all.
|
||||||
|
ids:
|
||||||
|
- foo
|
||||||
|
- bar
|
||||||
|
|
||||||
|
# GOARM to specify which 32-bit arm version to use if there are multiple versions
|
||||||
|
# from the build section. Krew plugin supports at this moment only one 32-bit version.
|
||||||
|
# Default is 6 for all artifacts or each id if there a multiple versions.
|
||||||
|
goarm: 6
|
||||||
|
|
||||||
|
# NOTE: make sure the url_template, the token and given repo (github or gitlab) owner and name are from the
|
||||||
|
# same kind. We will probably unify this in the next major version like it is done with scoop.
|
||||||
|
|
||||||
|
# GitHub/GitLab repository to push the Krew plugin to
|
||||||
|
# Gitea is not supported yet, but the support coming
|
||||||
|
index:
|
||||||
|
owner: repo-owner
|
||||||
|
name: krew-plugins
|
||||||
|
# Optionally a branch can be provided. If the branch does not exist, it
|
||||||
|
# will be created. If no branch is listed, the default branch will be used
|
||||||
|
branch: main
|
||||||
|
# Optionally a token can be provided, if it differs from the token provided to GoReleaser
|
||||||
|
token: "{{ .Env.KREW_GITHUB_TOKEN }}"
|
||||||
|
|
||||||
|
# Template for the url which is determined by the given Token (github or gitlab)
|
||||||
|
# Default for github is "https://github.com/<repo_owner>/<repo_name>/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
|
||||||
|
# Default for gitlab is "https://gitlab.com/<repo_owner>/<repo_name>/-/releases/{{ .Tag }}/downloads/{{ .ArtifactName }}"
|
||||||
|
# Default for gitea is "https://gitea.com/<repo_owner>/<repo_name>/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
|
||||||
|
url_template: "http://github.mycompany.com/foo/bar/releases/{{ .Tag }}/{{ .ArtifactName }}"
|
||||||
|
|
||||||
|
# Git author used to commit to the repository.
|
||||||
|
# Defaults are shown.
|
||||||
|
commit_author:
|
||||||
|
name: goreleaserbot
|
||||||
|
email: goreleaser@carlosbecker.com
|
||||||
|
|
||||||
|
# The project name and current git tag are used in the format string.
|
||||||
|
commit_msg_template: "Krew plugin update for {{ .ProjectName }} version {{ .Tag }}"
|
||||||
|
|
||||||
|
# Your app's homepage.
|
||||||
|
# Default is empty.
|
||||||
|
homepage: "https://example.com/"
|
||||||
|
|
||||||
|
# Template of your app's description.
|
||||||
|
# The usual guideline for this is to wrap the line at 80 chars.
|
||||||
|
#
|
||||||
|
# Default is empty.
|
||||||
|
description: "Software to create fast and easy drum rolls."
|
||||||
|
|
||||||
|
# Template of your app's short description.
|
||||||
|
# The usual guideline for this is to be at most 50 chars long.
|
||||||
|
#
|
||||||
|
# Default is empty.
|
||||||
|
short_description: "Software to create fast and easy drum rolls."
|
||||||
|
|
||||||
|
# Caveats for the user of your binary.
|
||||||
|
# The usual guideline for this is to wrap the line at 80 chars.
|
||||||
|
#
|
||||||
|
# Default is empty.
|
||||||
|
caveats: "How to use this binary"
|
||||||
|
|
||||||
|
# Setting this will prevent goreleaser to actually try to commit the updated
|
||||||
|
# krew plugin - instead, the plugin file will be stored on the dist folder only,
|
||||||
|
# leaving the responsibility of publishing it to the user.
|
||||||
|
# If set to auto, the release will not be uploaded to the Krew plugin
|
||||||
|
# in case there is an indicator for prerelease in the tag e.g. v1.0.0-rc1
|
||||||
|
# Default is false.
|
||||||
|
skip_upload: true
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! tip
|
||||||
|
Learn more about the [name template engine](/customization/templates/).
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
|
||||||
|
- Only one binary per archive is allowed;
|
||||||
|
- Binary releases (when `archives.format` is set to `binary`) are not allowed;
|
||||||
|
- Only one `GOARM` build is allowed;
|
||||||
@@ -94,17 +94,18 @@ nav:
|
|||||||
- Checksums and artifacts: customization/sign.md
|
- Checksums and artifacts: customization/sign.md
|
||||||
- Docker Images and Manifests: customization/docker_sign.md
|
- Docker Images and Manifests: customization/docker_sign.md
|
||||||
- Publish:
|
- Publish:
|
||||||
|
- customization/release.md
|
||||||
- customization/blob.md
|
- customization/blob.md
|
||||||
- customization/fury.md
|
- customization/fury.md
|
||||||
- customization/homebrew.md
|
- customization/homebrew.md
|
||||||
- customization/gofish.md
|
- customization/gofish.md
|
||||||
|
- customization/krew.md
|
||||||
- customization/scoop.md
|
- customization/scoop.md
|
||||||
- customization/changelog.md
|
- customization/changelog.md
|
||||||
- customization/release.md
|
|
||||||
- customization/artifactory.md
|
|
||||||
- customization/publishers.md
|
|
||||||
- customization/upload.md
|
- customization/upload.md
|
||||||
- customization/source.md
|
- customization/source.md
|
||||||
|
- customization/publishers.md
|
||||||
|
- customization/artifactory.md
|
||||||
- customization/milestone.md
|
- customization/milestone.md
|
||||||
- customization/snapshots.md
|
- customization/snapshots.md
|
||||||
- customization/nightly.md
|
- customization/nightly.md
|
||||||
|
|||||||
Reference in New Issue
Block a user