1
0
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:
Tom Payne 2021-11-02 23:57:20 +01:00 committed by GitHub
parent 36872ddef5
commit b1a0f35b14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 6 deletions

View File

@ -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,

View File

@ -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"

View File

@ -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.

View File

@ -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