mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
feat: set file info for binaries inside archives (#3618)
closes #3582 Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
f05b211b61
commit
937067697b
@ -139,6 +139,9 @@ archives:
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
builds_info:
|
||||
group: root
|
||||
owner: root
|
||||
files:
|
||||
- README.md
|
||||
- LICENSE.md
|
||||
|
@ -206,6 +206,7 @@ func doCreate(ctx *context.Context, arch config.Archive, binaries []*artifact.Ar
|
||||
if err := a.Add(config.File{
|
||||
Source: binary.Path,
|
||||
Destination: dst,
|
||||
Info: arch.BuildsInfo,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("failed to add: '%s' -> '%s': %w", binary.Path, dst, err)
|
||||
}
|
||||
|
@ -82,8 +82,12 @@ func TestRunPipe(t *testing.T) {
|
||||
ProjectName: "foobar",
|
||||
Archives: []config.Archive{
|
||||
{
|
||||
ID: "myid",
|
||||
Builds: []string{"default"},
|
||||
ID: "myid",
|
||||
Builds: []string{"default"},
|
||||
BuildsInfo: config.FileInfo{
|
||||
Owner: "root",
|
||||
Group: "root",
|
||||
},
|
||||
NameTemplate: defaultNameTemplate,
|
||||
StripParentBinaryFolder: dets.Strip,
|
||||
Files: []config.File{
|
||||
@ -233,6 +237,11 @@ func TestRunPipe(t *testing.T) {
|
||||
},
|
||||
tarFiles(t, filepath.Join(dist, name)),
|
||||
)
|
||||
|
||||
header := tarInfo(t, filepath.Join(dist, name), expectBin)
|
||||
require.Equal(t, "root", header.Uname)
|
||||
require.Equal(t, "root", header.Gname)
|
||||
|
||||
}
|
||||
}
|
||||
if format == "zip" {
|
||||
@ -363,6 +372,27 @@ func zipFiles(t *testing.T, path string) []string {
|
||||
return paths
|
||||
}
|
||||
|
||||
func tarInfo(t *testing.T, path, name string) *tar.Header {
|
||||
t.Helper()
|
||||
f, err := os.Open(path)
|
||||
require.NoError(t, err)
|
||||
defer f.Close()
|
||||
gr, err := gzip.NewReader(f)
|
||||
require.NoError(t, err)
|
||||
defer gr.Close()
|
||||
r := tar.NewReader(gr)
|
||||
for {
|
||||
next, err := r.Next()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if next.Name == name {
|
||||
return next
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func tarFiles(t *testing.T, path string) []string {
|
||||
t.Helper()
|
||||
f, err := os.Open(path)
|
||||
|
@ -480,6 +480,7 @@ type UniversalBinary struct {
|
||||
type Archive struct {
|
||||
ID string `yaml:"id,omitempty" json:"id,omitempty"`
|
||||
Builds []string `yaml:"builds,omitempty" json:"builds,omitempty"`
|
||||
BuildsInfo FileInfo `yaml:"builds_info,omitempty" json:"builds_info,omitempty"`
|
||||
NameTemplate string `yaml:"name_template,omitempty" json:"name_template,omitempty"`
|
||||
Replacements map[string]string `yaml:"replacements,omitempty" json:"replacements,omitempty"` // Deprecated: use templates instead
|
||||
Format string `yaml:"format,omitempty" json:"format,omitempty"`
|
||||
|
@ -40,6 +40,19 @@ archives:
|
||||
# - `{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}`
|
||||
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
|
||||
|
||||
# Sets the given file info to all the binaries included from the `builds`.
|
||||
#
|
||||
# Default is to use the actual binary properties.
|
||||
#
|
||||
# Since: v1.14.0.
|
||||
builds_info:
|
||||
group: root
|
||||
owner: root
|
||||
mode: 0644
|
||||
# format is `time.RFC3339Nano`
|
||||
mtime: 2008-01-02T15:04:05Z
|
||||
|
||||
|
||||
# Set this to true if you want all files in the archive to be in a single directory.
|
||||
# If set to true and you extract the archive 'goreleaser_Linux_arm64.tar.gz',
|
||||
# you'll get a folder 'goreleaser_Linux_arm64'.
|
||||
|
3
www/docs/static/schema.json
generated
vendored
3
www/docs/static/schema.json
generated
vendored
@ -166,6 +166,9 @@
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"builds_info": {
|
||||
"$ref": "#/$defs/FileInfo"
|
||||
},
|
||||
"name_template": {
|
||||
"type": "string"
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user