From 9bfb71b9ef32c59dcf5f7ac1b032b57b742bcaac Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 9 Apr 2023 12:38:12 +0800 Subject: [PATCH] build: compress build artifacts using gzip (#168) - Change the compression format from `tar` to `tar.gz` - Replace the flag `-cf` with `-zcf` in the `buildArgs` function fix https://github.com/appleboy/drone-scp/issues/123 --- plugin.go | 4 ++-- plugin_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin.go b/plugin.go index efbd6dc..676e609 100644 --- a/plugin.go +++ b/plugin.go @@ -120,7 +120,7 @@ func buildArgs(tar string, files fileList) []string { args = append(args, v) } } - args = append(args, "-cf") + args = append(args, "-zcf") args = append(args, getRealPath(tar)) args = append(args, files.Source...) @@ -254,7 +254,7 @@ func (p *Plugin) Exec() error { } files := globList(trimValues(p.Config.Source)) - p.DestFile = fmt.Sprintf("%s.tar", random.String(10)) + p.DestFile = fmt.Sprintf("%s.tar.gz", random.String(10)) // create a temporary file for the archive dir := os.TempDir() diff --git a/plugin_test.go b/plugin_test.go index e7954a9..a272928 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -579,7 +579,7 @@ func TestBuildArgs(t *testing.T) { } result := buildArgs("test.tar.gz", list) - expects := []string{"--exclude", "tests/a.txt", "--exclude", "tests/b.txt", "-cf", "test.tar.gz", "tests/a.txt", "tests/b.txt", "tests/c.txt"} + expects := []string{"--exclude", "tests/a.txt", "--exclude", "tests/b.txt", "-zcf", "test.tar.gz", "tests/a.txt", "tests/b.txt", "tests/c.txt"} assert.Equal(t, expects, result) list = fileList{ @@ -587,7 +587,7 @@ func TestBuildArgs(t *testing.T) { } result = buildArgs("test.tar.gz", list) - expects = []string{"-cf", "test.tar.gz", "tests/a.txt", "tests/b.txt"} + expects = []string{"-zcf", "test.tar.gz", "tests/a.txt", "tests/b.txt"} assert.Equal(t, expects, result) }