mirror of
https://github.com/romdo/go-conventionalcommit.git
synced 2026-02-19 08:06:41 +00:00
ci(github): setup GitHub Actions
This commit is contained in:
145
.github/workflows/ci.yml
vendored
Normal file
145
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
---
|
||||||
|
name: CI
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
name: Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v2
|
||||||
|
with:
|
||||||
|
version: v1.41
|
||||||
|
env:
|
||||||
|
VERBOSE: "true"
|
||||||
|
|
||||||
|
tidy:
|
||||||
|
name: Tidy
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.15
|
||||||
|
- uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
- name: Check if mods are tidy
|
||||||
|
run: make check-tidy
|
||||||
|
|
||||||
|
benchmark:
|
||||||
|
name: Benchmarks
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.ref != 'refs/heads/main'
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.15
|
||||||
|
- uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
- name: Run benchmarks
|
||||||
|
run: make bench | tee output.raw
|
||||||
|
- name: Fix benchmark names
|
||||||
|
run: >-
|
||||||
|
perl -pe 's/^(Benchmark.+?)\/(\S+)(-\d+)(\s+)/\1__\2\4/' output.raw |
|
||||||
|
tr '-' '_' | tee output.txt
|
||||||
|
- name: Announce benchmark result
|
||||||
|
uses: rhysd/github-action-benchmark@v1
|
||||||
|
with:
|
||||||
|
tool: "go"
|
||||||
|
output-file-path: output.txt
|
||||||
|
fail-on-alert: true
|
||||||
|
comment-on-alert: true
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
auto-push: false
|
||||||
|
|
||||||
|
cov:
|
||||||
|
name: Coverage
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.15
|
||||||
|
- uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
- name: Publish coverage
|
||||||
|
uses: paambaati/codeclimate-action@v2.7.4
|
||||||
|
env:
|
||||||
|
VERBOSE: "true"
|
||||||
|
GOMAXPROCS: 4
|
||||||
|
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
||||||
|
with:
|
||||||
|
coverageCommand: make cov
|
||||||
|
prefix: github.com/${{ github.repository }}
|
||||||
|
coverageLocations: |
|
||||||
|
${{ github.workspace }}/coverage.out:gocov
|
||||||
|
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
go_version:
|
||||||
|
- "1.15"
|
||||||
|
- "1.16"
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.terraform_version }}
|
||||||
|
- uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
- name: Run tests
|
||||||
|
run: make test
|
||||||
|
env:
|
||||||
|
VERBOSE: "true"
|
||||||
|
|
||||||
|
benchmark-store:
|
||||||
|
name: Store benchmarks
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.ref == 'refs/heads/main'
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: 1.15
|
||||||
|
- uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
- name: Run benchmarks
|
||||||
|
run: make bench | tee output.raw
|
||||||
|
- name: Fix benchmark names
|
||||||
|
run: >-
|
||||||
|
perl -pe 's/^(Benchmark.+?)\/(\S+)(-\d+)(\s+)/\1__\2\4/' output.raw |
|
||||||
|
tr '-' '_' | tee output.txt
|
||||||
|
- name: Store benchmark result
|
||||||
|
uses: rhysd/github-action-benchmark@v1
|
||||||
|
with:
|
||||||
|
tool: "go"
|
||||||
|
output-file-path: output.txt
|
||||||
|
github-token: ${{ secrets.ROMDOBOT_TOKEN }}
|
||||||
|
comment-on-alert: true
|
||||||
|
auto-push: true
|
||||||
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
/*.tidy-check
|
||||||
|
/bin/*
|
||||||
|
/coverage.out
|
||||||
|
/output.txt
|
||||||
93
.golangci.yml
Normal file
93
.golangci.yml
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
linters-settings:
|
||||||
|
funlen:
|
||||||
|
lines: 100
|
||||||
|
statements: 150
|
||||||
|
goconst:
|
||||||
|
min-occurrences: 5
|
||||||
|
gocyclo:
|
||||||
|
min-complexity: 20
|
||||||
|
golint:
|
||||||
|
min-confidence: 0
|
||||||
|
govet:
|
||||||
|
check-shadowing: true
|
||||||
|
enable-all: true
|
||||||
|
disable:
|
||||||
|
- fieldalignment
|
||||||
|
lll:
|
||||||
|
line-length: 80
|
||||||
|
tab-width: 4
|
||||||
|
maligned:
|
||||||
|
suggest-new: true
|
||||||
|
misspell:
|
||||||
|
locale: US
|
||||||
|
|
||||||
|
linters:
|
||||||
|
disable-all: true
|
||||||
|
enable:
|
||||||
|
- asciicheck
|
||||||
|
- bodyclose
|
||||||
|
- deadcode
|
||||||
|
- depguard
|
||||||
|
- dupl
|
||||||
|
- durationcheck
|
||||||
|
- errcheck
|
||||||
|
- errorlint
|
||||||
|
- exhaustive
|
||||||
|
- exportloopref
|
||||||
|
- funlen
|
||||||
|
- gochecknoinits
|
||||||
|
- goconst
|
||||||
|
- gocritic
|
||||||
|
- gocyclo
|
||||||
|
- godot
|
||||||
|
- gofumpt
|
||||||
|
- goimports
|
||||||
|
- goprintffuncname
|
||||||
|
- gosec
|
||||||
|
- gosimple
|
||||||
|
- govet
|
||||||
|
- importas
|
||||||
|
- ineffassign
|
||||||
|
- lll
|
||||||
|
- misspell
|
||||||
|
- nakedret
|
||||||
|
- nilerr
|
||||||
|
- noctx
|
||||||
|
- nolintlint
|
||||||
|
- prealloc
|
||||||
|
- predeclared
|
||||||
|
- revive
|
||||||
|
- rowserrcheck
|
||||||
|
- sqlclosecheck
|
||||||
|
- staticcheck
|
||||||
|
- structcheck
|
||||||
|
- tparallel
|
||||||
|
- typecheck
|
||||||
|
- unconvert
|
||||||
|
- unparam
|
||||||
|
- unused
|
||||||
|
- varcheck
|
||||||
|
- wastedassign
|
||||||
|
- whitespace
|
||||||
|
|
||||||
|
issues:
|
||||||
|
exclude:
|
||||||
|
- Using the variable on range scope `tt` in function literal
|
||||||
|
- Using the variable on range scope `tc` in function literal
|
||||||
|
exclude-rules:
|
||||||
|
- path: "_test\\.go"
|
||||||
|
linters:
|
||||||
|
- funlen
|
||||||
|
- dupl
|
||||||
|
- goconst
|
||||||
|
- source: "^//go:generate "
|
||||||
|
linters:
|
||||||
|
- lll
|
||||||
|
- source: "`json:"
|
||||||
|
linters:
|
||||||
|
- lll
|
||||||
|
|
||||||
|
run:
|
||||||
|
timeout: 2m
|
||||||
|
allow-parallel-runners: true
|
||||||
|
modules-download-mode: readonly
|
||||||
192
Makefile
Normal file
192
Makefile
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
GOMODNAME := $(shell grep 'module' go.mod | sed -e 's/^module //')
|
||||||
|
SOURCES := $(shell find . -name "*.go" -or -name "go.mod" -or -name "go.sum" \
|
||||||
|
-or -name "Makefile")
|
||||||
|
|
||||||
|
# Verbose output
|
||||||
|
ifdef VERBOSE
|
||||||
|
V = -v
|
||||||
|
endif
|
||||||
|
|
||||||
|
#
|
||||||
|
# Environment
|
||||||
|
#
|
||||||
|
|
||||||
|
BINDIR := bin
|
||||||
|
TOOLDIR := $(BINDIR)/tools
|
||||||
|
|
||||||
|
# Global environment variables for all targets
|
||||||
|
SHELL ?= /bin/bash
|
||||||
|
SHELL := env \
|
||||||
|
GO111MODULE=on \
|
||||||
|
GOBIN=$(CURDIR)/$(TOOLDIR) \
|
||||||
|
CGO_ENABLED=1 \
|
||||||
|
PATH='$(CURDIR)/$(BINDIR):$(CURDIR)/$(TOOLDIR):$(PATH)' \
|
||||||
|
$(SHELL)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Defaults
|
||||||
|
#
|
||||||
|
|
||||||
|
# Default target
|
||||||
|
.DEFAULT_GOAL := test
|
||||||
|
|
||||||
|
#
|
||||||
|
# Tools
|
||||||
|
#
|
||||||
|
|
||||||
|
TOOLS += $(TOOLDIR)/gobin
|
||||||
|
$(TOOLDIR)/gobin:
|
||||||
|
GO111MODULE=off go get -u github.com/myitcv/gobin
|
||||||
|
|
||||||
|
# external tool
|
||||||
|
define tool # 1: binary-name, 2: go-import-path
|
||||||
|
TOOLS += $(TOOLDIR)/$(1)
|
||||||
|
|
||||||
|
$(TOOLDIR)/$(1): $(TOOLDIR)/gobin Makefile
|
||||||
|
gobin $(V) "$(2)"
|
||||||
|
endef
|
||||||
|
|
||||||
|
$(eval $(call tool,godoc,golang.org/x/tools/cmd/godoc))
|
||||||
|
$(eval $(call tool,gofumports,mvdan.cc/gofumpt/gofumports))
|
||||||
|
$(eval $(call tool,golangci-lint,github.com/golangci/golangci-lint/cmd/golangci-lint@v1.41))
|
||||||
|
$(eval $(call tool,gomod,github.com/Helcaraxan/gomod))
|
||||||
|
|
||||||
|
.PHONY: tools
|
||||||
|
tools: $(TOOLS)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Development
|
||||||
|
#
|
||||||
|
|
||||||
|
BENCH ?= .
|
||||||
|
TESTARGS ?=
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
rm -f $(TOOLS)
|
||||||
|
rm -f ./coverage.out ./go.mod.tidy-check ./go.sum.tidy-check
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test:
|
||||||
|
go test $(V) -count=1 -race $(TESTARGS) ./...
|
||||||
|
|
||||||
|
.PHONY: test-deps
|
||||||
|
test-deps:
|
||||||
|
go test all
|
||||||
|
|
||||||
|
.PHONY: lint
|
||||||
|
lint: $(TOOLDIR)/golangci-lint
|
||||||
|
golangci-lint $(V) run
|
||||||
|
|
||||||
|
.PHONY: format
|
||||||
|
format: $(TOOLDIR)/gofumports
|
||||||
|
gofumports -w .
|
||||||
|
|
||||||
|
.SILENT: bench
|
||||||
|
.PHONY: bench
|
||||||
|
bench:
|
||||||
|
go test $(V) -count=1 -bench=$(BENCH) $(TESTARGS) ./...
|
||||||
|
|
||||||
|
#
|
||||||
|
# Code Generation
|
||||||
|
#
|
||||||
|
|
||||||
|
.PHONY: generate
|
||||||
|
generate:
|
||||||
|
go generate ./...
|
||||||
|
|
||||||
|
.PHONY: check-generate
|
||||||
|
check-generate:
|
||||||
|
$(eval CHKDIR := $(shell mktemp -d))
|
||||||
|
cp -av . "$(CHKDIR)"
|
||||||
|
make -C "$(CHKDIR)/" generate
|
||||||
|
( diff -rN . "$(CHKDIR)" && rm -rf "$(CHKDIR)" ) || \
|
||||||
|
( rm -rf "$(CHKDIR)" && exit 1 )
|
||||||
|
|
||||||
|
#
|
||||||
|
# Coverage
|
||||||
|
#
|
||||||
|
|
||||||
|
.PHONY: cov
|
||||||
|
cov: coverage.out
|
||||||
|
|
||||||
|
.PHONY: cov-html
|
||||||
|
cov-html: coverage.out
|
||||||
|
go tool cover -html=./coverage.out
|
||||||
|
|
||||||
|
.PHONY: cov-func
|
||||||
|
cov-func: coverage.out
|
||||||
|
go tool cover -func=./coverage.out
|
||||||
|
|
||||||
|
coverage.out: $(SOURCES)
|
||||||
|
go test $(V) -covermode=count -coverprofile=./coverage.out ./...
|
||||||
|
|
||||||
|
#
|
||||||
|
# Dependencies
|
||||||
|
#
|
||||||
|
|
||||||
|
.PHONY: deps
|
||||||
|
deps:
|
||||||
|
go mod download
|
||||||
|
|
||||||
|
.PHONY: deps-update
|
||||||
|
deps-update:
|
||||||
|
go get -u -t ./...
|
||||||
|
|
||||||
|
.PHONY: deps-analyze
|
||||||
|
deps-analyze: $(TOOLDIR)/gomod
|
||||||
|
gomod analyze
|
||||||
|
|
||||||
|
.PHONY: tidy
|
||||||
|
tidy:
|
||||||
|
go mod tidy $(V)
|
||||||
|
|
||||||
|
.PHONY: verify
|
||||||
|
verify:
|
||||||
|
go mod verify
|
||||||
|
|
||||||
|
.SILENT: check-tidy
|
||||||
|
.PHONY: check-tidy
|
||||||
|
check-tidy:
|
||||||
|
cp go.mod go.mod.tidy-check
|
||||||
|
cp go.sum go.sum.tidy-check
|
||||||
|
go mod tidy
|
||||||
|
( \
|
||||||
|
diff go.mod go.mod.tidy-check && \
|
||||||
|
diff go.sum go.sum.tidy-check && \
|
||||||
|
rm -f go.mod go.sum && \
|
||||||
|
mv go.mod.tidy-check go.mod && \
|
||||||
|
mv go.sum.tidy-check go.sum \
|
||||||
|
) || ( \
|
||||||
|
rm -f go.mod go.sum && \
|
||||||
|
mv go.mod.tidy-check go.mod && \
|
||||||
|
mv go.sum.tidy-check go.sum; \
|
||||||
|
exit 1 \
|
||||||
|
)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Documentation
|
||||||
|
#
|
||||||
|
|
||||||
|
# Serve docs
|
||||||
|
.PHONY: docs
|
||||||
|
docs: godoc
|
||||||
|
$(info serviing docs on http://127.0.0.1:6060/pkg/$(GOMODNAME)/)
|
||||||
|
@godoc -http=127.0.0.1:6060
|
||||||
|
|
||||||
|
#
|
||||||
|
# Release
|
||||||
|
#
|
||||||
|
|
||||||
|
.PHONY: new-version
|
||||||
|
new-version: check-npx
|
||||||
|
npx standard-version
|
||||||
|
|
||||||
|
.PHONY: next-version
|
||||||
|
next-version: check-npx
|
||||||
|
npx standard-version --dry-run
|
||||||
|
|
||||||
|
.PHONY: check-npx
|
||||||
|
check-npx:
|
||||||
|
$(if $(shell which npx),,\
|
||||||
|
$(error No npx found in PATH, please install NodeJS))
|
||||||
Reference in New Issue
Block a user