1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-04-23 12:18:50 +02:00

feat: Scoop pipe - Write the manifest before skips, like Brew pipe. (#2241)

* feat: Scoop pipe - Write the manifest before skips, like Brew pipe.

feat: Scoop pipe - Added tests and fixed the write path of the manifest.

* Update scoop.go

Co-authored-by: eolder <eolder@rajant.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Evan Older 2021-05-24 13:30:31 -04:00 committed by GitHub
parent 9913fe7db6
commit d521343b06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 2 deletions

View File

@ -5,6 +5,8 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -106,12 +108,18 @@ func doRun(ctx *context.Context, cl client.Client) error {
return err return err
} }
if ctx.SkipPublish { filename := filepath.Join(ctx.Config.Dist, path)
return pipe.ErrSkipPublishEnabled log.WithField("manifest", filename).Info("writing")
if err := os.WriteFile(filename, content.Bytes(), 0o644); err != nil {
return fmt.Errorf("failed to write scoop manifest: %w", err)
} }
if strings.TrimSpace(scoop.SkipUpload) == "true" { if strings.TrimSpace(scoop.SkipUpload) == "true" {
return pipe.Skip("scoop.skip_upload is true") return pipe.Skip("scoop.skip_upload is true")
} }
if ctx.SkipPublish {
return pipe.ErrSkipPublishEnabled
}
if strings.TrimSpace(scoop.SkipUpload) == "auto" && ctx.Semver.Prerelease != "" { if strings.TrimSpace(scoop.SkipUpload) == "auto" && ctx.Semver.Prerelease != "" {
return pipe.Skip("release is prerelease") return pipe.Skip("release is prerelease")
} }

View File

@ -975,6 +975,60 @@ func Test_buildManifest(t *testing.T) {
} }
} }
func TestRunPipeScoopWithSkip(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{
Archives: []config.Archive{
{Format: "tar.gz"},
},
Builds: []config.Build{
{Binary: "test"},
},
Dist: folder,
ProjectName: "run-pipe",
Scoop: config.Scoop{
Bucket: config.RepoRef{
Owner: "test",
Name: "test",
},
Description: "A run pipe test formula",
Homepage: "https://github.com/goreleaser",
Name: "run-pipe",
SkipUpload: "true",
},
},
}
path := filepath.Join(folder, "bin.tar.gz")
ctx.Artifacts.Add(&artifact.Artifact{
Name: "bin.tar.gz",
Path: path,
Goos: "windows",
Goarch: "amd64",
Type: artifact.UploadableArchive,
Extra: map[string]interface{}{
"ID": "foo",
"Format": "tar.gz",
},
})
f, err := os.Create(path)
require.NoError(t, err)
require.NoError(t, f.Close())
cli := &DummyClient{}
require.EqualError(t, doRun(ctx, cli), `scoop.skip_upload is true`)
distFile := filepath.Join(folder, ctx.Config.Scoop.Name+".json")
_, err = os.Stat(distFile)
require.NoError(t, err, "file should exist: "+distFile)
}
func TestWrapInDirectory(t *testing.T) { func TestWrapInDirectory(t *testing.T) {
folder := t.TempDir() folder := t.TempDir()
file := filepath.Join(folder, "archive") file := filepath.Join(folder, "archive")