-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Github Actions for linting (#13)
- Loading branch information
Roland Schaer
authored
Apr 18, 2022
1 parent
19d93a0
commit 8588275
Showing
5 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Lint | ||
|
||
env: | ||
GO_VERSION: 1.18 | ||
|
||
permissions: | ||
contents: read | ||
|
||
on: | ||
push: | ||
branches: | ||
- issue/gh-actions | ||
# paths: | ||
# - "**.go" | ||
# - go.mod | ||
# - go.sum | ||
pull_request: | ||
# paths: | ||
# - "**.go" | ||
# - go.mod | ||
# - go.sum | ||
|
||
jobs: | ||
|
||
lint: | ||
name: Lint | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
|
||
- name: Set Go Cache Paths | ||
id: go-cache-paths | ||
run: | | ||
echo "::set-output name=go-mod::$(go env GOMODCACHE)" | ||
- name: Restore Go Modules Cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.go-cache-paths.outputs.go-mod }} | ||
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} | ||
|
||
- name: Verify modules | ||
run: | | ||
make verify | ||
- name: Lint code | ||
run: | | ||
make lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Test | ||
|
||
env: | ||
GO_VERSION: 1.18 | ||
|
||
permissions: | ||
contents: read | ||
|
||
on: | ||
push: | ||
branches: | ||
- issue/gh-actions | ||
# on: [push, pull_request] | ||
|
||
jobs: | ||
|
||
test: | ||
name: Test | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
|
||
- name: Set Go Cache Paths | ||
id: go-cache-paths | ||
run: | | ||
echo "::set-output name=go-build::$(go env GOCACHE)" | ||
echo "::set-output name=go-mod::$(go env GOMODCACHE)" | ||
- name: Restore Go Cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.go-cache-paths.outputs.go-build }} | ||
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} | ||
|
||
- name: Restore Go Modules Cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.go-cache-paths.outputs.go-mod }} | ||
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} | ||
|
||
- name: Verify modules | ||
run: | | ||
make verify | ||
- name: Run Tests | ||
run: | | ||
make test | ||
- name: Build binary | ||
run: | | ||
make build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
GREEN := $(shell tput -Txterm setaf 2) | ||
YELLOW := $(shell tput -Txterm setaf 3) | ||
WHITE := $(shell tput -Txterm setaf 7) | ||
CYAN := $(shell tput -Txterm setaf 6) | ||
RESET := $(shell tput -Txterm sgr0) | ||
|
||
GOTESTSUM_VERSION := v1.7.0 | ||
STATICCHECK_VERSION := 2022.1 | ||
|
||
# Suppress CGO compiler warnings | ||
export CGO_CFLAGS=-w | ||
|
||
.PHONY: all build test | ||
|
||
all: help | ||
|
||
## Targets: | ||
|
||
build: ## Build your project and put the output binary in out/bin/ | ||
@mkdir -p out/bin | ||
@go build -o out/bin/ . | ||
|
||
clean: ## Clean up task related files | ||
@rm -fr ./out | ||
@rm -f ./report.xml ./profile.cov | ||
|
||
verify: ## Verify dependencies | ||
@go mod verify | ||
@go mod download | ||
|
||
lint: ## Run linters | ||
@go install honnef.co/go/tools/cmd/staticcheck@${STATICCHECK_VERSION} | ||
|
||
@go mod tidy | ||
@git diff --exit-code go.mod | ||
|
||
@staticcheck ./... | ||
|
||
test: ## Run tests | ||
@go install gotest.tools/gotestsum@${GOTESTSUM_VERSION} | ||
@gotestsum -- -coverprofile=profile.cov ./... | ||
|
||
coverage: test ## Generate coverage report | ||
@go tool cover -html=profile.cov | ||
|
||
help: ## Show this help | ||
@echo '' | ||
@echo 'Usage:' | ||
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}' | ||
@echo '' | ||
@echo 'Targets:' | ||
@awk 'BEGIN {FS = ":.*?## "} { \ | ||
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \ | ||
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \ | ||
}' $(MAKEFILE_LIST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters