-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace legacy build system with new go based build system
- Loading branch information
1 parent
e6cf83e
commit 6cfc509
Showing
3 changed files
with
164 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
//+build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
|
||
"github.com/urfave/cli" | ||
) | ||
|
||
var packages = []string{"cli", "altsrc"} | ||
|
||
func main() { | ||
app := cli.NewApp() | ||
|
||
app.Name = "builder" | ||
app.Usage = "Generates a new urfave/cli build!" | ||
|
||
app.Commands = cli.Commands{ | ||
cli.Command{ | ||
Name: "vet", | ||
Action: VetActionFunc, | ||
}, | ||
cli.Command{ | ||
Name: "test", | ||
Action: TestActionFunc, | ||
}, | ||
cli.Command{ | ||
Name: "gfmrun", | ||
Action: GfmrunActionFunc, | ||
}, | ||
cli.Command{ | ||
Name: "toc", | ||
Action: TocActionFunc, | ||
}, | ||
} | ||
|
||
err := app.Run(os.Args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func runCmd(arg string, args ...string) error { | ||
cmd := exec.Command(arg, args...) | ||
|
||
cmd.Stdin = os.Stdin | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
|
||
return cmd.Run() | ||
} | ||
|
||
func VetActionFunc(_ *cli.Context) error { | ||
return runCmd("go", "vet") | ||
} | ||
|
||
func TestActionFunc(c *cli.Context) error { | ||
for _, pkg := range packages { | ||
var packageName string | ||
|
||
if pkg == "cli" { | ||
packageName = "github.com/urfave/cli" | ||
} else { | ||
packageName = fmt.Sprintf("github.com/urfave/cli/%s", pkg) | ||
} | ||
|
||
coverProfile := fmt.Sprintf("--coverprofile=%s.coverprofile", pkg) | ||
|
||
err := runCmd("go", "test", "-v", coverProfile, packageName) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return testCleanup() | ||
} | ||
|
||
func testCleanup() error { | ||
var out bytes.Buffer | ||
|
||
for _, pkg := range packages { | ||
file, err := os.Open(fmt.Sprintf("%s.coverprofile", pkg)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
b, err := ioutil.ReadAll(file) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
out.Write(b) | ||
err = file.Close() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = os.Remove(fmt.Sprintf("%s.coverprofile", pkg)) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
outFile, err := os.Create("coverage.txt") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = out.WriteTo(outFile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = outFile.Close() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func GfmrunActionFunc(_ *cli.Context) error { | ||
file, err := os.Open("README.md") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var counter int | ||
scanner := bufio.NewScanner(file) | ||
for scanner.Scan() { | ||
if strings.Contains(scanner.Text(), "package main") { | ||
counter++ | ||
} | ||
} | ||
|
||
err = scanner.Err() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return runCmd("gfmrun", "-c", fmt.Sprint(counter), "-s", "README.md") | ||
} | ||
|
||
func TocActionFunc(_ *cli.Context) error { | ||
err := runCmd("node_modules/.bin/markdown-toc", "-i", "README.md") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = runCmd("git", "diff", "--exit-code") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.