Skip to content

Commit

Permalink
main: add support for github actions
Browse files Browse the repository at this point in the history
Fixes #48

now with logic to detect GITHUB_SHA env variable, let's do a run without
the `-range` flag so that path lights up.

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
  • Loading branch information
vbatts committed May 14, 2021
1 parent 5fd8690 commit f025c31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ jobs:
go vet -x ./...
go build -v .
go test -v ./...
./git-validation -run DCO,short-subject,dangling-whitespace -v
./git-validation -run DCO,short-subject,dangling-whitespace -v -range ${GITHUB_SHA}..HEAD
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
flDebug = flag.Bool("D", false, "debug output")
flQuiet = flag.Bool("q", false, "less output")
flDir = flag.String("d", ".", "git directory to validate from")
flNoGithub = flag.Bool("no-github", false, "disables Github Actions environment checks (when env GITHUB_ACTIONS=true is set)")
flNoTravis = flag.Bool("no-travis", false, "disables travis environment checks (when env TRAVIS=true is set)")
flTravisPROnly = flag.Bool("travis-pr-only", true, "when on travis, only run validations if the CI-Build is checking pull-request build")
)
Expand Down Expand Up @@ -73,6 +74,14 @@ func main() {
commitRange = os.Getenv("TRAVIS_COMMIT")
}
}
// https://docs.github.com/en/actions/reference/environment-variables
if strings.ToLower(os.Getenv("GITHUB_ACTIONS")) == "true" && !*flNoGithub {
head := "HEAD"
if os.Getenv("GITHUB_HEAD_REF") != "" {
head = os.Getenv("GITHUB_HEAD_REF")
}
commitRange = fmt.Sprintf("%s..%s", os.Getenv("GITHUB_SHA"), head)
}
}

runner, err := validate.NewRunner(*flDir, rules, commitRange, *flVerbose)
Expand Down

0 comments on commit f025c31

Please sign in to comment.