1
0
mirror of https://github.com/strongdm/comply synced 2025-12-16 19:24:01 +00:00

Compare commits

...

5 Commits

Author SHA1 Message Date
Justin McCarthy
e60d7285f4 more precise cross-platform dependency checking 2018-07-20 17:44:28 -07:00
Justin McCarthy
c99d800397 use filepath join to open index html 2018-07-20 17:08:09 -07:00
Justin McCarthy
0f1badca5b prepare Makefile for introduction of Windows binary 2018-07-05 17:26:29 -07:00
Justin McCarthy
00b59ed620 update to reflect contributions 2018-07-02 17:12:00 -07:00
Justin Bodeutsch
749017761d Percent signs need to be escaped in Printf (#49) 2018-07-02 17:10:00 -07:00
5 changed files with 93 additions and 49 deletions

View File

@@ -1,4 +1,6 @@
# Authors in alphabetical order: # Authors in alphabetical order:
Anthony Oliver
Justin Bodeutsch
Justin McCarthy <justin@strongdm.com> Justin McCarthy <justin@strongdm.com>
Manisha Singh <manisha@strongdm.com> Manisha Singh

View File

@@ -19,10 +19,12 @@ dist: clean
$(eval LDFLAGS := -ldflags='-X "github.com/strongdm/comply/internal/cli.Version=$(VERSION)"') $(eval LDFLAGS := -ldflags='-X "github.com/strongdm/comply/internal/cli.Version=$(VERSION)"')
mkdir dist mkdir dist
echo $(VERSION) echo $(VERSION)
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -gcflags=-trimpath=$(GOPATH) -asmflags=-trimpath=$(GOPATH) $(LDFLAGS) -o dist/comply-$(VERSION)-darwin-amd64 . GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -gcflags=-trimpath=$(GOPATH) -asmflags=-trimpath=$(GOPATH) -ldflags '-extldflags "-static"' $(LDFLAGS) -o dist/comply-$(VERSION)-darwin-amd64 .
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -gcflags=-trimpath=$(GOPATH) -asmflags=-trimpath=$(GOPATH) $(LDFLAGS) -o dist/comply-$(VERSION)-linux-amd64 . GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -gcflags=-trimpath=$(GOPATH) -asmflags=-trimpath=$(GOPATH) -ldflags '-extldflags "-static"' $(LDFLAGS) -o dist/comply-$(VERSION)-linux-amd64 .
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -gcflags=-trimpath=$(GOPATH) -asmflags=-trimpath=$(GOPATH) -ldflags '-extldflags "-static"' $(LDFLAGS) -o dist/comply-$(VERSION)-windows-amd64.exe .
cd dist && tar -czvf comply-$(VERSION)-darwin-amd64.tgz comply-$(VERSION)-darwin-amd64 cd dist && tar -czvf comply-$(VERSION)-darwin-amd64.tgz comply-$(VERSION)-darwin-amd64
cd dist && tar -czvf comply-$(VERSION)-linux-amd64.tgz comply-$(VERSION)-linux-amd64 cd dist && tar -czvf comply-$(VERSION)-linux-amd64.tgz comply-$(VERSION)-linux-amd64
cd dist && zip comply-$(VERSION)-windows-amd64.zip comply-$(VERSION)-windows-amd64.exe
brew: clean $(GO_SOURCES) brew: clean $(GO_SOURCES)
$(eval VERSION := $(shell cat version)) $(eval VERSION := $(shell cat version))

View File

@@ -133,14 +133,32 @@ func notifyVersion(c *cli.Context) error {
} }
func pandocMustExist(c *cli.Context) error { func pandocMustExist(c *cli.Context) error {
eitherMustExistErr := fmt.Errorf("Please install either Docker or the pandoc package and re-run `%s`", c.Command.Name) eitherMustExistErr := fmt.Errorf("\n\nPlease install either Docker or the pandoc package and re-run `%s`. Find OS-specific pandoc installation instructions at: [TODO]", c.Command.Name)
pandocExistErr := pandocBinaryMustExist(c) pandocExistErr, found, goodVersion, pdfLatex := pandocBinaryMustExist(c)
dockerExistErr := dockerMustExist(c) dockerExistErr, inPath, isRunning := dockerMustExist(c)
config.SetPandoc(pandocExistErr == nil, dockerExistErr == nil) config.SetPandoc(pandocExistErr == nil, dockerExistErr == nil)
check := func(b bool) string {
if b {
return "✔"
} else {
return "✖"
}
}
if pandocExistErr != nil && dockerExistErr != nil { if pandocExistErr != nil && dockerExistErr != nil {
fmt.Printf(`
[%s] pandoc binary installed and in PATH
[%s] pandoc version compatible
[%s] pdflatex binary installed and in PATH
[%s] docker binary installed
[%s] docker running
`, check(found), check(goodVersion), check(pdfLatex), check(inPath), check(isRunning))
return eitherMustExistErr return eitherMustExistErr
} }
@@ -152,67 +170,89 @@ func pandocMustExist(c *cli.Context) error {
return nil return nil
} }
func pandocBinaryMustExist(c *cli.Context) error { func pandocBinaryMustExist(c *cli.Context) (e error, found, goodVersion, pdfLatex bool) {
cmd := exec.Command("pandoc", "-v") cmd := exec.Command("pandoc", "-v")
outputRaw, err := cmd.Output() outputRaw, err := cmd.Output()
e = nil
found = false
goodVersion = false
pdfLatex = false
if err != nil { if err != nil {
return errors.Wrap(err, "error calling pandoc") e = errors.Wrap(err, "error calling pandoc")
} } else {
found = true
output := strings.TrimSpace((string(outputRaw))) goodVersion = true
versionErr := errors.New("cannot determine pandoc version") output := strings.TrimSpace((string(outputRaw)))
if !strings.HasPrefix(output, "pandoc") { versionErr := errors.New("cannot determine pandoc version")
return versionErr if !strings.HasPrefix(output, "pandoc") {
} e = versionErr
goodVersion = false
re := regexp.MustCompile(`pandoc (\d+)\.(\d+)`) } else {
result := re.FindStringSubmatch(output) re := regexp.MustCompile(`pandoc (\d+)\.(\d+)`)
if len(result) != 3 { result := re.FindStringSubmatch(output)
return versionErr if len(result) != 3 {
} e = versionErr
goodVersion = false
major, err := strconv.Atoi(result[1]) } else {
if err != nil { major, err := strconv.Atoi(result[1])
return versionErr if err != nil {
} e = versionErr
minor, err := strconv.Atoi(result[2]) goodVersion = false
if err != nil { }
return versionErr minor, err := strconv.Atoi(result[2])
} if err != nil {
e = versionErr
if major < 2 || minor < 1 { goodVersion = false
return errors.New("pandoc 2.1 or greater required") }
if major < 2 || minor < 1 {
e = errors.New("pandoc 2.1 or greater required")
goodVersion = false
}
}
}
} }
// pdflatex must also be present // pdflatex must also be present
cmd = exec.Command("pdflatex", "-v") cmd = exec.Command("pdflatex", "--version")
outputRaw, err = cmd.Output() outputRaw, err = cmd.Output()
if err != nil { if err != nil {
return errors.Wrap(err, "error calling pdflatex") e = errors.Wrap(err, "error calling pdflatex")
} else if !strings.Contains(string(outputRaw), "TeX") {
e = errors.New("pdflatex is required")
} else {
pdfLatex = true
} }
if !strings.Contains(string(outputRaw), "TeX") { return e, found, goodVersion, pdfLatex
return errors.New("pdflatex is required")
}
return nil
} }
func dockerMustExist(c *cli.Context) error { func dockerMustExist(c *cli.Context) (e error, inPath, isRunning bool) {
dockerErr := fmt.Errorf("Docker must be available in order to run `%s`", c.Command.Name) dockerErr := fmt.Errorf("Docker must be available in order to run `%s`", c.Command.Name)
inPath = true
cmd := exec.Command("docker", "--version")
_, err := cmd.Output()
if err != nil {
inPath = false
}
isRunning = true
ctx := context.Background() ctx := context.Background()
cli, err := client.NewEnvClient() cli, err := client.NewEnvClient()
if err != nil { if err != nil {
return dockerErr isRunning = false
return dockerErr, inPath, isRunning
} }
_, err = cli.Ping(ctx) _, err = cli.Ping(ctx)
if err != nil { if err != nil {
return dockerErr isRunning = false
return dockerErr, inPath, isRunning
} }
return nil return nil, inPath, isRunning
} }
func dockerPull(c *cli.Context) error { func dockerPull(c *cli.Context) error {

View File

@@ -69,10 +69,10 @@ func (g *githubPlugin) Configured() bool {
func (g *githubPlugin) Links() model.TicketLinks { func (g *githubPlugin) Links() model.TicketLinks {
links := model.TicketLinks{} links := model.TicketLinks{}
links.AuditAll = fmt.Sprintf("https://github.com/%s/%s/issues?q=is%3Aissue+is%3Aopen+label%3Acomply+label%3Aaudit", g.username, g.reponame) links.AuditAll = fmt.Sprintf("https://github.com/%s/%s/issues?q=is%%3Aissue+is%%3Aopen+label%%3Acomply+label%%3Aaudit", g.username, g.reponame)
links.AuditOpen = fmt.Sprintf("https://github.com/%s/%s/issues?q=is%3Aissue+is%3Aopen+label%3Acomply+label%3Aaudit", g.username, g.reponame) links.AuditOpen = fmt.Sprintf("https://github.com/%s/%s/issues?q=is%%3Aissue+is%%3Aopen+label%%3Acomply+label%%3Aaudit", g.username, g.reponame)
links.ProcedureAll = fmt.Sprintf("https://github.com/%s/%s/issues?q=is%3Aissue+label%3Acomply+label%3Aprocedure", g.username, g.reponame) links.ProcedureAll = fmt.Sprintf("https://github.com/%s/%s/issues?q=is%%3Aissue+label%%3Acomply+label%%3Aprocedure", g.username, g.reponame)
links.ProcedureOpen = fmt.Sprintf("https://github.com/%s/%s/issues?q=is%3Aissue+is%3Aopen+label%3Acomply+label%3Aprocedure", g.username, g.reponame) links.ProcedureOpen = fmt.Sprintf("https://github.com/%s/%s/issues?q=is%%3Aissue+is%%3Aopen+label%%3Acomply+label%%3Aprocedure", g.username, g.reponame)
return links return links
} }

View File

@@ -82,7 +82,7 @@ func html(output string, live bool, errCh chan error, wg *sync.WaitGroup) {
if live { if live {
if !opened { if !opened {
opened = true opened = true
open.Run("output/index.html") open.Run(filepath.Join(".", "output", "index.html"))
} }
} else { } else {
wg.Done() wg.Done()