Skip to content

Commit

Permalink
ci: add Makefile and github ci flow
Browse files Browse the repository at this point in the history
  • Loading branch information
saitofun committed Jun 2, 2024
1 parent 02e2ef2 commit 9f05f45
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ci

on:
push:
branches: [ "main" ]
tags: [ "v*.*.*" ]
pull_request:
branches: [ "main" ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22'

- name: Test
run: make cover

- name: Coverage report
uses: codecov/codecov-action@v4
with:
token: ${{secrets.CODECOV_TOKEN}}
file: ./cover.out
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
PACKAGES=`go list ./... | grep -E -v 'example|proto'`
FORMAT_FILES=`find . -type f -name '*.go' | grep -E -v '_generated.go|.pb.go'`
XGO_OK=$(shell type xgo > /dev/null 2>&1 && echo $$?)

xgo:
@if [ "${XGO_OK}" != "0" ]; then \
echo "installing xgo for unit test"; \
go install github.com/xhd2015/xgo/cmd/xgo@latest; \
fi

tidy:
go mod tidy

cover: xgo tidy
xgo test -failfast ${PACKAGES} -coverprofile=cover.out -covermode=count


test: tidy
xgo test -race -failfast ${PACKAGES}

report:
@echo ">>>static checking"
@go vet ./...
@echo "done\n"
@echo ">>>detecting ineffectual assignments"
@ineffassign ./...
@echo "done\n"
@echo ">>>detecting icyclomatic complexities over 10 and average"
@gocyclo -over 10 -avg -ignore '_test|vendor' . || true
@echo "done\n"

MOD=$(shell cat go.mod | grep ^module -m 1 | awk '{ print $$2; }' || '')
FILE_LIST=$(shell find . -type f -name '*.go' | grep -E -v '_generated.go|.pb.go')

.PHONY: fmt
fmt:
@echo ${MOD}
@for item in ${FILE_LIST} ; \
do \
if [ -z ${MOD} ]; then \
goimports -d -w $$item ; \
else \
goimports -d -w -local "${MOD}" $$item ; \
fi \
done


0 comments on commit 9f05f45

Please sign in to comment.