github.com/ahmet2mir/goreleaser@v0.180.3-0.20210927151101-8e5ee5a9b8c5/internal/pipe/sourcearchive/source.go (about) 1 // Package sourcearchive archives the source of the project using git-archive. 2 package sourcearchive 3 4 import ( 5 "path/filepath" 6 7 "github.com/apex/log" 8 "github.com/goreleaser/goreleaser/internal/artifact" 9 "github.com/goreleaser/goreleaser/internal/git" 10 "github.com/goreleaser/goreleaser/internal/tmpl" 11 "github.com/goreleaser/goreleaser/pkg/context" 12 ) 13 14 // Pipe for source archive. 15 type Pipe struct{} 16 17 func (Pipe) String() string { 18 return "creating source archive" 19 } 20 21 func (Pipe) Skip(ctx *context.Context) bool { 22 return !ctx.Config.Source.Enabled 23 } 24 25 // Run the pipe. 26 func (Pipe) Run(ctx *context.Context) (err error) { 27 name, err := tmpl.New(ctx).Apply(ctx.Config.Source.NameTemplate) 28 if err != nil { 29 return err 30 } 31 filename := name + "." + ctx.Config.Source.Format 32 path := filepath.Join(ctx.Config.Dist, filename) 33 log.WithField("file", filename).Info("creating source archive") 34 out, err := git.Clean(git.Run("archive", "-o", path, ctx.Git.FullCommit)) 35 log.Debug(out) 36 ctx.Artifacts.Add(&artifact.Artifact{ 37 Type: artifact.UploadableSourceArchive, 38 Name: filename, 39 Path: path, 40 Extra: map[string]interface{}{ 41 "Format": ctx.Config.Source.Format, 42 }, 43 }) 44 return err 45 } 46 47 // Default sets the pipe defaults. 48 func (Pipe) Default(ctx *context.Context) error { 49 archive := &ctx.Config.Source 50 if archive.Format == "" { 51 archive.Format = "tar.gz" 52 } 53 54 if archive.NameTemplate == "" { 55 archive.NameTemplate = "{{ .ProjectName }}-{{ .Version }}" 56 } 57 return nil 58 }