Skip to content

Commit

Permalink
Flags to update either coverage image, or update markdown files for c…
Browse files Browse the repository at this point in the history
…overage.
  • Loading branch information
jpoles1 committed Jul 15, 2018
1 parent 74f957f commit a098e08
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# GopherBadger
### Generate coverage badge images using Go!

![gopherbadger-tag-do-not-edit](https://img.shields.io/badge/Coverage-71%-brightgreen.svg?longCache=true&style=flat)
![gopherbadger-tag-do-not-edit](https://img.shields.io/badge/Coverage-67%-brightgreen.svg?longCache=true&style=flat)

One day, I noticed that there was no easy way to generate coverage badges for my Golang projects. So I made one (see above)!

Expand Down
1 change: 1 addition & 0 deletions badge.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ func drawBadge(coveragePct float64, filename string) error {
//Save to file
err = dc.SavePNG(filename)
errCheck("Saving image file", err)
fmt.Println("Saved badge to file: " + filename)
return err
}
Binary file modified coverage_badge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"flag"
"fmt"
"io"
"io/ioutil"
Expand All @@ -10,6 +11,7 @@ import (
"os/exec"
"regexp"
"strconv"
"strings"

"github.com/fatih/color"
)
Expand Down Expand Up @@ -66,10 +68,20 @@ func writeBadgeToMd(coverageFloat float64, filepath string) {
if err != nil {
log.Fatal("Error: could not write shield url to markdown file: ", err)
}
fmt.Println("Wrote badge image to markdown file: " + filepath)
}
func main() {
badgeOutputFlag := flag.Bool("png", true, "Boolean to decide if .png will be generated by the software")
updateMdFilesFlag := flag.String("md", "", "A list of markdown filepaths for badge updates.")
flag.Parse()
var coverageFloat float64
coverageFloat = <-getCommandOutput("go test ./... -coverprofile=coverage.out && go tool cover -func=coverage.out")
drawBadge(coverageFloat, "coverage_badge.png")
writeBadgeToMd(coverageFloat, "./README.md")
if *badgeOutputFlag == true {
drawBadge(coverageFloat, "coverage_badge.png")
}
if *updateMdFilesFlag != "" {
for _, filepath := range strings.Split(*updateMdFilesFlag, ",") {
writeBadgeToMd(coverageFloat, filepath)
}
}
}

0 comments on commit a098e08

Please sign in to comment.