diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 0000000..cc8b640 --- /dev/null +++ b/.codespellrc @@ -0,0 +1,5 @@ +[codespell] + +skip = ./vendor,./.git +check-filenames = true + diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..d162971 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,24 @@ +What has been done? Why? What problem is being solved? + +I didn't forget about (remove if it is not applicable): + +- [ ] Well-written commit messages (see [documentation][how-to-write-commit] how to write a commit message) +- [ ] Don't forget about TarantoolBot in a commit message (see [example][tarantoolbot-example]) +- [ ] Tests (see [documentation][go-testing] for a testing package) +- [ ] Changelog (see [documentation][keepachangelog] for changelog format) +- [ ] Documentation (see [documentation][go-doc] for documentation style guide) + +Related issues: + +Related to #XXX + +Part of #XXX + +Closes #XXX + +[go-doc]: https://go.dev/blog/godoc +[go-testing]: https://pkg.go.dev/testing +[how-to-write-commit]: https://www.tarantool.io/en/doc/latest/contributing/developer_guidelines/#how-to-write-a-commit-message +[keepachangelog]: https://keepachangelog.com/en/1.0.0/ +[tarantoolbot-example]: https://github.com/tarantool/tt/pull/1030/commits + diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml new file mode 100644 index 0000000..7e973e2 --- /dev/null +++ b/.github/workflows/check.yaml @@ -0,0 +1,70 @@ +name: Run checks + +on: + push: + pull_request: + +env: + GO_VERSION: 1.25 + CODESPELL_VERSION: v2.4.1 + + +jobs: + golangci-lint: + runs-on: ubuntu-latest + if: | + github.event_name == 'push' || + github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name != github.repository + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - uses: golangci/golangci-lint-action@v8 + name: run golangci-lint with gha format + continue-on-error: true + + - uses: golangci/golangci-lint-action@v8 + name: run golangci-lint with human-readable format + + codespell: + runs-on: ubuntu-latest + if: | + github.event_name == 'push' || + github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name != github.repository + steps: + - uses: actions/checkout@v4 + + - name: install codespell + run: pip3 install codespell==${CODESPELL_VERSION} + + - name: run codespell + run: make codespell + + verify-generation: + runs-on: ubuntu-latest + if: | + github.event_name == 'push' || + github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name != github.repository + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + + - name: genrate code + run: go generate ./... + + - name: check for changes + run: | + if [ -n "$(git status --porcelain)" ]; then + echo "new files were generated" + git status --porcelain + git diff + exit 1 + fi + diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml new file mode 100644 index 0000000..5a2b1cd --- /dev/null +++ b/.github/workflows/testing.yaml @@ -0,0 +1,65 @@ +name: testing + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + run-tests: + if: (github.event_name == 'push') || + (github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name != github.repository) || + (github.event_name == 'workflow_dispatch') + + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + golang: ['1.24', 'stable'] + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.golang }} + + - name: run tests + run: make test + + - name: run tests with race + run: make testrace + + run-tests-with-coverage: + if: (github.event_name == 'push') || + (github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name != github.repository) || + (github.event_name == 'workflow_dispatch') + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.golang }} + + - name: run tests, collect code coverage data and send to Coveralls + env: + COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: make coverage coveralls-deps coveralls + + run-benchmarks: + if: false + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.golang }} + - name: run benchmarks + run: make bench + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4a37a24 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +coverage.out + diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..f2724a1 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,58 @@ +version: '2' + +run: + timeout: 3m + +formatters: + enable: + - goimports + +issues: + # Disable limits on the number of printed issues + max-issues-per-linter: 0 # 0 = no limit + max-same-issues: 0 # 0 = no limit + +linters: + default: all + + disable: + - dupl # Dupl is disabled, since we're generating a lot of boilerplate code. + - cyclop # Cyclop is disabled, since cyclomatic complexities is very abstract metric, + # that sometimes lead to strange linter behaviour. + - wsl # WSL is disabled, since it's obsolete. Using WSL_v5. + - nlreturn # nlreturn is disabled, since it's duplicated by wsl_v5.return check. + - ireturn # ireturn is disabled, since it's not needed. + + exclusions: + generated: lax + rules: + - path: _test.go + linters: + - wrapcheck + + settings: + godot: + scope: all + lll: + line-length: 120 + tab-width: 4 + wsl_v5: + allow-first-in-block: true + allow-whole-block: false + branch-max-lines: 2 + case-max-lines: 0 + default: all + depguard: + rules: + main: + files: + - "$all" + - "!$test" + allow: + - $gostd + test: + files: + - "$test" + allow: + - $gostd + - "github.com/stretchr/testify" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e2115e6 --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +GOTEST := go test +TAGS := +COVERAGE_FILE := coverage.out + +.PHONY: codespell +codespell: + @echo "Running codespell" + @codespell + +.PHONY: test +test: + @echo "Running tests" + @go test ./... -count=1 + +.PHONY: testrace +testrace: + @echo "Running tests with race flag" + @go test ./... -count=100 -race + +.PHONY: coverage +coverage: + @echo "Running tests with coveralls" + go test -tags "$(TAGS)" $(go list ./... | grep -v test_helpers) -v -p 1 -covermode=atomic -coverprofile=$(COVERAGE_FILE) -count=1 + go tool cover -func=$(COVERAGE_FILE) + +.PHONY: coveralls +coveralls: + @echo "uploading coverage to coveralls" + @goveralls -coverprofile=$(COVERAGE_FILE) -service=github + +.PHONY: coveralls-deps +coveralls-deps: + @echo "Installing coveralls" + @go get github.com/mattn/goveralls + @go install github.com/mattn/goveralls + +.PHONY: lint-deps +lint-deps: + @echo "Installing lint deps" + @go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7.0 + +.PHONY: lint +lint: lint-deps + @echo "Running go-linter" + @go mod tidy + @go mod vendor + @golangci-lint run --config=./.golangci.yml --modules-download-mode vendor --verbose + diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..e358ca5 --- /dev/null +++ b/doc.go @@ -0,0 +1,2 @@ +// Package config provides a uniform way to handle various configurations. +package config