Skip to content

Commit

Permalink
feat: allow to pr scoop manifests (#3916)
Browse files Browse the repository at this point in the history
follow up of #3903

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Apr 7, 2023
1 parent 5805c5d commit 282c421
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 8 deletions.
26 changes: 18 additions & 8 deletions internal/pipe/scoop/scoop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
50 changes: 50 additions & 0 deletions internal/pipe/scoop/scoop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 12 additions & 0 deletions internal/pipe/scoop/testdata/TestRunPipePullRequest.json.golden
Original file line number Diff line number Diff line change
@@ -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"
}
14 changes: 14 additions & 0 deletions www/docs/customization/scoop.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 282c421

Please sign in to comment.