From 79fe61e65ca7029943daa2cb0b8365f496dbd7b6 Mon Sep 17 00:00:00 2001 From: chai2010 Date: Mon, 15 Feb 2016 16:47:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8C=85=E6=97=B6=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E6=BA=90=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- builder.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/builder.go b/builder.go index 02defe9..442d5a0 100644 --- a/builder.go +++ b/builder.go @@ -29,6 +29,9 @@ func main() { // zip文件名 zipBaseName := fmt.Sprintf("gopl-zh-%s-%s", time.Now().Format("20060102"), gitVersion[:6]) + // 导出Git + exportGitToZip("./_book/" + zipBaseName + ".source.zip") + os.Remove(zipBaseName + ".zip") file, err := os.Create(zipBaseName + ".zip") if err != nil { @@ -112,6 +115,16 @@ func getGitCommitVersion() (version string) { return "master" } +// 导出Git到Zip文件 +func exportGitToZip(filename string) { + if !strings.HasSuffix(filename, ".zip") { + filename += ".zip" + } + if _, err := exec.Command(`git`, `archive`, `--format`, `zip`, `--output`, filename, `master`).CombinedOutput(); err != nil { + log.Fatal("cpFile: ", err) + } +} + func cpFile(dst, src string) { err := os.MkdirAll(filepath.Dir(dst), 0666) if err != nil && !os.IsExist(err) {