-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
187 additions
and
35 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,66 @@ | ||
# This workflow will build a golang project | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | ||
|
||
name: ci | ||
|
||
on: [push, pull_request] | ||
env: | ||
GO_VERSION: '1.21' | ||
|
||
jobs: | ||
# Check if there is any dirty change for go mod tidy | ||
go-mod: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
# https://github.com/actions/setup-go#supported-version-syntax | ||
# ex: | ||
# - 1.18beta1 -> 1.18.0-beta.1 | ||
# - 1.18rc1 -> 1.18.0-rc.1 | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Check go mod | ||
run: | | ||
go mod tidy | ||
git diff --exit-code go.mod | ||
git diff --exit-code go.sum | ||
test: | ||
runs-on: ubuntu-latest | ||
needs: go-mod | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Run Unit tests. | ||
run: make test | ||
format: | ||
runs-on: ubuntu-latest | ||
needs: test | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: format Go Code | ||
run: make format | ||
lint: | ||
runs-on: ubuntu-latest | ||
needs: format | ||
steps: | ||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Lint Go 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
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,71 @@ | ||
GO := go | ||
ROOT_PACKAGE := github.com/seacraft/log | ||
ifeq ($(origin ROOT_DIR),undefined) | ||
ROOT_DIR := $(shell pwd) | ||
endif | ||
|
||
# Linux command settings | ||
FIND := find . ! -path './third_party/*' ! -path './vendor/*' | ||
XARGS := xargs --no-run-if-empty | ||
|
||
all: test format lint | ||
|
||
## test: Test the package. | ||
.PHONY: test | ||
test: | ||
@echo "===========> Testing packages" | ||
@$(GO) test $(ROOT_PACKAGE)/... | ||
|
||
.PHONY: goimports.verify | ||
goimports.verify: | ||
ifeq (,$(shell which goimports 2>/dev/null)) | ||
@echo "===========> Installing goimports" | ||
@$(GO) install golang.org/x/tools/cmd/goimports@v0.17.0 | ||
endif | ||
|
||
.PHONY: golines.verify | ||
golines.verify: | ||
ifeq (,$(shell which golines 2>/dev/null)) | ||
@echo "===========> Installing golines" | ||
@$(GO) install github.com/segmentio/golines@v0.12.2 | ||
endif | ||
|
||
## format: Format the package with `gofmt` | ||
.PHONY: format | ||
format: golines.verify goimports.verify | ||
@echo "===========> Formating codes" | ||
@$(FIND) -type f -name '*.go' | $(XARGS) gofmt -s -w | ||
@$(FIND) -type f -name '*.go' | $(XARGS) goimports -w -local $(ROOT_PACKAGE) | ||
@$(FIND) -type f -name '*.go' | $(XARGS) golines -w --max-len=120 --reformat-tags --shorten-comments --ignore-generated . | ||
|
||
.PHONY: lint.verify | ||
lint.verify: | ||
ifeq (,$(shell which golangci-lint 2>/dev/null)) | ||
@echo "===========> Installing golangci lint" | ||
@$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.1 | ||
endif | ||
|
||
## lint: Check syntax and styling of go sources. | ||
.PHONY: lint | ||
lint: lint.verify | ||
@echo "===========> Run golangci to lint source codes" | ||
@golangci-lint run $(ROOT_DIR)/... | ||
|
||
.PHONY: updates.verify | ||
updates.verify: | ||
ifeq (,$(shell which go-mod-outdated 2>/dev/null)) | ||
@echo "===========> Installing go-mod-outdated" | ||
@$(GO) install github.com/psampaz/go-mod-outdated@v0.9.0 | ||
endif | ||
|
||
## check-updates: Check outdated dependencies of the go projects. | ||
.PHONY: check-updates | ||
check-updates: updates.verify | ||
@$(GO) list -u -m -json all | go-mod-outdated -update -direct | ||
|
||
## help: Show this help info. | ||
.PHONY: help | ||
help: Makefile | ||
@echo -e "\nUsage: make <TARGETS> ...\n\nTargets:" | ||
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' | ||
@echo "$$USAGE_OPTIONS" |
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/seacraft/log/example | ||
|
||
go 1.20 | ||
go 1.21 | ||
|
||
require ( | ||
github.com/seacraft/log v1.0.0 | ||
|
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 |
---|---|---|
@@ -1,17 +1,19 @@ | ||
module github.com/seacraft/log | ||
|
||
go 1.20 | ||
go 1.21 | ||
|
||
require ( | ||
github.com/sirupsen/logrus v1.9.3 | ||
github.com/spf13/pflag v1.0.5 | ||
github.com/stretchr/testify v1.8.4 | ||
go.uber.org/zap v1.26.0 | ||
k8s.io/klog v1.0.0 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/sirupsen/logrus v1.9.3 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/stretchr/objx v0.5.0 // indirect | ||
github.com/stretchr/testify v1.8.4 // indirect | ||
go.uber.org/multierr v1.10.0 // indirect | ||
go.uber.org/zap v1.26.0 // indirect | ||
go.uber.org/multierr v1.11.0 // indirect | ||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
k8s.io/klog v1.0.0 // indirect | ||
) |
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
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
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
Oops, something went wrong.