From 4cf680e3acd6c75e27016fe91786d5dea11e5990 Mon Sep 17 00:00:00 2001 From: CHIKAMATSU Naohiro Date: Wed, 15 May 2024 23:50:47 +0900 Subject: [PATCH] Update --- .github/ISSUE_TEMPLATE/feature-request.md | 20 ++ .../{linux_test.yml => coverage.yml} | 9 +- .github/workflows/mac_test.yml | 31 -- .github/workflows/multi_ver_unittest.yml | 23 -- .github/workflows/unit_test.yml | 37 +++ .github/workflows/windows_test.yml | 31 -- .octocov.yml | 21 +- Makefile | 8 +- README.md | 9 +- cmd/root.go | 3 +- doc/img/cover-tree.svg | 287 ++++++++++++++++++ 11 files changed, 371 insertions(+), 108 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/feature-request.md rename .github/workflows/{linux_test.yml => coverage.yml} (66%) delete mode 100644 .github/workflows/mac_test.yml delete mode 100644 .github/workflows/multi_ver_unittest.yml create mode 100644 .github/workflows/unit_test.yml delete mode 100644 .github/workflows/windows_test.yml create mode 100644 doc/img/cover-tree.svg diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md new file mode 100644 index 0000000..64a391b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +## Is your feature request related to a problem? +A clear and concise description of what the problem is. E.g. I'm always frustrated when ... + +## Describe the solution you'd like +A clear and concise description of what you want to happen. + +## Describe alternatives you've considered +A clear and concise description of any alternative solutions or features you've considered. + +## Additional context +Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/linux_test.yml b/.github/workflows/coverage.yml similarity index 66% rename from .github/workflows/linux_test.yml rename to .github/workflows/coverage.yml index 2cefdd1..34d0371 100644 --- a/.github/workflows/linux_test.yml +++ b/.github/workflows/coverage.yml @@ -1,4 +1,4 @@ -name: LinuxUnitTest +name: Coverage on: workflow_dispatch: @@ -25,10 +25,7 @@ jobs: go-version: "1" check-latest: true - - name: Download dependencies - run: go mod download + - name: Run tests with coverage report output + run: go test -cover -coverpkg=./... -coverprofile=coverage.out ./... - - uses: nao1215/actions-hottest@v1 - with: - args: '-cover -coverpkg=./... -coverprofile=coverage.out ./...' - uses: k1LoW/octocov-action@v1 diff --git a/.github/workflows/mac_test.yml b/.github/workflows/mac_test.yml deleted file mode 100644 index f6cb6df..0000000 --- a/.github/workflows/mac_test.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: MacUnitTest - -on: - workflow_dispatch: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - unit_test: - name: Unit test (mac) - - strategy: - matrix: - platform: [macos-latest] - - runs-on: ${{ matrix.platform }} - - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-go@v5 - with: - go-version: "1" - check-latest: true - - - name: Run unit test - run: | - go mod download - go test -race -v ./... diff --git a/.github/workflows/multi_ver_unittest.yml b/.github/workflows/multi_ver_unittest.yml deleted file mode 100644 index c795615..0000000 --- a/.github/workflows/multi_ver_unittest.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: MultiVersionUnitTest - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - unit-test: - runs-on: ubuntu-latest - strategy: - matrix: - go-version: ["1.20", "1.22"] - steps: - - uses: actions/checkout@v4 - - name: Setup Go ${{ matrix.go-version }} - uses: actions/setup-go@v5 - with: - go-version: ${{ matrix.go-version }} - - - name: MultiVersionUnitTest - run: make test diff --git a/.github/workflows/unit_test.yml b/.github/workflows/unit_test.yml new file mode 100644 index 0000000..31806b9 --- /dev/null +++ b/.github/workflows/unit_test.yml @@ -0,0 +1,37 @@ +name: MultiPlatformUnitTest + +on: + workflow_dispatch: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + unit_test: + name: Unit test (linux) + + strategy: + matrix: + os: + - "ubuntu-latest" + - "windows-latest" + - "macos-latest" + go: + - "1" + - "1.22" + - "1.21" + - "1.20" + fail-fast: false + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + + - name: Run tests with coverage report output + run: go test -cover -coverpkg=./... -coverprofile=coverage.out ./... + diff --git a/.github/workflows/windows_test.yml b/.github/workflows/windows_test.yml deleted file mode 100644 index 4ccee50..0000000 --- a/.github/workflows/windows_test.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: WindowsUnitTest - -on: - workflow_dispatch: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - unit_test: - name: Unit test (windows) - - strategy: - matrix: - platform: [windows-latest] - - runs-on: ${{ matrix.platform }} - - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-go@v5 - with: - go-version: "1" - check-latest: true - - - name: Run unit test - run: | - go mod download - go test -race -v ./... diff --git a/.octocov.yml b/.octocov.yml index 1e17b9f..828894b 100644 --- a/.octocov.yml +++ b/.octocov.yml @@ -1,28 +1,27 @@ # generated by octocov init coverage: - if: true acceptable: 80% -testExecutionTime: - if: true - acceptable: 1:1.1 - acceptable: current <= 1min && diff <= 2sec + exclude: + - "github.com/nao1215/gup/main.go" + - "github.com/nao1215/gup/cmd/root.go" + - "github.com/nao1215/gup/cmd/man.go" + - "github.com/nao1215/gup/cmd/bug_report.go" + - "github.com/nao1215/gup/internal/assets/asset.go" + - "github.com/nao1215/gup/internal/completion/completion.go" + badge: + path: docs/coverage.svg diff: datastores: - artifact://${GITHUB_REPOSITORY} comment: if: is_pull_request -summary: - if: true report: if: is_default_branch datastores: - artifact://${GITHUB_REPOSITORY} -coverage: - badge: - path: docs/coverage.svg codeToTestRatio: badge: path: docs/ratio.svg testExecutionTime: badge: - path: docs/time.svg \ No newline at end of file + path: docs/time.svg diff --git a/Makefile b/Makefile index 102ff9c..716d56b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: build test clean vet fmt chkfmt changelog tools help +.PHONY: build test clean vet fmt chkfmt changelog tools help coverage-tree APP = gup VERSION = $(shell git describe --tags --abbrev=0) @@ -34,6 +34,12 @@ vet: ## Start go vet fmt: ## Format go source code $(GO_FORMAT) $(GO_PKGROOT) +coverage-tree: test ## Generate coverage tree + go-cover-treemap -statements -coverprofile cover.out > doc/img/cover-tree.svg + +tools: ## Install dependency tools + $(GO_INSTALL) github.com/nikolaydubina/go-cover-treemap@latest + .DEFAULT_GOAL := help help: @grep -E '^[0-9a-zA-Z_-]+[[:blank:]]*:.*?## .*$$' $(MAKEFILE_LIST) | sort \ diff --git a/README.md b/README.md index 68438a2..ac1a2a0 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,6 @@ [![All Contributors](https://img.shields.io/badge/all_contributors-10-orange.svg?style=flat-square)](#contributors-) [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) -[![MultiVersionUnitTest](https://github.com/nao1215/gup/actions/workflows/multi_ver_unittest.yml/badge.svg)](https://github.com/nao1215/gup/actions/workflows/multi_ver_unittest.yml) -[![WindowsUnitTest](https://github.com/nao1215/gup/actions/workflows/windows_test.yml/badge.svg)](https://github.com/nao1215/gup/actions/workflows/windows_test.yml) -[![MacUnitTest](https://github.com/nao1215/gup/actions/workflows/mac_test.yml/badge.svg)](https://github.com/nao1215/gup/actions/workflows/mac_test.yml) -[![LinuxUnitTest](https://github.com/nao1215/gup/actions/workflows/linux_test.yml/badge.svg)](https://github.com/nao1215/gup/actions/workflows/linux_test.yml) [![reviewdog](https://github.com/nao1215/gup/actions/workflows/reviewdog.yml/badge.svg)](https://github.com/nao1215/gup/actions/workflows/reviewdog.yml) ![Coverage](https://raw.githubusercontent.com/nao1215/octocovs-central-repo/main/badges/nao1215/gup/coverage.svg) [![gosec](https://github.com/nao1215/gup/actions/workflows/security.yml/badge.svg)](https://github.com/nao1215/gup/actions/workflows/security.yml) @@ -197,6 +193,11 @@ Contributions are not only related to development. For example, GitHub Star moti ### Star History [![Star History Chart](https://api.star-history.com/svg?repos=nao1215/gup&type=Date)](https://star-history.com/#nao1215/gup&Date) +### For Developers +When adding new features or fixing bugs, please write unit tests. The sqly is unit tested for all packages as the unit test tree map below shows. + +![treemap](./doc/img/cover-tree.svg) + ## Contact If you would like to send comments such as "find a bug" or "request for additional features" to the developer, please use one of the following contacts. diff --git a/cmd/root.go b/cmd/root.go index abd2d99..74671fa 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -58,7 +58,8 @@ func Execute() error { return rootCmd.Execute() } -func completeNCPUs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { +// completeNCPUs returns the number of CPU cores as a string. +func completeNCPUs(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { n := runtime.NumCPU() ret := make([]string, 0, n) for i := 1; i <= n; i++ { diff --git a/doc/img/cover-tree.svg b/doc/img/cover-tree.svg new file mode 100644 index 0000000..3c0d3af --- /dev/null +++ b/doc/img/cover-tree.svg @@ -0,0 +1,287 @@ + + + + + + +github.com/nao1215/gup + + + + + + + +cmd + + + + + + + +internal + + + + + + + +bug_report.go + + + + + + + + + + + + + +check.go + + + + + + + +completion.go + + + + + + + +export.go + + + + + + + +import.go + + + + + + + +list.go + + + + + + + +man.go + + + + + + + +remove.go + + + + + + + +root.go + + + + + + + +update.go + + + + + + + +version.go + + + + + + + +assets/asset.go + + + + + + + +cmdinfo/cmdinfo.go + + + + + + + +completion/completion.go + + + + + + + +config/config.go + + + + + + + +goutil/goutil.go + + + + + + + +notify/notify.go + + + + + + + +print/print.go + + + + \ No newline at end of file