Skip to content

Commit

Permalink
feat: support tgz and txz as archive formats
Browse files Browse the repository at this point in the history
We support `.tar.gz` since the beginning, and `.tar.xz` for a long time.

`.tgz` and `.txz` are just commonly used shorthands for the same
formats.

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Apr 8, 2023
1 parent 00d16bb commit c41d6de
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pkg/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ type Archive interface {
// New archive.
func New(w io.Writer, format string) (Archive, error) {
switch format {
case "tar.gz":
case "tar.gz", "tgz":
return targz.New(w), nil
case "tar":
return tar.New(w), nil
case "gz":
return gzip.New(w), nil
case "tar.xz":
case "tar.xz", "txz":
return tarxz.New(w), nil
case "zip":
return zip.New(w), nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/archive/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestArchive(t *testing.T) {
require.NoError(t, empty.Close())
require.NoError(t, os.Mkdir(folder+"/folder-inside", 0o755))

for _, format := range []string{"tar.gz", "zip", "gz", "tar.xz", "tar"} {
for _, format := range []string{"tar.gz", "zip", "gz", "tar.xz", "tar", "tgz", "txz"} {
format := format
t.Run(format, func(t *testing.T) {
f1, err := os.Create(filepath.Join(t.TempDir(), "1.tar"))
Expand All @@ -37,7 +37,7 @@ func TestArchive(t *testing.T) {
require.NoError(t, archive.Close())
require.NoError(t, f1.Close())

if format == "tar.xz" || format == "gz" {
if format == "tar.xz" || format == "txz" || format == "gz" {
_, err := Copying(f1, io.Discard, format)
require.Error(t, err)
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (bh Hook) JSONSchema() *jsonschema.Schema {
// FormatOverride is used to specify a custom format for a specific GOOS.
type FormatOverride struct {
Goos string `yaml:"goos,omitempty" json:"goos,omitempty"`
Format string `yaml:"format,omitempty" json:"format,omitempty"`
Format string `yaml:"format,omitempty" json:"format,omitempty" jsonschema:"enum=tar,enum=tgz,enum=tar.gz,enum=zip,enum=gz,enum=tar.xz,enum=txz,default=tar.gz"`
}

// File is a file inside an archive.
Expand Down Expand Up @@ -516,7 +516,7 @@ type Archive struct {
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"`
Format string `yaml:"format,omitempty" json:"format,omitempty" jsonschema:"enum=tar,enum=tgz,enum=tar.gz,enum=zip,enum=gz,enum=tar.xz,enum=txz,default=tar.gz"`
FormatOverrides []FormatOverride `yaml:"format_overrides,omitempty" json:"format_overrides,omitempty"`
WrapInDirectory string `yaml:"wrap_in_directory,omitempty" json:"wrap_in_directory,omitempty" jsonschema:"oneof_type=string;boolean"`
StripParentBinaryFolder bool `yaml:"strip_parent_binary_folder,omitempty" json:"strip_parent_binary_folder,omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions www/docs/customization/archive.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ archives:
builds:
- default

# Archive format. Valid options are `tar.gz`, `tar.xz`, `tar`, `gz`, `zip` and `binary`.
# Archive format. Valid options are `tar.gz`, `tgz`, `tar.xz`, `txz`, tar`, `gz`, `zip` and `binary`.
# If format is `binary`, no archives are created and the binaries are instead
# uploaded directly.
#
Expand All @@ -36,10 +36,10 @@ archives:
# Archive name.
#
# Default:
# - if format is `tar.gz`, `tar.xz`, `gz` or `zip`:
# - `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}`
# - if format is `binary`:
# - `{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}`
# - if format is anything else:
# - `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}`
# Templates: allowed
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"

Expand Down
9 changes: 8 additions & 1 deletion www/docs/static/schema-pro.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions www/docs/static/schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c41d6de

Please sign in to comment.