Skip to content

Commit

Permalink
add pre-submit checks (#22)
Browse files Browse the repository at this point in the history
Also advertise the new feature in the README

Fixes #6
  • Loading branch information
thomas-fossati authored Sep 7, 2021
1 parent 8bbb616 commit 0446ddb
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
.DEFAULT_GOAL := help

SHELL := /bin/bash

GO111MODULE := on

GOPKG := github.com/veraison/swid

GOLINT ?= golangci-lint

ifeq ($(MAKECMDGOALS),lint)
GOLINT_ARGS ?= run --timeout=3m
else
ifeq ($(MAKECMDGOALS),lint-extra)
GOLINT_ARGS ?= run --timeout=3m --issues-exit-code=0 -E dupl -E gocritic -E gosimple -E lll -E prealloc
endif
endif

.PHONY: lint lint-extra
lint lint-extra: ; $(GOLINT) $(GOLINT_ARGS)

ifeq ($(MAKECMDGOALS),test)
GOTEST_ARGS ?= -v -race $(GOPKG)
else
ifeq ($(MAKECMDGOALS),test-cover)
GOTEST_ARGS ?= -short -cover $(GOPKG)
endif
endif

COVER_THRESHOLD := $(shell grep '^name: cover' .github/workflows/ci-go-cover.yml | cut -c13-)

.PHONY: test test-cover
test test-cover: ; go test $(GOTEST_ARGS)

presubmit:
@echo
@echo ">>> Check that the reported coverage figures are $(COVER_THRESHOLD)"
@echo
$(MAKE) test-cover
@echo
@echo ">>> Fix any lint error"
@echo
$(MAKE) lint

.PHONY: help
help:
@echo "Available targets:"
@echo " * test: run unit tests for $(GOPKG)"
@echo " * test-cover: run unit tests and measure coverage for $(GOPKG)"
@echo " * lint: lint sources using default configuration"
@echo " * lint-extra: lint sources using default configuration and some extra checkers"
@echo " * presubmit: check you are ready to push your local branch to remote"
@echo " * help: print this menu"
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ The `swid` package provides a golang API for manipulating Software Identificatio
## Resources

* [Package Documentation](https://pkg.go.dev/github.com/veraison/swid)

## Developer tips

Before doing a PR (and routinely during the dev/test cycle) run
```
make presubmit
```
and check its output to make sure your code coverage figures are in line with the target and that there are no newly introduced lint problems.

0 comments on commit 0446ddb

Please sign in to comment.