mirror of
https://github.com/goreleaser/goreleaser.git
synced 2024-12-31 01:53:50 +02:00
feat(source): add prefix_template option (#2620)
This commit is contained in:
parent
36872ddef5
commit
b1a0f35b14
@ -31,7 +31,19 @@ func (Pipe) Run(ctx *context.Context) (err error) {
|
||||
filename := name + "." + ctx.Config.Source.Format
|
||||
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))
|
||||
args := []string{
|
||||
"archive",
|
||||
"-o", path,
|
||||
}
|
||||
if ctx.Config.Source.PrefixTemplate != "" {
|
||||
prefix, err := tmpl.New(ctx).Apply(ctx.Config.Source.PrefixTemplate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
args = append(args, "--prefix", prefix)
|
||||
}
|
||||
args = append(args, ctx.Git.FullCommit)
|
||||
out, err := git.Clean(git.Run(args...))
|
||||
log.Debug(out)
|
||||
ctx.Artifacts.Add(&artifact.Artifact{
|
||||
Type: artifact.UploadableSourceArchive,
|
||||
|
@ -28,8 +28,9 @@ func TestArchive(t *testing.T) {
|
||||
ProjectName: "foo",
|
||||
Dist: "dist",
|
||||
Source: config.Source{
|
||||
Format: format,
|
||||
Enabled: true,
|
||||
Format: format,
|
||||
Enabled: true,
|
||||
PrefixTemplate: "{{ .ProjectName }}-{{ .Version }}/",
|
||||
},
|
||||
})
|
||||
ctx.Git.FullCommit = "HEAD"
|
||||
|
@ -756,9 +756,10 @@ type Publisher struct {
|
||||
|
||||
// Source configuration.
|
||||
type Source struct {
|
||||
NameTemplate string `yaml:"name_template,omitempty"`
|
||||
Format string `yaml:"format,omitempty"`
|
||||
Enabled bool `yaml:"enabled,omitempty"`
|
||||
NameTemplate string `yaml:"name_template,omitempty"`
|
||||
Format string `yaml:"format,omitempty"`
|
||||
Enabled bool `yaml:"enabled,omitempty"`
|
||||
PrefixTemplate string `yaml:"prefix_template,omitempty"`
|
||||
}
|
||||
|
||||
// Project includes all project configuration.
|
||||
|
@ -18,6 +18,11 @@ source:
|
||||
# Any format git-archive supports, this supports too.
|
||||
# Defaults to `tar.gz`
|
||||
format: 'tar'
|
||||
|
||||
# Prefix template.
|
||||
# String to prepend to each filename in the archive.
|
||||
# Defaults to empty
|
||||
prefix_template: '{{ .ProjectName }}-{{ .Version }}/'
|
||||
```
|
||||
|
||||
!!! tip
|
||||
|
Loading…
Reference in New Issue
Block a user