Skip to content

Commit 854d4a2

Browse files
committed
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 <vbatts@hashbangbash.com>
1 parent 5fd8690 commit 854d4a2

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ jobs:
3434
go vet -x ./...
3535
go build -v .
3636
go test -v ./...
37+
./git-validation -run DCO,short-subject,dangling-whitespace -v
3738
./git-validation -run DCO,short-subject,dangling-whitespace -v -range ${GITHUB_SHA}..HEAD

main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var (
2222
flDebug = flag.Bool("D", false, "debug output")
2323
flQuiet = flag.Bool("q", false, "less output")
2424
flDir = flag.String("d", ".", "git directory to validate from")
25+
flNoGithub = flag.Bool("no-github", false, "disables Github Actions environment checks (when env GITHUB_ACTIONS=true is set)")
2526
flNoTravis = flag.Bool("no-travis", false, "disables travis environment checks (when env TRAVIS=true is set)")
2627
flTravisPROnly = flag.Bool("travis-pr-only", true, "when on travis, only run validations if the CI-Build is checking pull-request build")
2728
)
@@ -73,6 +74,14 @@ func main() {
7374
commitRange = os.Getenv("TRAVIS_COMMIT")
7475
}
7576
}
77+
// https://docs.github.com/en/actions/reference/environment-variables
78+
if strings.ToLower(os.Getenv("GITHUB_ACTIONS")) == "true" && !*flNoGithub {
79+
head = "HEAD"
80+
if os.Getenv("GITHUB_HEAD_REF") != "" {
81+
head = os.Getenv("GITHUB_HEAD_REF")
82+
}
83+
commitRange = fmt.Sprintf("%s..%s", os.Getenv("GITHUB_SHA"), head)
84+
}
7685
}
7786

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

0 commit comments

Comments
 (0)