Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lint, test coverage, CodeQL and basic CI GitHub Actions #1

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -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"]'
25 changes: 25 additions & 0 deletions .github/workflows/go-test-coverage.yml
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -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 ./...
28 changes: 28 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ go.work.sum
# env file
.env
deployment

# html file output from `make check-coverage`
cover.html
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
55 changes: 55 additions & 0 deletions config/.testcoverage.yml
Original file line number Diff line number Diff line change
@@ -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: ''