diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..aa4c8f4 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,15 @@ +name: CodeQL analysis + +on: + push: + pull_request: + branches: [ "main" ] + schedule: + - cron: '0 3 * * 0' + +jobs: + call-codeQL-analysis: + name: CodeQL analysis + uses: actions/reusable-workflows/.github/workflows/codeql-analysis.yml@main + with: + languages: '["go"]' \ No newline at end of file diff --git a/.github/workflows/go-test-coverage.yml b/.github/workflows/go-test-coverage.yml new file mode 100644 index 0000000..cc802f4 --- /dev/null +++ b/.github/workflows/go-test-coverage.yml @@ -0,0 +1,25 @@ +name: go-test-coverage + +on: + push: + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [ stable ] + steps: + - uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + - name: generate test coverage + run: make check-coverage + - name: check test coverage + uses: vladopajic/go-test-coverage@v2 + with: + config: ./config/.testcoverage.yml \ No newline at end of file diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..f8f1aa0 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,23 @@ +name: CI + +on: + push: + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [ stable ] + steps: + - uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + - name: Build + run: go build ./... + - name: Test + run: go test -v ./... \ No newline at end of file diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..bc2eec8 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,28 @@ +name: golangci-lint + +on: + push: + pull_request: + branches: [ "main" ] + +permissions: + contents: read + pull-requests: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [ stable ] + steps: + - uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: latest \ No newline at end of file diff --git a/.gitignore b/.gitignore index 889f480..99057d1 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ go.work.sum # env file .env deployment + +# html file output from `make check-coverage` +cover.html diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..43ea531 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +GOBIN ?= $$(go env GOPATH)/bin + +.PHONY: install-go-test-coverage +install-go-test-coverage: + go install github.com/vladopajic/go-test-coverage/v2@latest + +.PHONY: check-coverage +check-coverage: install-go-test-coverage + go test ./... -coverprofile=./cover.out -covermode=set -coverpkg=./... + go tool cover -html=./cover.out -o=./cover.html + ${GOBIN}/go-test-coverage --config=./config/.testcoverage.yml diff --git a/config/.testcoverage.yml b/config/.testcoverage.yml new file mode 100644 index 0000000..8cb93b1 --- /dev/null +++ b/config/.testcoverage.yml @@ -0,0 +1,55 @@ +# (mandatory) +# Path to coverage profile file (output of `go test -coverprofile` command). +# +# For cases where there are many coverage profiles, such as when running +# unit tests and integration tests separately, you can combine all those +# profiles into one. In this case, the profile should have a comma-separated list +# of profile files, e.g., 'cover_unit.out,cover_integration.out'. +profile: ./cover.out + +# (optional; but recommended to set) +# When specified reported file paths will not contain local prefix in the output. +local-prefix: '' + +# Holds coverage thresholds percentages, values should be in range [0-100]. +threshold: + # (optional; default 0) + # Minimum coverage percentage required for individual files. + file: 80 + + # (optional; default 0) + # Minimum coverage percentage required for each package. + package: 80 + + # (optional; default 0) + # Minimum overall project coverage percentage required. + total: 95 + +# Holds regexp rules which will override thresholds for matched files or packages +# using their paths. +# +# First rule from this list that matches file or package is going to apply +# new threshold to it. If project has multiple rules that match same path, +# override rules should be listed in order from specific to more general rules. +override: + # Increase coverage threshold to 100% for `foo` package + # (default is 80, as configured above in this example). + - path: ^pkg/lib/foo$ + threshold: 100 + +# Holds regexp rules which will exclude matched files or packages +# from coverage statistics. +exclude: + # Exclude files or packages matching their paths + paths: + - \.pb\.go$ # excludes all protobuf generated files + - ^pkg/bar # exclude package `pkg/bar` + +# File name of go-test-coverage breakdown file, which can be used to +# analyze coverage difference. +breakdown-file-name: '' + +diff: + # File name of go-test-coverage breakdown file which will be used to + # report coverage difference. + base-breakdown-file-name: '' \ No newline at end of file