Skip to content

Commit

Permalink
Add Github Actions for linting (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Roland Schaer authored Apr 18, 2022
1 parent 19d93a0 commit 8588275
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/lint.yml
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
56 changes: 56 additions & 0 deletions .github/workflows/test.yml
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ vendor/
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Unit tests and coverage reports
profile.cov
report.xml

### Intellij ###
# User-specific stuff:
.idea/
Expand Down
55 changes: 55 additions & 0 deletions Makefile
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)
1 change: 1 addition & 0 deletions output/tableoutput_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var asciiTpl = `+-------------------------------------+
`

//lint:ignore ST1018 stick to unicode characters for test output
var tableTpl = `%s
 DESCRIPTION  KEY  VALUE  TYPE 
 sensor  key  value  type 
Expand Down

0 comments on commit 8588275

Please sign in to comment.