Skip to content

Commit c3db17c

Browse files
authored
Refine test coverage
1 parent 3226cb0 commit c3db17c

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ jobs:
2424
go-version: 1.14
2525
- name: Build
2626
run: make all
27+
- name: Upload coverage
28+
uses: actions/upload-artifact@v2
29+
with:
30+
name: coverage
31+
path: coverage.*
2732
- id: git-auto-tag
2833
name: Bump version and push tag
2934
uses: anothrNick/[email protected]
@@ -39,7 +44,8 @@ jobs:
3944
run: make release
4045
env:
4146
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42-
- uses: actions/upload-artifact@v2
47+
- name: Upload dist
48+
uses: actions/upload-artifact@v2
4349
with:
4450
name: dist
4551
path: dist

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313

1414
# Output of the go coverage tool, specifically when used with LiteIDE
1515
*.out
16+
coverage.html
1617

1718
# Dependency directories (remove the comment below to include it)
18-
# vendor/
19+
#vendor/
1920

2021
# Output of GoReleaser
2122
dist/
2223

23-
2424
# Visual Studio Code files
2525
.vscode/*
2626
!.vscode/settings.json

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ lint-fast: ## golangci-lint --fast
4848
.PHONY: test
4949
test: ## go test with race detector and code covarage
5050
$(call print-target)
51-
go test -race -covermode=atomic ./...
51+
go test -race -covermode=atomic -coverprofile=coverage.out ./...
52+
go tool cover -html=coverage.out -o coverage.html
5253

5354
.PHONY: mod-tidy
5455
mod-tidy: ## go mod tidy

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ This is a GitHub repository template for Go. It has been created for ease-of-use
1313

1414
It includes:
1515

16-
- [Visual Studio Code](https://code.visualstudio.com) configuration with [Go](https://code.visualstudio.com/docs/languages/go) and [Remote Container](https://code.visualstudio.com/docs/remote/containers) support,
16+
- continous integration via [GitHub Actions](https://github.com/features/actions),
17+
- build automation via [Make](https://www.gnu.org/software/make),
1718
- dependency management using [Go Modules](https://github.com/golang/go/wiki/Modules),
1819
- linting with [golangci-lint](https://github.com/golangci/golangci-lint),
19-
- build automation via [Make](https://www.gnu.org/software/make), [GitHub Actions](https://github.com/features/actions),
20+
- unit testing with [race detector](https://blog.golang.org/race-detector) and [code covarage HTML report](https://blog.golang.org/cover),
2021
- auto-tagging via [Github Tag Bump](https://github.com/marketplace/actions/github-tag-bump) GitHub Action,
21-
- releasing using [GoReleaser](https://github.com/goreleaser/goreleaser).
22+
- releasing using [GoReleaser](https://github.com/goreleaser/goreleaser),
23+
- depdendencies scanning and vulnerabilities alerting thanks to [Dependabot](https://dependabot.com/go/),
24+
- [Visual Studio Code](https://code.visualstudio.com) configuration with [Go](https://code.visualstudio.com/docs/languages/go) and [Remote Container](https://code.visualstudio.com/docs/remote/containers) support.
2225

2326
`Star` this repository if you find it valuable and worth maintaining.
2427

@@ -34,14 +37,13 @@ It includes:
3437
## Build
3538

3639
- Terminal: `make` to get help for make targets.
37-
- Terminal: `make all` to execute a full build.
3840
- Visual Studio Code: `Terminal``Run Build Task... (CTRL+ALT+B)` to execute a fast build.
3941

4042
## Release
4143

4244
The release workflow is triggered each time a tag with `v` prefix is pushed.
4345

44-
This repo uses [Github Tag Bump](https://github.com/marketplace/actions/github-tag-bump) for auto tagging on master branch. It automatically triggers the release workflow.
46+
This repo uses [Github Tag Bump](https://github.com/marketplace/actions/github-tag-bump) for auto tagging on master branch. Therfore, it automatically triggers the release workflow as well.
4547

4648
- Add `#minor` to your commit message to bump minor version.
4749
- Add `#major` to your commit message to bump major version. DANGER! Use it with caution and make sure you understand the consequences. More info: [Go Wiki](https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher), [Go Blog](https://blog.golang.org/v2-go-modules).
@@ -53,6 +55,7 @@ Remember to update Go version in [.github/workflows](.github/workflows), [Makefi
5355
Notable files:
5456
- [devcontainer.json](.devcontainer/devcontainer.json) - Visual Studio Code Remote Container configuration
5557
- [.github/workflows](.github/workflows) - GitHub Actions workflows
58+
- [.github/dependabot.yml](.github/dependabot.yml) - Dependabot configuration
5659
- [.vscode](.vscode) - Visual Studio Code configuration files
5760
- [.golangci.yml](.golangci.yml) - golangci-lint configuration
5861
- [.goreleaser.yml](.goreleaser.yml) - GoReleaser configuration
@@ -70,6 +73,8 @@ You can always remove the [.devcontainer](.devcontainer) and [.vscode](.vscode)
7073
### Why GitHub Actions, not any other CI server
7174

7275
GitHub Actions is out-of-the-box if you are already using GitHub.
76+
[Here](https://github.com/mvdan/github-actions-golang) you can learn how to use it for Go.
77+
7378
However, changing to any other CI server should be very simple, because this repository has build logic and tooling installation in Makefile.
7479

7580
You can also use the `docker` make target to run the build using a docker container.
@@ -113,6 +118,10 @@ release:
113118
114119
Alternativly you can completly remove the usage of GoReleaser if you prefer handcrafted release notes.
115120
121+
### Why the code coverage results are not accurate
122+
123+
By default `go test` records code coverage for the package that is currently tested. If you want to get more accurate (cross-package) coverage, then consider using [go-acc](https://github.com/ory/go-acc). [Read more](https://www.ory.sh/golang-go-code-coverage-accurate/).
124+
116125
## Contributing
117126

118127
Simply create an issue or a pull request.

0 commit comments

Comments
 (0)