mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-02-07 13:31:37 +02:00
feat: allow to pr krew plugin manifests (#3915)
following up on #3903 Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
01b14f9b7a
commit
5805c5d608
@ -328,7 +328,22 @@ func doPublish(ctx *context.Context, manifest *artifact.Artifact, cl client.Clie
|
||||
return err
|
||||
}
|
||||
|
||||
return cl.CreateFile(ctx, author, repo, content, gpath, msg)
|
||||
if !cfg.Index.PullRequest.Enabled {
|
||||
return cl.CreateFile(ctx, author, repo, content, gpath, msg)
|
||||
}
|
||||
|
||||
log.Info("brews.pull_request enabled, creating a PR")
|
||||
pcl, ok := cl.(client.PullRequestOpener)
|
||||
if !ok {
|
||||
return fmt.Errorf("client does not support pull requests")
|
||||
}
|
||||
|
||||
if err := cl.CreateFile(ctx, author, repo, content, gpath, msg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
title := fmt.Sprintf("Updated %s to %s", ctx.Config.ProjectName, ctx.Version)
|
||||
return pcl.OpenPullRequest(ctx, repo, cfg.Index.PullRequest.Base, title)
|
||||
}
|
||||
|
||||
func buildManifestPath(folder, filename string) string {
|
||||
|
@ -310,6 +310,59 @@ func TestFullPipe(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunPipePullRequest(t *testing.T) {
|
||||
folder := t.TempDir()
|
||||
ctx := testctx.NewWithCfg(
|
||||
config.Project{
|
||||
Dist: folder,
|
||||
ProjectName: "foo",
|
||||
Krews: []config.Krew{
|
||||
{
|
||||
Name: "foo",
|
||||
Homepage: "https://goreleaser.com",
|
||||
ShortDescription: "test",
|
||||
Description: "Fake desc",
|
||||
Index: config.RepoRef{
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
Branch: "update-{{.Version}}",
|
||||
PullRequest: config.PullRequest{
|
||||
Enabled: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
testctx.WithVersion("1.2.1"),
|
||||
testctx.WithCurrentTag("v1.2.1"),
|
||||
)
|
||||
path := filepath.Join(folder, "dist/foo_darwin_all/foo")
|
||||
ctx.Artifacts.Add(&artifact.Artifact{
|
||||
Name: "foo_macos.tar.gz",
|
||||
Path: path,
|
||||
Goos: "darwin",
|
||||
Goarch: "all",
|
||||
Type: artifact.UploadableArchive,
|
||||
Extra: map[string]interface{}{
|
||||
artifact.ExtraID: "foo",
|
||||
artifact.ExtraFormat: "tar.gz",
|
||||
artifact.ExtraBinaries: []string{"foo"},
|
||||
},
|
||||
})
|
||||
|
||||
require.NoError(t, os.MkdirAll(filepath.Dir(path), 0o755))
|
||||
f, err := os.Create(path)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, f.Close())
|
||||
|
||||
client := client.NewMock()
|
||||
require.NoError(t, runAll(ctx, client))
|
||||
require.NoError(t, publishAll(ctx, client))
|
||||
require.True(t, client.CreatedFile)
|
||||
require.True(t, client.OpenedPullRequest)
|
||||
golden.RequireEqualYaml(t, []byte(client.Content))
|
||||
}
|
||||
|
||||
func TestRunPipeUniversalBinary(t *testing.T) {
|
||||
folder := t.TempDir()
|
||||
|
||||
|
24
internal/pipe/krew/testdata/TestRunPipePullRequest.yaml
vendored
Normal file
24
internal/pipe/krew/testdata/TestRunPipePullRequest.yaml
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
apiVersion: krew.googlecontainertools.github.com/v1alpha2
|
||||
kind: Plugin
|
||||
metadata:
|
||||
name: foo
|
||||
spec:
|
||||
version: v1.2.1
|
||||
platforms:
|
||||
- bin: foo
|
||||
uri: https://dummyhost/download/v1.2.1/foo_macos.tar.gz
|
||||
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||
selector:
|
||||
matchLabels:
|
||||
os: darwin
|
||||
arch: amd64
|
||||
- bin: foo
|
||||
uri: https://dummyhost/download/v1.2.1/foo_macos.tar.gz
|
||||
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
|
||||
selector:
|
||||
matchLabels:
|
||||
os: darwin
|
||||
arch: arm64
|
||||
shortDescription: test
|
||||
homepage: https://goreleaser.com
|
||||
description: Fake desc
|
@ -61,6 +61,20 @@ krews:
|
||||
# provided to GoReleaser
|
||||
token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
|
||||
|
||||
# Sets up pull request creation instead of just pushing to the given branch.
|
||||
# Make sure the 'branch' property is different from base before enabling
|
||||
# it.
|
||||
#
|
||||
# Since: v1.17
|
||||
pull_request:
|
||||
# Whether to enable it or not.
|
||||
enabled: true
|
||||
|
||||
# Base branch of the PR.
|
||||
#
|
||||
# Default: default repository branch.
|
||||
base: main
|
||||
|
||||
# URL which is determined by the given Token (github or
|
||||
# gitlab)
|
||||
# Default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user