You've already forked go-semantic-release
temp(pkg/releaser): add ZipFiles Method
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -35,3 +37,47 @@ func GetAccessToken(providerName string) (string, error) {
|
||||
}
|
||||
return token, nil
|
||||
}
|
||||
|
||||
// ZipFile compress given file in zip format
|
||||
func ZipFile(repository string, file string) (string, error) {
|
||||
|
||||
zipFileName := fmt.Sprintf("%s/%s", strings.TrimSuffix(repository, "/"), file)
|
||||
zipFile, err := os.Create(zipFileName)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
defer zipFile.Close()
|
||||
|
||||
fileToZip, err := os.Open(file)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer fileToZip.Close()
|
||||
|
||||
fileToZipInfo, err := fileToZip.Stat()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
zipWriter := zip.NewWriter(zipFile)
|
||||
|
||||
fileToZipHeader, err := zip.FileInfoHeader(fileToZipInfo)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
fileToZipHeader.Name = fileToZipInfo.Name()
|
||||
|
||||
fileToZipWriter, err := zipWriter.CreateHeader(fileToZipHeader)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if _, err = io.Copy(fileToZipWriter, fileToZip); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return zipFileName, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user