Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: upload source archive Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com> * fix: lint Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
- Loading branch information
Showing
15 changed files
with
257 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Package sourcearchive archives the source of the project using git-archive. | ||
package sourcearchive | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/apex/log" | ||
"github.com/goreleaser/goreleaser/internal/artifact" | ||
"github.com/goreleaser/goreleaser/internal/git" | ||
"github.com/goreleaser/goreleaser/internal/pipe" | ||
"github.com/goreleaser/goreleaser/internal/tmpl" | ||
"github.com/goreleaser/goreleaser/pkg/context" | ||
) | ||
|
||
// Pipe for cleandis | ||
type Pipe struct{} | ||
|
||
func (Pipe) String() string { | ||
return "creating source archive" | ||
} | ||
|
||
// Run the pipe | ||
func (Pipe) Run(ctx *context.Context) (err error) { | ||
if !ctx.Config.Source.Enabled { | ||
return pipe.Skip("source pipe is disabled") | ||
} | ||
|
||
name, err := tmpl.New(ctx).Apply(ctx.Config.Source.NameTemplate) | ||
if err != nil { | ||
return err | ||
} | ||
var filename = name + "." + ctx.Config.Source.Format | ||
var path = filepath.Join(ctx.Config.Dist, filename) | ||
log.WithField("file", filename).Info("creating source archive") | ||
out, err := git.Clean(git.Run("archive", "-o", path, ctx.Git.FullCommit)) | ||
log.Debug(out) | ||
ctx.Artifacts.Add(&artifact.Artifact{ | ||
Type: artifact.UploadableSourceArchive, | ||
Name: filename, | ||
Path: path, | ||
Extra: map[string]interface{}{ | ||
"Format": ctx.Config.Source.Format, | ||
}, | ||
}) | ||
return err | ||
} | ||
|
||
// Default sets the pipe defaults | ||
func (Pipe) Default(ctx *context.Context) error { | ||
var archive = &ctx.Config.Source | ||
if archive.Format == "" { | ||
archive.Format = "tar.gz" | ||
} | ||
|
||
if archive.NameTemplate == "" { | ||
archive.NameTemplate = "{{ .ProjectName }}-{{ .Version }}" | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package sourcearchive | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/goreleaser/goreleaser/internal/artifact" | ||
"github.com/goreleaser/goreleaser/internal/testlib" | ||
"github.com/goreleaser/goreleaser/pkg/config" | ||
"github.com/goreleaser/goreleaser/pkg/context" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestArchive(t *testing.T) { | ||
for _, format := range []string{"tar.gz", "tar", "zip"} { | ||
t.Run(format, func(t *testing.T) { | ||
tmp, back := testlib.Mktmp(t) | ||
defer back() | ||
require.NoError(t, os.Mkdir("dist", 0744)) | ||
|
||
testlib.GitInit(t) | ||
require.NoError(t, ioutil.WriteFile("code.txt", []byte("not really code"), 0655)) | ||
require.NoError(t, ioutil.WriteFile("README.md", []byte("# my dope fake project"), 0655)) | ||
testlib.GitAdd(t) | ||
testlib.GitCommit(t, "feat: first") | ||
|
||
var ctx = context.New(config.Project{ | ||
ProjectName: "foo", | ||
Dist: "dist", | ||
Source: config.Source{ | ||
Format: format, | ||
Enabled: true, | ||
}, | ||
}) | ||
ctx.Git.FullCommit = "HEAD" | ||
ctx.Version = "1.0.0" | ||
|
||
require.NoError(t, Pipe{}.Default(ctx)) | ||
require.NoError(t, Pipe{}.Run(ctx)) | ||
|
||
var artifacts = ctx.Artifacts.List() | ||
require.Len(t, artifacts, 1) | ||
require.Equal(t, artifact.Artifact{ | ||
Type: artifact.UploadableSourceArchive, | ||
Name: "foo-1.0.0." + format, | ||
Path: "dist/foo-1.0.0." + format, | ||
Extra: map[string]interface{}{ | ||
"Format": format, | ||
}, | ||
}, *artifacts[0]) | ||
stat, err := os.Stat(filepath.Join(tmp, "dist", "foo-1.0.0."+format)) | ||
require.NoError(t, err) | ||
require.Greater(t, stat.Size(), int64(100)) | ||
}) | ||
} | ||
} | ||
|
||
func TestDefault(t *testing.T) { | ||
var ctx = context.New(config.Project{}) | ||
require.NoError(t, Pipe{}.Default(ctx)) | ||
require.Equal(t, config.Source{ | ||
NameTemplate: "{{ .ProjectName }}-{{ .Version }}", | ||
Format: "tar.gz", | ||
}, ctx.Config.Source) | ||
} | ||
|
||
func TestInvalidNameTemplate(t *testing.T) { | ||
var ctx = context.New(config.Project{ | ||
Source: config.Source{ | ||
Enabled: true, | ||
NameTemplate: "{{ .foo }-asdda", | ||
}, | ||
}) | ||
require.EqualError(t, Pipe{}.Run(ctx), "template: tmpl:1: unexpected \"}\" in operand") | ||
} | ||
|
||
func TestDisabled(t *testing.T) { | ||
testlib.AssertSkipped(t, Pipe{}.Run(context.New(config.Project{}))) | ||
} | ||
|
||
func TestString(t *testing.T) { | ||
require.NotEmpty(t, Pipe{}.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.