From 59392066c4ac1d2ad9644a90ab71c315226dafd7 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Thu, 13 May 2021 07:58:24 -0400 Subject: [PATCH] main: add support for github actions 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 --- .github/workflows/go.yml | 1 + main.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 9077ed8..bb4be17 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -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 diff --git a/main.go b/main.go index cd5f271..1a34d7f 100644 --- a/main.go +++ b/main.go @@ -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") ) @@ -73,6 +74,10 @@ 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 { + commitRange = fmt.Sprintf("%s..%s", os.Getenv("GITHUB_SHA"), "HEAD") + } } runner, err := validate.NewRunner(*flDir, rules, commitRange, *flVerbose)