From 97df62312959b795a849bb29f0133dbcd11be1ad Mon Sep 17 00:00:00 2001 From: Robert Pajak Date: Thu, 2 Jul 2020 21:53:21 +0200 Subject: [PATCH 1/7] Refine test coverage --- .github/workflows/build.yml | 8 +++++++- .gitignore | 4 ++-- Makefile | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bf36511..e35d891 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,6 +24,11 @@ jobs: go-version: 1.14 - name: Build run: make all + - name: Upload coverage + uses: actions/upload-artifact@v2 + with: + name: coverage + path: coverage.* - id: git-auto-tag name: Bump version and push tag uses: anothrNick/github-tag-action@1.22.0 @@ -39,7 +44,8 @@ jobs: run: make release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - uses: actions/upload-artifact@v2 + - name: Upload dist + uses: actions/upload-artifact@v2 with: name: dist path: dist diff --git a/.gitignore b/.gitignore index 21b8801..49df16d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,14 +13,14 @@ # Output of the go coverage tool, specifically when used with LiteIDE *.out +coverage.html # Dependency directories (remove the comment below to include it) -# vendor/ +vendor/ # Output of GoReleaser dist/ - # Visual Studio Code files .vscode/* !.vscode/settings.json diff --git a/Makefile b/Makefile index 734be92..5c7b86a 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,8 @@ lint-fast: ## golangci-lint --fast .PHONY: test test: ## go test with race detector and code covarage $(call print-target) - go test -race -covermode=atomic ./... + go test -race -coverpkg=./... -covermode=atomic -coverprofile=coverage.out ./... + go tool cover -html=coverage.out -o coverage.html .PHONY: mod-tidy mod-tidy: ## go mod tidy From 6d8461a9e466cc52226d71a326330d318939e623 Mon Sep 17 00:00:00 2001 From: Robert Pajak Date: Thu, 2 Jul 2020 22:33:40 +0200 Subject: [PATCH 2/7] Add useful hyperlink in FAQ --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5a86897..53aaf20 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,8 @@ You can always remove the [.devcontainer](.devcontainer) and [.vscode](.vscode) ### Why GitHub Actions, not any other CI server GitHub Actions is out-of-the-box if you are already using GitHub. +[Here](https://github.com/mvdan/github-actions-golang) you can learn how to use it for Go. + However, changing to any other CI server should be very simple, because this repository has build logic and tooling installation in Makefile. You can also use the `docker` make target to run the build using a docker container. From a8005124d588c6c821cb5dc4e6dee9c2c141545b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Fri, 3 Jul 2020 20:30:43 +0200 Subject: [PATCH 3/7] Update Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5c7b86a..569eb9e 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ lint-fast: ## golangci-lint --fast .PHONY: test test: ## go test with race detector and code covarage $(call print-target) - go test -race -coverpkg=./... -covermode=atomic -coverprofile=coverage.out ./... + go test -race -covermode=atomic -coverprofile=coverage.out ./... go tool cover -html=coverage.out -o coverage.html .PHONY: mod-tidy From bcdfb822edcac34a8e38c4f2470aa7f30f41bd3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Fri, 3 Jul 2020 20:51:15 +0200 Subject: [PATCH 4/7] Update README.md --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 53aaf20..449ce4c 100644 --- a/README.md +++ b/README.md @@ -13,12 +13,15 @@ This is a GitHub repository template for Go. It has been created for ease-of-use It includes: -- [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, +- continous integration via [GitHub Actions](https://github.com/features/actions), +- build automation via [Make](https://www.gnu.org/software/make), - dependency management using [Go Modules](https://github.com/golang/go/wiki/Modules), - linting with [golangci-lint](https://github.com/golangci/golangci-lint), -- build automation via [Make](https://www.gnu.org/software/make), [GitHub Actions](https://github.com/features/actions), +- unit testing with [race detector](https://blog.golang.org/race-detector) and [code covarage HTML report](https://blog.golang.org/cover), - auto-tagging via [Github Tag Bump](https://github.com/marketplace/actions/github-tag-bump) GitHub Action, -- releasing using [GoReleaser](https://github.com/goreleaser/goreleaser). +- releasing using [GoReleaser](https://github.com/goreleaser/goreleaser), +- depdendencies scanning and vulnerabilities alerting thanks to [Dependabot](https://dependabot.com/go/), +- [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. `Star` this repository if you find it valuable and worth maintaining. @@ -53,6 +56,7 @@ Remember to update Go version in [.github/workflows](.github/workflows), [Makefi Notable files: - [devcontainer.json](.devcontainer/devcontainer.json) - Visual Studio Code Remote Container configuration - [.github/workflows](.github/workflows) - GitHub Actions workflows +- [github/dependabot.yml] - Dependabot configuration - [.vscode](.vscode) - Visual Studio Code configuration files - [.golangci.yml](.golangci.yml) - golangci-lint configuration - [.goreleaser.yml](.goreleaser.yml) - GoReleaser configuration @@ -115,6 +119,10 @@ release: Alternativly you can completly remove the usage of GoReleaser if you prefer handcrafted release notes. +### Why the code coverage results are not accurate + +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/). + ## Contributing Simply create an issue or a pull request. From 500db3242b4a73642755a013b7af5d8527621995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Fri, 3 Jul 2020 20:54:21 +0200 Subject: [PATCH 5/7] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 449ce4c..e7fea9d 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ It includes: The release workflow is triggered each time a tag with `v` prefix is pushed. -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. +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. - Add `#minor` to your commit message to bump minor version. - 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). @@ -56,7 +56,7 @@ Remember to update Go version in [.github/workflows](.github/workflows), [Makefi Notable files: - [devcontainer.json](.devcontainer/devcontainer.json) - Visual Studio Code Remote Container configuration - [.github/workflows](.github/workflows) - GitHub Actions workflows -- [github/dependabot.yml] - Dependabot configuration +- [.github/dependabot.yml](.github/dependabot.yml) - Dependabot configuration - [.vscode](.vscode) - Visual Studio Code configuration files - [.golangci.yml](.golangci.yml) - golangci-lint configuration - [.goreleaser.yml](.goreleaser.yml) - GoReleaser configuration From a4762c7f910b741e0af73c83ea3f0f6f32aaa3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Fri, 3 Jul 2020 20:55:30 +0200 Subject: [PATCH 6/7] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index e7fea9d..c70c8a5 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,6 @@ It includes: ## Build - Terminal: `make` to get help for make targets. -- Terminal: `make all` to execute a full build. - Visual Studio Code: `Terminal` → `Run Build Task... (CTRL+ALT+B)` to execute a fast build. ## Release From 74faf9c6b4f11cfc273873cb91d30812d781d7b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Fri, 3 Jul 2020 21:28:36 +0200 Subject: [PATCH 7/7] Update .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 49df16d..93fd3de 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,7 @@ coverage.html # Dependency directories (remove the comment below to include it) -vendor/ +#vendor/ # Output of GoReleaser dist/