mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-04-11 11:42:15 +02:00
refactor: use context on git exec calls (#3032)
This commit is contained in:
parent
9fc502c18a
commit
ce9058ac8c
@ -133,7 +133,7 @@ func setupReleaseContext(ctx *context.Context, options releaseOpts) *context.Con
|
||||
ctx.ReleaseFooterFile = options.releaseFooterFile
|
||||
ctx.ReleaseFooterTmpl = options.releaseFooterTmpl
|
||||
ctx.Snapshot = options.snapshot
|
||||
if options.autoSnapshot && git.CheckDirty() != nil {
|
||||
if options.autoSnapshot && git.CheckDirty(ctx) != nil {
|
||||
log.Info("git repo is dirty and --auto-snapshot is set, implying --snapshot")
|
||||
ctx.Snapshot = true
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
@ -11,11 +12,11 @@ import (
|
||||
)
|
||||
|
||||
// ExtractRepoFromConfig gets the repo name from the Git config.
|
||||
func ExtractRepoFromConfig() (result config.Repo, err error) {
|
||||
if !IsRepo() {
|
||||
func ExtractRepoFromConfig(ctx context.Context) (result config.Repo, err error) {
|
||||
if !IsRepo(ctx) {
|
||||
return result, errors.New("current folder is not a git repository")
|
||||
}
|
||||
out, err := Run("ls-remote", "--get-url")
|
||||
out, err := Run(ctx, "ls-remote", "--get-url")
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("no remote configured to list refs from")
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package git_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/git"
|
||||
@ -10,14 +11,14 @@ import (
|
||||
|
||||
func TestNotARepo(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
_, err := git.ExtractRepoFromConfig()
|
||||
_, err := git.ExtractRepoFromConfig(context.Background())
|
||||
require.EqualError(t, err, `current folder is not a git repository`)
|
||||
}
|
||||
|
||||
func TestNoRemote(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
testlib.GitInit(t)
|
||||
_, err := git.ExtractRepoFromConfig()
|
||||
_, err := git.ExtractRepoFromConfig(context.Background())
|
||||
require.EqualError(t, err, `no remote configured to list refs from`)
|
||||
}
|
||||
|
||||
@ -25,20 +26,21 @@ func TestRepoName(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
testlib.GitInit(t)
|
||||
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
||||
repo, err := git.ExtractRepoFromConfig()
|
||||
repo, err := git.ExtractRepoFromConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "goreleaser/goreleaser", repo.String())
|
||||
}
|
||||
|
||||
func TestRepoNameWithDifferentRemote(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
testlib.Mktmp(t)
|
||||
testlib.GitInit(t)
|
||||
testlib.GitRemoteAddWithName(t, "upstream", "https://github.com/goreleaser/goreleaser.git")
|
||||
_, err := git.Run("pull", "upstream", "main")
|
||||
_, err := git.Run(ctx, "pull", "upstream", "main")
|
||||
require.NoError(t, err)
|
||||
_, err = git.Run("branch", "--set-upstream-to", "upstream/main")
|
||||
_, err = git.Run(ctx, "branch", "--set-upstream-to", "upstream/main")
|
||||
require.NoError(t, err)
|
||||
repo, err := git.ExtractRepoFromConfig()
|
||||
repo, err := git.ExtractRepoFromConfig(ctx)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "goreleaser/goreleaser", repo.String())
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package git
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"os/exec"
|
||||
"strings"
|
||||
@ -11,19 +12,18 @@ import (
|
||||
)
|
||||
|
||||
// IsRepo returns true if current folder is a git repository.
|
||||
func IsRepo() bool {
|
||||
out, err := Run("rev-parse", "--is-inside-work-tree")
|
||||
func IsRepo(ctx context.Context) bool {
|
||||
out, err := Run(ctx, "rev-parse", "--is-inside-work-tree")
|
||||
return err == nil && strings.TrimSpace(out) == "true"
|
||||
}
|
||||
|
||||
func RunWithEnv(env []string, args ...string) (string, error) {
|
||||
// TODO: use exex.CommandContext here and refactor.
|
||||
func RunWithEnv(ctx context.Context, env []string, args ...string) (string, error) {
|
||||
extraArgs := []string{
|
||||
"-c", "log.showSignature=false",
|
||||
}
|
||||
args = append(extraArgs, args...)
|
||||
/* #nosec */
|
||||
cmd := exec.Command("git", args...)
|
||||
cmd := exec.CommandContext(ctx, "git", args...)
|
||||
|
||||
stdout := bytes.Buffer{}
|
||||
stderr := bytes.Buffer{}
|
||||
@ -47,8 +47,8 @@ func RunWithEnv(env []string, args ...string) (string, error) {
|
||||
}
|
||||
|
||||
// Run runs a git command and returns its output or errors.
|
||||
func Run(args ...string) (string, error) {
|
||||
return RunWithEnv([]string{}, args...)
|
||||
func Run(ctx context.Context, args ...string) (string, error) {
|
||||
return RunWithEnv(ctx, []string{}, args...)
|
||||
}
|
||||
|
||||
// Clean the output.
|
||||
|
@ -1,6 +1,7 @@
|
||||
package git_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@ -10,11 +11,12 @@ import (
|
||||
)
|
||||
|
||||
func TestGit(t *testing.T) {
|
||||
out, err := git.Run("status")
|
||||
ctx := context.Background()
|
||||
out, err := git.Run(ctx, "status")
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, out)
|
||||
|
||||
out, err = git.Run("command-that-dont-exist")
|
||||
out, err = git.Run(ctx, "command-that-dont-exist")
|
||||
require.Error(t, err)
|
||||
require.Empty(t, out)
|
||||
require.Equal(
|
||||
@ -25,6 +27,7 @@ func TestGit(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGitWarning(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
testlib.Mktmp(t)
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "foo")
|
||||
@ -34,24 +37,26 @@ func TestGitWarning(t *testing.T) {
|
||||
testlib.GitBranch(t, "tags/1.2.3")
|
||||
testlib.GitTag(t, "1.2.3")
|
||||
|
||||
out, err := git.Run("describe", "--tags", "--abbrev=0", "tags/1.2.3^")
|
||||
out, err := git.Run(ctx, "describe", "--tags", "--abbrev=0", "tags/1.2.3^")
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "1.2.2\n", out)
|
||||
}
|
||||
|
||||
func TestRepo(t *testing.T) {
|
||||
require.True(t, git.IsRepo(), "goreleaser folder should be a git repo")
|
||||
ctx := context.Background()
|
||||
require.True(t, git.IsRepo(ctx), "goreleaser folder should be a git repo")
|
||||
|
||||
require.NoError(t, os.Chdir(os.TempDir()))
|
||||
require.False(t, git.IsRepo(), os.TempDir()+" folder should be a git repo")
|
||||
require.False(t, git.IsRepo(ctx), os.TempDir()+" folder should be a git repo")
|
||||
}
|
||||
|
||||
func TestClean(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
out, err := git.Clean("asdasd 'ssadas'\nadasd", nil)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "asdasd ssadas", out)
|
||||
|
||||
out, err = git.Clean(git.Run("command-that-dont-exist"))
|
||||
out, err = git.Clean(git.Run(ctx, "command-that-dont-exist"))
|
||||
require.Error(t, err)
|
||||
require.Empty(t, out)
|
||||
require.Equal(
|
||||
|
@ -408,13 +408,13 @@ func doPublish(ctx *context.Context, pkgs []*artifact.Artifact) error {
|
||||
|
||||
env := []string{fmt.Sprintf("GIT_SSH_COMMAND=%s", sshcmd)}
|
||||
|
||||
if err := runGitCmds(parent, env, [][]string{
|
||||
if err := runGitCmds(ctx, parent, env, [][]string{
|
||||
{"clone", url, cfg.Name},
|
||||
}); err != nil {
|
||||
return fmt.Errorf("failed to setup local AUR repo: %w", err)
|
||||
}
|
||||
|
||||
if err := runGitCmds(cwd, env, [][]string{
|
||||
if err := runGitCmds(ctx, cwd, env, [][]string{
|
||||
// setup auth et al
|
||||
{"config", "--local", "user.name", author.Name},
|
||||
{"config", "--local", "user.email", author.Email},
|
||||
@ -436,7 +436,7 @@ func doPublish(ctx *context.Context, pkgs []*artifact.Artifact) error {
|
||||
}
|
||||
|
||||
log.WithField("repo", url).WithField("name", cfg.Name).Info("pushing")
|
||||
if err := runGitCmds(cwd, env, [][]string{
|
||||
if err := runGitCmds(ctx, cwd, env, [][]string{
|
||||
{"add", "-A", "."},
|
||||
{"commit", "-m", msg},
|
||||
{"push", "origin", "HEAD"},
|
||||
@ -489,10 +489,10 @@ func keyPath(key string) (string, error) {
|
||||
return path, nil
|
||||
}
|
||||
|
||||
func runGitCmds(cwd string, env []string, cmds [][]string) error {
|
||||
func runGitCmds(ctx *context.Context, cwd string, env []string, cmds [][]string) error {
|
||||
for _, cmd := range cmds {
|
||||
args := append([]string{"-C", cwd}, cmd...)
|
||||
if _, err := git.Clean(git.RunWithEnv(env, args...)); err != nil {
|
||||
if _, err := git.Clean(git.RunWithEnv(ctx, env, args...)); err != nil {
|
||||
return fmt.Errorf("%q failed: %w", strings.Join(cmd, " "), err)
|
||||
}
|
||||
}
|
||||
|
@ -237,36 +237,34 @@ func TestFullPipe(t *testing.T) {
|
||||
key := makeKey(t, keygen.Ed25519)
|
||||
|
||||
folder := t.TempDir()
|
||||
ctx := &context.Context{
|
||||
Git: context.GitInfo{
|
||||
CurrentTag: "v1.0.1-foo",
|
||||
},
|
||||
Semver: context.Semver{
|
||||
Major: 1,
|
||||
Minor: 0,
|
||||
Patch: 1,
|
||||
Prerelease: "foo",
|
||||
},
|
||||
Version: "1.0.1-foo",
|
||||
Artifacts: artifact.New(),
|
||||
Env: map[string]string{
|
||||
"FOO": "foo_is_bar",
|
||||
},
|
||||
Config: config.Project{
|
||||
Dist: folder,
|
||||
ProjectName: name,
|
||||
AURs: []config.AUR{
|
||||
{
|
||||
Name: name,
|
||||
IDs: []string{"foo"},
|
||||
PrivateKey: key,
|
||||
License: "MIT",
|
||||
GitURL: url,
|
||||
Description: "A run pipe test fish food and FOO={{ .Env.FOO }}",
|
||||
},
|
||||
ctx := context.New(config.Project{
|
||||
Dist: folder,
|
||||
ProjectName: name,
|
||||
AURs: []config.AUR{
|
||||
{
|
||||
Name: name,
|
||||
IDs: []string{"foo"},
|
||||
PrivateKey: key,
|
||||
License: "MIT",
|
||||
GitURL: url,
|
||||
Description: "A run pipe test fish food and FOO={{ .Env.FOO }}",
|
||||
},
|
||||
},
|
||||
})
|
||||
ctx.Git = context.GitInfo{
|
||||
CurrentTag: "v1.0.1-foo",
|
||||
}
|
||||
ctx.Semver = context.Semver{
|
||||
Major: 1,
|
||||
Minor: 0,
|
||||
Patch: 1,
|
||||
Prerelease: "foo",
|
||||
}
|
||||
ctx.Version = "1.0.1-foo"
|
||||
ctx.Env = map[string]string{
|
||||
"FOO": "foo_is_bar",
|
||||
}
|
||||
|
||||
tt.prepare(ctx)
|
||||
ctx.Artifacts.Add(&artifact.Artifact{
|
||||
Name: "should-be-ignored.tar.gz",
|
||||
@ -338,45 +336,45 @@ func TestRunPipe(t *testing.T) {
|
||||
key := makeKey(t, keygen.Ed25519)
|
||||
|
||||
folder := t.TempDir()
|
||||
ctx := &context.Context{
|
||||
TokenType: context.TokenTypeGitHub,
|
||||
Git: context.GitInfo{
|
||||
CurrentTag: "v1.0.1",
|
||||
},
|
||||
Semver: context.Semver{
|
||||
Major: 1,
|
||||
Minor: 0,
|
||||
Patch: 1,
|
||||
},
|
||||
Version: "1.0.1",
|
||||
Artifacts: artifact.New(),
|
||||
Env: map[string]string{
|
||||
"FOO": "foo_is_bar",
|
||||
},
|
||||
Config: config.Project{
|
||||
Dist: folder,
|
||||
ProjectName: "foo",
|
||||
AURs: []config.AUR{
|
||||
{
|
||||
License: "MIT",
|
||||
Description: "A run pipe test aur and FOO={{ .Env.FOO }}",
|
||||
Homepage: "https://github.com/goreleaser",
|
||||
IDs: []string{"foo"},
|
||||
GitURL: url,
|
||||
PrivateKey: key,
|
||||
},
|
||||
},
|
||||
GitHubURLs: config.GitHubURLs{
|
||||
Download: "https://github.com",
|
||||
},
|
||||
Release: config.Release{
|
||||
GitHub: config.Repo{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
},
|
||||
ctx := context.New(config.Project{
|
||||
Dist: folder,
|
||||
ProjectName: "foo",
|
||||
AURs: []config.AUR{
|
||||
{
|
||||
License: "MIT",
|
||||
Description: "A run pipe test aur and FOO={{ .Env.FOO }}",
|
||||
Homepage: "https://github.com/goreleaser",
|
||||
IDs: []string{"foo"},
|
||||
GitURL: url,
|
||||
PrivateKey: key,
|
||||
},
|
||||
},
|
||||
GitHubURLs: config.GitHubURLs{
|
||||
Download: "https://github.com",
|
||||
},
|
||||
Release: config.Release{
|
||||
GitHub: config.Repo{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
ctx.Git = context.GitInfo{
|
||||
CurrentTag: "v1.0.1",
|
||||
}
|
||||
ctx.Semver = context.Semver{
|
||||
Major: 1,
|
||||
Minor: 0,
|
||||
Patch: 1,
|
||||
}
|
||||
ctx.Version = "1.0.1"
|
||||
ctx.Artifacts = artifact.New()
|
||||
ctx.Env = map[string]string{
|
||||
"FOO": "foo_is_bar",
|
||||
}
|
||||
|
||||
for _, a := range []struct {
|
||||
name string
|
||||
goos string
|
||||
@ -484,26 +482,24 @@ func TestRunPipeBinaryRelease(t *testing.T) {
|
||||
url := makeBareRepo(t)
|
||||
key := makeKey(t, keygen.Ed25519)
|
||||
folder := t.TempDir()
|
||||
ctx := &context.Context{
|
||||
Git: context.GitInfo{
|
||||
CurrentTag: "v1.2.1",
|
||||
},
|
||||
Semver: context.Semver{
|
||||
Major: 1,
|
||||
Minor: 2,
|
||||
Patch: 1,
|
||||
},
|
||||
Version: "1.2.1",
|
||||
Artifacts: artifact.New(),
|
||||
Config: config.Project{
|
||||
Dist: folder,
|
||||
ProjectName: "foo",
|
||||
AURs: []config.AUR{{
|
||||
GitURL: url,
|
||||
PrivateKey: key,
|
||||
}},
|
||||
},
|
||||
ctx := context.New(config.Project{
|
||||
Dist: folder,
|
||||
ProjectName: "foo",
|
||||
AURs: []config.AUR{{
|
||||
GitURL: url,
|
||||
PrivateKey: key,
|
||||
}},
|
||||
})
|
||||
|
||||
ctx.Git = context.GitInfo{
|
||||
CurrentTag: "v1.2.1",
|
||||
}
|
||||
ctx.Semver = context.Semver{
|
||||
Major: 1,
|
||||
Minor: 2,
|
||||
Patch: 1,
|
||||
}
|
||||
ctx.Version = "1.2.1"
|
||||
|
||||
path := filepath.Join(folder, "dist/foo_linux_amd64/foo")
|
||||
ctx.Artifacts.Add(&artifact.Artifact{
|
||||
@ -780,6 +776,7 @@ func makeBareRepo(tb testing.TB) string {
|
||||
tb.Helper()
|
||||
dir := tb.TempDir()
|
||||
_, err := git.Run(
|
||||
context.New(config.Project{}),
|
||||
"-C", dir,
|
||||
"-c", "init.defaultBranch=master",
|
||||
"init",
|
||||
@ -803,7 +800,7 @@ func makeKey(tb testing.TB, algo keygen.KeyType) string {
|
||||
func requireEqualRepoFiles(tb testing.TB, folder, name, url string) {
|
||||
tb.Helper()
|
||||
dir := tb.TempDir()
|
||||
_, err := git.Run("-C", dir, "clone", url, "repo")
|
||||
_, err := git.Run(context.New(config.Project{}), "-C", dir, "clone", url, "repo")
|
||||
require.NoError(tb, err)
|
||||
|
||||
for reponame, ext := range map[string]string{
|
||||
|
@ -244,7 +244,7 @@ func getChangelog(ctx *context.Context, tag string) (string, error) {
|
||||
prev := ctx.Git.PreviousTag
|
||||
if prev == "" {
|
||||
// get first commit
|
||||
result, err := git.Clean(git.Run("rev-list", "--max-parents=0", "HEAD"))
|
||||
result, err := git.Clean(git.Run(ctx, "rev-list", "--max-parents=0", "HEAD"))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -283,7 +283,7 @@ func newGithubChangeloger(ctx *context.Context) (changeloger, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
repo, err := git.ExtractRepoFromConfig()
|
||||
repo, err := git.ExtractRepoFromConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -301,7 +301,7 @@ func newSCMChangeloger(ctx *context.Context) (changeloger, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
repo, err := git.ExtractRepoFromConfig()
|
||||
repo, err := git.ExtractRepoFromConfig(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -348,14 +348,14 @@ type gitChangeloger struct{}
|
||||
|
||||
var validSHA1 = regexp.MustCompile(`^[a-fA-F0-9]{40}$`)
|
||||
|
||||
func (g gitChangeloger) Log(_ *context.Context, prev, current string) (string, error) {
|
||||
func (g gitChangeloger) Log(ctx *context.Context, prev, current string) (string, error) {
|
||||
args := []string{"log", "--pretty=oneline", "--abbrev-commit", "--no-decorate", "--no-color"}
|
||||
if validSHA1.MatchString(prev) {
|
||||
args = append(args, prev, current)
|
||||
} else {
|
||||
args = append(args, fmt.Sprintf("tags/%s..tags/%s", prev, current))
|
||||
}
|
||||
return git.Run(args...)
|
||||
return git.Run(ctx, args...)
|
||||
}
|
||||
|
||||
type scmChangeloger struct {
|
||||
|
@ -18,10 +18,8 @@ func TestFillBasicData(t *testing.T) {
|
||||
testlib.GitInit(t)
|
||||
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
||||
|
||||
ctx := &context.Context{
|
||||
TokenType: context.TokenTypeGitHub,
|
||||
Config: config.Project{},
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
require.Equal(t, "goreleaser", ctx.Config.Release.GitHub.Owner)
|
||||
@ -47,51 +45,49 @@ func TestFillPartial(t *testing.T) {
|
||||
testlib.GitInit(t)
|
||||
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
||||
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{
|
||||
GitHubURLs: config.GitHubURLs{
|
||||
Download: "https://github.company.com",
|
||||
ctx := context.New(config.Project{
|
||||
GitHubURLs: config.GitHubURLs{
|
||||
Download: "https://github.company.com",
|
||||
},
|
||||
Dist: "disttt",
|
||||
Release: config.Release{
|
||||
GitHub: config.Repo{
|
||||
Owner: "goreleaser",
|
||||
Name: "test",
|
||||
},
|
||||
Dist: "disttt",
|
||||
Release: config.Release{
|
||||
GitHub: config.Repo{
|
||||
Owner: "goreleaser",
|
||||
Name: "test",
|
||||
},
|
||||
},
|
||||
Archives: []config.Archive{
|
||||
{
|
||||
Files: []config.File{
|
||||
{Source: "glob/*"},
|
||||
},
|
||||
},
|
||||
},
|
||||
Builds: []config.Build{
|
||||
{
|
||||
ID: "build1",
|
||||
Binary: "testreleaser",
|
||||
},
|
||||
{Goos: []string{"linux"}},
|
||||
{
|
||||
ID: "build3",
|
||||
Binary: "another",
|
||||
Ignore: []config.IgnoredBuild{
|
||||
{Goos: "darwin", Goarch: "amd64"},
|
||||
},
|
||||
},
|
||||
},
|
||||
Dockers: []config.Docker{
|
||||
{
|
||||
ImageTemplates: []string{"a/b"},
|
||||
},
|
||||
},
|
||||
Brews: []config.Homebrew{
|
||||
{
|
||||
Description: "foo",
|
||||
},
|
||||
Archives: []config.Archive{
|
||||
{
|
||||
Files: []config.File{
|
||||
{Source: "glob/*"},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
Builds: []config.Build{
|
||||
{
|
||||
ID: "build1",
|
||||
Binary: "testreleaser",
|
||||
},
|
||||
{Goos: []string{"linux"}},
|
||||
{
|
||||
ID: "build3",
|
||||
Binary: "another",
|
||||
Ignore: []config.IgnoredBuild{
|
||||
{Goos: "darwin", Goarch: "amd64"},
|
||||
},
|
||||
},
|
||||
},
|
||||
Dockers: []config.Docker{
|
||||
{
|
||||
ImageTemplates: []string{"a/b"},
|
||||
},
|
||||
},
|
||||
Brews: []config.Homebrew{
|
||||
{
|
||||
Description: "foo",
|
||||
},
|
||||
},
|
||||
})
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
require.Len(t, ctx.Config.Archives[0].Files, 1)
|
||||
require.NotEmpty(t, ctx.Config.Dockers[0].Goos)
|
||||
@ -101,15 +97,13 @@ func TestFillPartial(t *testing.T) {
|
||||
require.Equal(t, "disttt", ctx.Config.Dist)
|
||||
require.NotEqual(t, "https://github.com", ctx.Config.GitHubURLs.Download)
|
||||
|
||||
ctx = &context.Context{
|
||||
TokenType: context.TokenTypeGitea,
|
||||
|
||||
Config: config.Project{
|
||||
GiteaURLs: config.GiteaURLs{
|
||||
API: "https://gitea.com/api/v1",
|
||||
},
|
||||
ctx = context.New(config.Project{
|
||||
GiteaURLs: config.GiteaURLs{
|
||||
API: "https://gitea.com/api/v1",
|
||||
},
|
||||
}
|
||||
})
|
||||
ctx.TokenType = context.TokenTypeGitea
|
||||
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
require.Equal(t, "https://gitea.com", ctx.Config.GiteaURLs.Download)
|
||||
}
|
||||
@ -141,16 +135,15 @@ func TestGiteaTemplateDownloadURL(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
ctx := &context.Context{
|
||||
TokenType: context.TokenTypeGitea,
|
||||
Env: context.Env{
|
||||
"GORELEASER_TEST_GITEA_URLS_API": "https://gitea.com/api/v1",
|
||||
},
|
||||
Config: config.Project{
|
||||
GiteaURLs: config.GiteaURLs{
|
||||
API: tt.apiURL,
|
||||
},
|
||||
ctx := context.New(config.Project{
|
||||
GiteaURLs: config.GiteaURLs{
|
||||
API: tt.apiURL,
|
||||
},
|
||||
})
|
||||
|
||||
ctx.TokenType = context.TokenTypeGitea
|
||||
ctx.Env = context.Env{
|
||||
"GORELEASER_TEST_GITEA_URLS_API": "https://gitea.com/api/v1",
|
||||
}
|
||||
|
||||
err := Pipe{}.Run(ctx)
|
||||
|
@ -49,14 +49,14 @@ var fakeInfo = context.GitInfo{
|
||||
}
|
||||
|
||||
func getInfo(ctx *context.Context) (context.GitInfo, error) {
|
||||
if !git.IsRepo() && ctx.Snapshot {
|
||||
if !git.IsRepo(ctx) && ctx.Snapshot {
|
||||
log.Warn("accepting to run without a git repo because this is a snapshot")
|
||||
return fakeInfo, nil
|
||||
}
|
||||
if !git.IsRepo() {
|
||||
if !git.IsRepo(ctx) {
|
||||
return context.GitInfo{}, ErrNotRepository
|
||||
}
|
||||
info, err := getGitInfo()
|
||||
info, err := getGitInfo(ctx)
|
||||
if err != nil && ctx.Snapshot {
|
||||
log.WithError(err).Warn("ignoring errors because this is a snapshot")
|
||||
if info.Commit == "" {
|
||||
@ -67,28 +67,28 @@ func getInfo(ctx *context.Context) (context.GitInfo, error) {
|
||||
return info, err
|
||||
}
|
||||
|
||||
func getGitInfo() (context.GitInfo, error) {
|
||||
branch, err := getBranch()
|
||||
func getGitInfo(ctx *context.Context) (context.GitInfo, error) {
|
||||
branch, err := getBranch(ctx)
|
||||
if err != nil {
|
||||
return context.GitInfo{}, fmt.Errorf("couldn't get current branch: %w", err)
|
||||
}
|
||||
short, err := getShortCommit()
|
||||
short, err := getShortCommit(ctx)
|
||||
if err != nil {
|
||||
return context.GitInfo{}, fmt.Errorf("couldn't get current commit: %w", err)
|
||||
}
|
||||
full, err := getFullCommit()
|
||||
full, err := getFullCommit(ctx)
|
||||
if err != nil {
|
||||
return context.GitInfo{}, fmt.Errorf("couldn't get current commit: %w", err)
|
||||
}
|
||||
date, err := getCommitDate()
|
||||
date, err := getCommitDate(ctx)
|
||||
if err != nil {
|
||||
return context.GitInfo{}, fmt.Errorf("couldn't get commit date: %w", err)
|
||||
}
|
||||
summary, err := getSummary()
|
||||
summary, err := getSummary(ctx)
|
||||
if err != nil {
|
||||
return context.GitInfo{}, fmt.Errorf("couldn't get summary: %w", err)
|
||||
}
|
||||
gitURL, err := getURL()
|
||||
gitURL, err := getURL(ctx)
|
||||
if err != nil {
|
||||
return context.GitInfo{}, fmt.Errorf("couldn't get remote URL: %w", err)
|
||||
}
|
||||
@ -102,7 +102,7 @@ func getGitInfo() (context.GitInfo, error) {
|
||||
gitURL = u.String()
|
||||
}
|
||||
|
||||
tag, err := getTag()
|
||||
tag, err := getTag(ctx)
|
||||
if err != nil {
|
||||
return context.GitInfo{
|
||||
Branch: branch,
|
||||
@ -116,22 +116,22 @@ func getGitInfo() (context.GitInfo, error) {
|
||||
}, ErrNoTag
|
||||
}
|
||||
|
||||
subject, err := getTagWithFormat(tag, "contents:subject")
|
||||
subject, err := getTagWithFormat(ctx, tag, "contents:subject")
|
||||
if err != nil {
|
||||
return context.GitInfo{}, fmt.Errorf("couldn't get tag subject: %w", err)
|
||||
}
|
||||
|
||||
contents, err := getTagWithFormat(tag, "contents")
|
||||
contents, err := getTagWithFormat(ctx, tag, "contents")
|
||||
if err != nil {
|
||||
return context.GitInfo{}, fmt.Errorf("couldn't get tag contents: %w", err)
|
||||
}
|
||||
|
||||
body, err := getTagWithFormat(tag, "contents:body")
|
||||
body, err := getTagWithFormat(ctx, tag, "contents:body")
|
||||
if err != nil {
|
||||
return context.GitInfo{}, fmt.Errorf("couldn't get tag content body: %w", err)
|
||||
}
|
||||
|
||||
previous, err := getPreviousTag(tag)
|
||||
previous, err := getPreviousTag(ctx, tag)
|
||||
if err != nil {
|
||||
// shouldn't error, will only affect templates
|
||||
log.Warnf("couldn't find any tags before %q", tag)
|
||||
@ -163,10 +163,10 @@ func validate(ctx *context.Context) error {
|
||||
if _, err := os.Stat(".git/shallow"); err == nil {
|
||||
log.Warn("running against a shallow clone - check your CI documentation at https://goreleaser.com/ci")
|
||||
}
|
||||
if err := CheckDirty(); err != nil {
|
||||
if err := CheckDirty(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := git.Clean(git.Run("describe", "--exact-match", "--tags", "--match", ctx.Git.CurrentTag))
|
||||
_, err := git.Clean(git.Run(ctx, "describe", "--exact-match", "--tags", "--match", ctx.Git.CurrentTag))
|
||||
if err != nil {
|
||||
return ErrWrongRef{
|
||||
commit: ctx.Git.Commit,
|
||||
@ -177,20 +177,20 @@ func validate(ctx *context.Context) error {
|
||||
}
|
||||
|
||||
// CheckDirty returns an error if the current git repository is dirty.
|
||||
func CheckDirty() error {
|
||||
out, err := git.Run("status", "--porcelain")
|
||||
func CheckDirty(ctx *context.Context) error {
|
||||
out, err := git.Run(ctx, "status", "--porcelain")
|
||||
if strings.TrimSpace(out) != "" || err != nil {
|
||||
return ErrDirty{status: out}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getBranch() (string, error) {
|
||||
return git.Clean(git.Run("rev-parse", "--abbrev-ref", "HEAD", "--quiet"))
|
||||
func getBranch(ctx *context.Context) (string, error) {
|
||||
return git.Clean(git.Run(ctx, "rev-parse", "--abbrev-ref", "HEAD", "--quiet"))
|
||||
}
|
||||
|
||||
func getCommitDate() (time.Time, error) {
|
||||
ct, err := git.Clean(git.Run("show", "--format='%ct'", "HEAD", "--quiet"))
|
||||
func getCommitDate(ctx *context.Context) (time.Time, error) {
|
||||
ct, err := git.Clean(git.Run(ctx, "show", "--format='%ct'", "HEAD", "--quiet"))
|
||||
if err != nil {
|
||||
return time.Time{}, err
|
||||
}
|
||||
@ -205,24 +205,24 @@ func getCommitDate() (time.Time, error) {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func getShortCommit() (string, error) {
|
||||
return git.Clean(git.Run("show", "--format='%h'", "HEAD", "--quiet"))
|
||||
func getShortCommit(ctx *context.Context) (string, error) {
|
||||
return git.Clean(git.Run(ctx, "show", "--format='%h'", "HEAD", "--quiet"))
|
||||
}
|
||||
|
||||
func getFullCommit() (string, error) {
|
||||
return git.Clean(git.Run("show", "--format='%H'", "HEAD", "--quiet"))
|
||||
func getFullCommit(ctx *context.Context) (string, error) {
|
||||
return git.Clean(git.Run(ctx, "show", "--format='%H'", "HEAD", "--quiet"))
|
||||
}
|
||||
|
||||
func getSummary() (string, error) {
|
||||
return git.Clean(git.Run("describe", "--always", "--dirty", "--tags"))
|
||||
func getSummary(ctx *context.Context) (string, error) {
|
||||
return git.Clean(git.Run(ctx, "describe", "--always", "--dirty", "--tags"))
|
||||
}
|
||||
|
||||
func getTagWithFormat(tag, format string) (string, error) {
|
||||
out, err := git.Run("tag", "-l", "--format='%("+format+")'", tag)
|
||||
func getTagWithFormat(ctx *context.Context, tag, format string) (string, error) {
|
||||
out, err := git.Run(ctx, "tag", "-l", "--format='%("+format+")'", tag)
|
||||
return strings.TrimSpace(strings.TrimSuffix(strings.ReplaceAll(out, "'", ""), "\n\n")), err
|
||||
}
|
||||
|
||||
func getTag() (string, error) {
|
||||
func getTag(ctx *context.Context) (string, error) {
|
||||
var tag string
|
||||
var err error
|
||||
for _, fn := range []func() (string, error){
|
||||
@ -230,10 +230,10 @@ func getTag() (string, error) {
|
||||
return os.Getenv("GORELEASER_CURRENT_TAG"), nil
|
||||
},
|
||||
func() (string, error) {
|
||||
return git.Clean(git.Run("tag", "--points-at", "HEAD", "--sort", "-version:refname"))
|
||||
return git.Clean(git.Run(ctx, "tag", "--points-at", "HEAD", "--sort", "-version:refname"))
|
||||
},
|
||||
func() (string, error) {
|
||||
return git.Clean(git.Run("describe", "--tags", "--abbrev=0"))
|
||||
return git.Clean(git.Run(ctx, "describe", "--tags", "--abbrev=0"))
|
||||
},
|
||||
} {
|
||||
tag, err = fn()
|
||||
@ -245,14 +245,14 @@ func getTag() (string, error) {
|
||||
return tag, err
|
||||
}
|
||||
|
||||
func getPreviousTag(current string) (string, error) {
|
||||
func getPreviousTag(ctx *context.Context, current string) (string, error) {
|
||||
if tag := os.Getenv("GORELEASER_PREVIOUS_TAG"); tag != "" {
|
||||
return tag, nil
|
||||
}
|
||||
|
||||
return git.Clean(git.Run("describe", "--tags", "--abbrev=0", fmt.Sprintf("tags/%s^", current)))
|
||||
return git.Clean(git.Run(ctx, "describe", "--tags", "--abbrev=0", fmt.Sprintf("tags/%s^", current)))
|
||||
}
|
||||
|
||||
func getURL() (string, error) {
|
||||
return git.Clean(git.Run("ls-remote", "--get-url"))
|
||||
func getURL(ctx *context.Context) (string, error) {
|
||||
return git.Clean(git.Run(ctx, "ls-remote", "--get-url"))
|
||||
}
|
||||
|
@ -18,9 +18,7 @@ func TestDescription(t *testing.T) {
|
||||
|
||||
func TestNotAGitFolder(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
require.EqualError(t, Pipe{}.Run(ctx), ErrNotRepository.Error())
|
||||
}
|
||||
|
||||
@ -30,9 +28,7 @@ func TestSingleCommit(t *testing.T) {
|
||||
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
||||
testlib.GitCommit(t, "commit1")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
require.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
|
||||
require.Equal(t, "v0.0.1", ctx.Git.Summary)
|
||||
@ -46,9 +42,7 @@ func TestAnnotatedTags(t *testing.T) {
|
||||
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
||||
testlib.GitCommit(t, "commit1")
|
||||
testlib.GitAnnotatedTag(t, "v0.0.1", "first version\n\nlalalla\nlalal\nlah")
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
require.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
|
||||
require.Equal(t, "first version", ctx.Git.TagSubject)
|
||||
@ -64,9 +58,7 @@ func TestBranch(t *testing.T) {
|
||||
testlib.GitCommit(t, "test-branch-commit")
|
||||
testlib.GitTag(t, "test-branch-tag")
|
||||
testlib.GitCheckoutBranch(t, "test-branch")
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
require.Equal(t, "test-branch", ctx.Git.Branch)
|
||||
require.Equal(t, "test-branch-tag", ctx.Git.Summary)
|
||||
@ -77,18 +69,14 @@ func TestNoRemote(t *testing.T) {
|
||||
testlib.GitInit(t)
|
||||
testlib.GitCommit(t, "commit1")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
require.EqualError(t, Pipe{}.Run(ctx), "couldn't get remote URL: fatal: No remote configured to list refs from.")
|
||||
}
|
||||
|
||||
func TestNewRepository(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
testlib.GitInit(t)
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
// TODO: improve this error handling
|
||||
require.Contains(t, Pipe{}.Run(ctx).Error(), `fatal: ambiguous argument 'HEAD'`)
|
||||
}
|
||||
@ -191,9 +179,7 @@ func TestTagIsNotLastCommit(t *testing.T) {
|
||||
testlib.GitCommit(t, "commit3")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
testlib.GitCommit(t, "commit4")
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
err := Pipe{}.Run(ctx)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "git tag v0.0.1 was not made against commit")
|
||||
@ -290,9 +276,7 @@ func TestTagFromCI(t *testing.T) {
|
||||
require.NoError(t, os.Setenv(name, value))
|
||||
}
|
||||
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
require.Equal(t, tc.expected, ctx.Git.CurrentTag)
|
||||
|
||||
@ -308,9 +292,7 @@ func TestNoPreviousTag(t *testing.T) {
|
||||
testlib.GitRemoteAdd(t, "git@github.com:foo/bar.git")
|
||||
testlib.GitCommit(t, "commit1")
|
||||
testlib.GitTag(t, "v0.0.1")
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
require.Equal(t, "v0.0.1", ctx.Git.CurrentTag)
|
||||
require.Empty(t, ctx.Git.PreviousTag, "should be empty")
|
||||
@ -340,9 +322,7 @@ func TestPreviousTagFromCI(t *testing.T) {
|
||||
require.NoError(t, os.Setenv(name, value))
|
||||
}
|
||||
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
require.NoError(t, Pipe{}.Run(ctx))
|
||||
require.Equal(t, tc.expected, ctx.Git.PreviousTag)
|
||||
|
||||
|
@ -28,7 +28,7 @@ func (Pipe) Default(ctx *context.Context) error {
|
||||
}
|
||||
|
||||
if milestone.Repo.Name == "" {
|
||||
repo, err := git.ExtractRepoFromConfig()
|
||||
repo, err := git.ExtractRepoFromConfig(ctx)
|
||||
|
||||
if err != nil && !ctx.Snapshot {
|
||||
return err
|
||||
|
@ -15,18 +15,16 @@ func TestDefaultWithRepoConfig(t *testing.T) {
|
||||
testlib.GitInit(t)
|
||||
testlib.GitRemoteAdd(t, "git@github.com:githubowner/githubrepo.git")
|
||||
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{
|
||||
Milestones: []config.Milestone{
|
||||
{
|
||||
Repo: config.Repo{
|
||||
Name: "configrepo",
|
||||
Owner: "configowner",
|
||||
},
|
||||
ctx := context.New(config.Project{
|
||||
Milestones: []config.Milestone{
|
||||
{
|
||||
Repo: config.Repo{
|
||||
Name: "configrepo",
|
||||
Owner: "configowner",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
require.Equal(t, "configrepo", ctx.Config.Milestones[0].Repo.Name)
|
||||
@ -48,26 +46,22 @@ func TestDefaultWithRepoRemote(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDefaultWithNameTemplate(t *testing.T) {
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{
|
||||
Milestones: []config.Milestone{
|
||||
{
|
||||
NameTemplate: "confignametemplate",
|
||||
},
|
||||
ctx := context.New(config.Project{
|
||||
Milestones: []config.Milestone{
|
||||
{
|
||||
NameTemplate: "confignametemplate",
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
require.Equal(t, "confignametemplate", ctx.Config.Milestones[0].NameTemplate)
|
||||
}
|
||||
|
||||
func TestDefaultWithoutGitRepo(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{
|
||||
Milestones: []config.Milestone{{}},
|
||||
},
|
||||
}
|
||||
ctx := context.New(config.Project{
|
||||
Milestones: []config.Milestone{{}},
|
||||
})
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
require.EqualError(t, Pipe{}.Default(ctx), "current folder is not a git repository")
|
||||
require.Empty(t, ctx.Config.Milestones[0].Repo.String())
|
||||
@ -75,11 +69,9 @@ func TestDefaultWithoutGitRepo(t *testing.T) {
|
||||
|
||||
func TestDefaultWithoutGitRepoOrigin(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{
|
||||
Milestones: []config.Milestone{{}},
|
||||
},
|
||||
}
|
||||
ctx := context.New(config.Project{
|
||||
Milestones: []config.Milestone{{}},
|
||||
})
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
testlib.GitInit(t)
|
||||
require.EqualError(t, Pipe{}.Default(ctx), "no remote configured to list refs from")
|
||||
@ -88,11 +80,9 @@ func TestDefaultWithoutGitRepoOrigin(t *testing.T) {
|
||||
|
||||
func TestDefaultWithoutGitRepoSnapshot(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{
|
||||
Milestones: []config.Milestone{{}},
|
||||
},
|
||||
}
|
||||
ctx := context.New(config.Project{
|
||||
Milestones: []config.Milestone{{}},
|
||||
})
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
ctx.Snapshot = true
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
@ -100,11 +90,9 @@ func TestDefaultWithoutGitRepoSnapshot(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDefaultWithoutNameTemplate(t *testing.T) {
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{
|
||||
Milestones: []config.Milestone{{}},
|
||||
},
|
||||
}
|
||||
ctx := context.New(config.Project{
|
||||
Milestones: []config.Milestone{{}},
|
||||
})
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
require.Equal(t, "{{ .Tag }}", ctx.Config.Milestones[0].NameTemplate)
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ func (Pipe) Default(ctx *context.Context) error {
|
||||
switch ctx.TokenType {
|
||||
case context.TokenTypeGitLab:
|
||||
if ctx.Config.Release.GitLab.Name == "" {
|
||||
repo, err := git.ExtractRepoFromConfig()
|
||||
repo, err := git.ExtractRepoFromConfig(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -63,7 +63,7 @@ func (Pipe) Default(ctx *context.Context) error {
|
||||
)
|
||||
case context.TokenTypeGitea:
|
||||
if ctx.Config.Release.Gitea.Name == "" {
|
||||
repo, err := git.ExtractRepoFromConfig()
|
||||
repo, err := git.ExtractRepoFromConfig(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -79,7 +79,7 @@ func (Pipe) Default(ctx *context.Context) error {
|
||||
default:
|
||||
// We keep github as default for now
|
||||
if ctx.Config.Release.GitHub.Name == "" {
|
||||
repo, err := git.ExtractRepoFromConfig()
|
||||
repo, err := git.ExtractRepoFromConfig(ctx)
|
||||
if err != nil && !ctx.Snapshot {
|
||||
return err
|
||||
}
|
||||
|
@ -498,16 +498,14 @@ func TestDefaultFilled(t *testing.T) {
|
||||
testlib.GitInit(t)
|
||||
testlib.GitRemoteAdd(t, "git@github.com:goreleaser/goreleaser.git")
|
||||
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{
|
||||
Release: config.Release{
|
||||
GitHub: config.Repo{
|
||||
Name: "foo",
|
||||
Owner: "bar",
|
||||
},
|
||||
ctx := context.New(config.Project{
|
||||
Release: config.Release{
|
||||
GitHub: config.Repo{
|
||||
Name: "foo",
|
||||
Owner: "bar",
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
require.Equal(t, "foo", ctx.Config.Release.GitHub.Name)
|
||||
@ -516,9 +514,7 @@ func TestDefaultFilled(t *testing.T) {
|
||||
|
||||
func TestDefaultNotAGitRepo(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
require.EqualError(t, Pipe{}.Default(ctx), "current folder is not a git repository")
|
||||
require.Empty(t, ctx.Config.Release.GitHub.String())
|
||||
@ -526,9 +522,7 @@ func TestDefaultNotAGitRepo(t *testing.T) {
|
||||
|
||||
func TestDefaultGitRepoWithoutOrigin(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
testlib.GitInit(t)
|
||||
require.EqualError(t, Pipe{}.Default(ctx), "no remote configured to list refs from")
|
||||
@ -537,9 +531,7 @@ func TestDefaultGitRepoWithoutOrigin(t *testing.T) {
|
||||
|
||||
func TestDefaultNotAGitRepoSnapshot(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
ctx.Snapshot = true
|
||||
require.NoError(t, Pipe{}.Default(ctx))
|
||||
@ -548,9 +540,7 @@ func TestDefaultNotAGitRepoSnapshot(t *testing.T) {
|
||||
|
||||
func TestDefaultGitRepoWithoutRemote(t *testing.T) {
|
||||
testlib.Mktmp(t)
|
||||
ctx := &context.Context{
|
||||
Config: config.Project{},
|
||||
}
|
||||
ctx := context.New(config.Project{})
|
||||
ctx.TokenType = context.TokenTypeGitHub
|
||||
require.Error(t, Pipe{}.Default(ctx))
|
||||
require.Empty(t, ctx.Config.Release.GitHub.String())
|
||||
|
@ -43,7 +43,7 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
args = append(args, "--prefix", prefix)
|
||||
}
|
||||
args = append(args, ctx.Git.FullCommit)
|
||||
out, err := git.Clean(git.Run(args...))
|
||||
out, err := git.Clean(git.Run(ctx, args...))
|
||||
log.Debug(out)
|
||||
ctx.Artifacts.Add(&artifact.Artifact{
|
||||
Type: artifact.UploadableSourceArchive,
|
||||
|
@ -1,6 +1,7 @@
|
||||
package testlib
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/git"
|
||||
@ -83,7 +84,7 @@ func fakeGit(args ...string) (string, error) {
|
||||
"-c", "log.showSignature=false",
|
||||
}
|
||||
allArgs = append(allArgs, args...)
|
||||
return git.Run(allArgs...)
|
||||
return git.Run(context.TODO(), allArgs...)
|
||||
}
|
||||
|
||||
// GitCheckoutBranch allows us to change the active branch that we're using.
|
||||
|
Loading…
x
Reference in New Issue
Block a user