mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
feat: allow to pr scoop manifests (#3916)
follow up of https://github.com/goreleaser/goreleaser/pull/3903 Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
5805c5d608
commit
282c42164e
@ -174,14 +174,24 @@ func doPublish(ctx *context.Context, cl client.Client) error {
|
||||
scoop.Bucket = ref
|
||||
|
||||
repo := client.RepoFromRef(scoop.Bucket)
|
||||
return cl.CreateFile(
|
||||
ctx,
|
||||
author,
|
||||
repo,
|
||||
content,
|
||||
path.Join(scoop.Folder, manifest.Name),
|
||||
commitMessage,
|
||||
)
|
||||
gpath := path.Join(scoop.Folder, manifest.Name)
|
||||
|
||||
if !scoop.Bucket.PullRequest.Enabled {
|
||||
return cl.CreateFile(ctx, author, repo, content, gpath, commitMessage)
|
||||
}
|
||||
|
||||
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, commitMessage); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
title := fmt.Sprintf("Updated %s to %s", ctx.Config.ProjectName, ctx.Version)
|
||||
return pcl.OpenPullRequest(ctx, repo, scoop.Bucket.PullRequest.Base, title)
|
||||
}
|
||||
|
||||
// Manifest represents a scoop.sh App Manifest.
|
||||
|
@ -510,6 +510,56 @@ func Test_doRun(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunPipePullRequest(t *testing.T) {
|
||||
folder := t.TempDir()
|
||||
ctx := testctx.NewWithCfg(
|
||||
config.Project{
|
||||
Dist: folder,
|
||||
ProjectName: "foo",
|
||||
Scoop: config.Scoop{
|
||||
Name: "foo",
|
||||
Homepage: "https://goreleaser.com",
|
||||
Description: "Fake desc",
|
||||
Bucket: 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_windows_amd64/foo.exe")
|
||||
ctx.Artifacts.Add(&artifact.Artifact{
|
||||
Name: "foo_windows_amd64.tar.gz",
|
||||
Path: path,
|
||||
Goos: "windows",
|
||||
Goarch: "amd64",
|
||||
Type: artifact.UploadableArchive,
|
||||
Extra: map[string]interface{}{
|
||||
artifact.ExtraID: "foo",
|
||||
artifact.ExtraFormat: "tar.gz",
|
||||
artifact.ExtraBinary: "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, doRun(ctx, client))
|
||||
require.NoError(t, doPublish(ctx, client))
|
||||
require.True(t, client.CreatedFile)
|
||||
require.True(t, client.OpenedPullRequest)
|
||||
golden.RequireEqualJSON(t, []byte(client.Content))
|
||||
}
|
||||
|
||||
func Test_buildManifest(t *testing.T) {
|
||||
folder := t.TempDir()
|
||||
file := filepath.Join(folder, "archive")
|
||||
|
12
internal/pipe/scoop/testdata/TestRunPipePullRequest.json.golden
vendored
Normal file
12
internal/pipe/scoop/testdata/TestRunPipePullRequest.json.golden
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": "1.2.1",
|
||||
"architecture": {
|
||||
"64bit": {
|
||||
"url": "https://dummyhost/download/v1.2.1/foo_windows_amd64.tar.gz",
|
||||
"bin": null,
|
||||
"hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
}
|
||||
},
|
||||
"homepage": "https://goreleaser.com",
|
||||
"description": "Fake desc"
|
||||
}
|
@ -40,6 +40,20 @@ scoop:
|
||||
# to GoReleaser
|
||||
token: "{{ .Env.SCOOP_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
|
||||
|
||||
# Folder inside the repository to put the scoop.
|
||||
#
|
||||
# Note that while scoop works if the manifests are in a folder,
|
||||
|
Loading…
x
Reference in New Issue
Block a user