From c867632ebfee02b91314fc564b29dfd19cca839a Mon Sep 17 00:00:00 2001 From: Noah Zoschke Date: Fri, 26 Jan 2018 08:25:29 -0800 Subject: [PATCH 1/7] boilerplate golang bios script --- bios.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100755 bios.sh diff --git a/bios.sh b/bios.sh new file mode 100755 index 0000000..1250f42 --- /dev/null +++ b/bios.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -ex + +mkdir -p src/$PKG && cd src/$PKG +run -s "Cloning" git clone $URL --branch $REF --single-branch . +git reset --hard $SHA + +PKGS=$(go list $PKG/...) +run -s "Linting" golint -set_exit_status $PKGS +run -s "Vetting" go vet -x $PKGS +run -s "Building" go build -v $PKGS +run -s "Testing" go test -v $PKGS From 116b4c734125291c79104cd882edd216156f4308 Mon Sep 17 00:00:00 2001 From: Noah Zoschke Date: Fri, 26 Jan 2018 08:46:33 -0800 Subject: [PATCH 2/7] exported types should have comment (golint) --- tools/generate.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/generate.go b/tools/generate.go index 6bb3184..adccc7b 100644 --- a/tools/generate.go +++ b/tools/generate.go @@ -118,12 +118,14 @@ func debug(msg string) { var docsPat = regexp.MustCompile("^\\s*(\\/\\/|#)\\s") var dashPat = regexp.MustCompile("\\-+") +// Seg is a segment of an example type Seg struct { Docs, DocsRendered string Code, CodeRendered string CodeEmpty, CodeLeading, CodeRun bool } +// Example is info extracted from an example file type Example struct { Id, Name string GoCode, GoCodeHash, UrlHash string From 13a5dea6a788dfed74ddf070ef7e39fca1c6ff33 Mon Sep 17 00:00:00 2001 From: Noah Zoschke Date: Fri, 26 Jan 2018 08:48:48 -0800 Subject: [PATCH 3/7] Id should be ID (golint) --- tools/generate.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/generate.go b/tools/generate.go index adccc7b..6f17c84 100644 --- a/tools/generate.go +++ b/tools/generate.go @@ -127,7 +127,7 @@ type Seg struct { // Example is info extracted from an example file type Example struct { - Id, Name string + ID, Name string GoCode, GoCodeHash, UrlHash string Segs [][]*Seg NextExample *Example @@ -222,14 +222,14 @@ func parseExamples() []*Example { for _, exampleName := range exampleNames { if (exampleName != "") && !strings.HasPrefix(exampleName, "#") { example := Example{Name: exampleName} - exampleId := strings.ToLower(exampleName) - exampleId = strings.Replace(exampleId, " ", "-", -1) - exampleId = strings.Replace(exampleId, "/", "-", -1) - exampleId = strings.Replace(exampleId, "'", "", -1) - exampleId = dashPat.ReplaceAllString(exampleId, "-") - example.Id = exampleId + exampleID := strings.ToLower(exampleName) + exampleID = strings.Replace(exampleID, " ", "-", -1) + exampleID = strings.Replace(exampleID, "/", "-", -1) + exampleID = strings.Replace(exampleID, "'", "", -1) + exampleID = dashPat.ReplaceAllString(exampleID, "-") + example.ID = exampleID example.Segs = make([][]*Seg, 0) - sourcePaths := mustGlob("examples/" + exampleId + "/*") + sourcePaths := mustGlob("examples/" + exampleID + "/*") for _, sourcePath := range sourcePaths { if strings.HasSuffix(sourcePath, ".hash") { example.GoCodeHash, example.UrlHash = parseHashFile(sourcePath) @@ -243,7 +243,7 @@ func parseExamples() []*Example { } newCodeHash := sha1Sum(example.GoCode) if example.GoCodeHash != newCodeHash { - example.UrlHash = resetUrlHashFile(newCodeHash, example.GoCode, "examples/"+example.Id+"/"+example.Id+".hash") + example.UrlHash = resetUrlHashFile(newCodeHash, example.GoCode, "examples/"+example.ID+"/"+example.ID+".hash") } examples = append(examples, &example) } @@ -270,7 +270,7 @@ func renderExamples(examples []*Example) { _, err := exampleTmpl.Parse(mustReadFile("templates/example.tmpl")) check(err) for _, example := range examples { - exampleF, err := os.Create(siteDir + "/" + example.Id) + exampleF, err := os.Create(siteDir + "/" + example.ID) check(err) exampleTmpl.Execute(exampleF, example) } From d5a7560cdcdfc749f8f04d598bceb1046496c616 Mon Sep 17 00:00:00 2001 From: Noah Zoschke Date: Fri, 26 Jan 2018 08:51:01 -0800 Subject: [PATCH 4/7] Url should be URL (golint) --- tools/generate.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/generate.go b/tools/generate.go index 6f17c84..56362b4 100644 --- a/tools/generate.go +++ b/tools/generate.go @@ -128,7 +128,7 @@ type Seg struct { // Example is info extracted from an example file type Example struct { ID, Name string - GoCode, GoCodeHash, UrlHash string + GoCode, GoCodeHash, URLHash string Segs [][]*Seg NextExample *Example } @@ -138,7 +138,7 @@ func parseHashFile(sourcePath string) (string, string) { return lines[0], lines[1] } -func resetUrlHashFile(codehash, code, sourcePath string) string { +func resetURLHashFile(codehash, code, sourcePath string) string { payload := strings.NewReader(code) resp, err := http.Post("https://play.golang.org/share", "text/plain", payload) if err != nil { @@ -232,7 +232,7 @@ func parseExamples() []*Example { sourcePaths := mustGlob("examples/" + exampleID + "/*") for _, sourcePath := range sourcePaths { if strings.HasSuffix(sourcePath, ".hash") { - example.GoCodeHash, example.UrlHash = parseHashFile(sourcePath) + example.GoCodeHash, example.URLHash = parseHashFile(sourcePath) } else { sourceSegs, filecontents := parseAndRenderSegs(sourcePath) if filecontents != "" { @@ -243,7 +243,7 @@ func parseExamples() []*Example { } newCodeHash := sha1Sum(example.GoCode) if example.GoCodeHash != newCodeHash { - example.UrlHash = resetUrlHashFile(newCodeHash, example.GoCode, "examples/"+example.ID+"/"+example.ID+".hash") + example.URLHash = resetURLHashFile(newCodeHash, example.GoCode, "examples/"+example.ID+"/"+example.ID+".hash") } examples = append(examples, &example) } From 08b8a982487149fcfdf13c34640351e320616028 Mon Sep 17 00:00:00 2001 From: Noah Zoschke Date: Fri, 26 Jan 2018 08:52:01 -0800 Subject: [PATCH 5/7] remove unreachable code (go vet) --- tools/generate.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/generate.go b/tools/generate.go index 56362b4..700f447 100644 --- a/tools/generate.go +++ b/tools/generate.go @@ -106,7 +106,6 @@ func whichLexer(path string) string { return "console" } panic("No lexer for " + path) - return "" } func debug(msg string) { From e83d23555c2f00a9d0046fccca9c27a3cf83e861 Mon Sep 17 00:00:00 2001 From: Noah Zoschke Date: Fri, 26 Jan 2018 08:55:12 -0800 Subject: [PATCH 6/7] customize build --- bios.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bios.sh b/bios.sh index 1250f42..772ccd3 100755 --- a/bios.sh +++ b/bios.sh @@ -5,8 +5,10 @@ mkdir -p src/$PKG && cd src/$PKG run -s "Cloning" git clone $URL --branch $REF --single-branch . git reset --hard $SHA -PKGS=$(go list $PKG/...) +go get github.com/russross/blackfriday + +PKGS=$(go list $PKG/... | grep -v examples) run -s "Linting" golint -set_exit_status $PKGS run -s "Vetting" go vet -x $PKGS -run -s "Building" go build -v $PKGS +run -s "Building" tools/build run -s "Testing" go test -v $PKGS From fd573c309521427f407dd689e5344b29ec4d2804 Mon Sep 17 00:00:00 2001 From: Noah Zoschke Date: Fri, 26 Jan 2018 08:55:25 -0800 Subject: [PATCH 7/7] no tests --- bios.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/bios.sh b/bios.sh index 772ccd3..353ef84 100755 --- a/bios.sh +++ b/bios.sh @@ -11,4 +11,3 @@ PKGS=$(go list $PKG/... | grep -v examples) run -s "Linting" golint -set_exit_status $PKGS run -s "Vetting" go vet -x $PKGS run -s "Building" tools/build -run -s "Testing" go test -v $PKGS