diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 0000000..d4cb50e --- /dev/null +++ b/.codespellrc @@ -0,0 +1,5 @@ +[codespell] + +skip = ./vendor,./.git +# ignore-words-list = +check-filenames = true diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..70638f9 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,9 @@ +What has been done? Why? What problem is being solved? + +I didn't forget about (remove if it is not applicable): + +- [ ] Tests (see [documentation](https://pkg.go.dev/testing) for a testing package) +- [ ] Changelog (see [documentation](https://keepachangelog.com/en/1.0.0/) for changelog format) +- [ ] Documentation (see [documentation](https://go.dev/blog/godoc) for documentation style guide) + +Related issues: diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml new file mode 100644 index 0000000..c2e1f05 --- /dev/null +++ b/.github/workflows/check.yaml @@ -0,0 +1,72 @@ +name: Run checks + +on: + push: + pull_request: + +env: + GO_VERSION: 1.24 + 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..072555b --- /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.23', '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..2d83068 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +coverage.out diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..df8327f --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,29 @@ +version: '2' + +run: + timeout: 3m + +formatters: + enable: + - goimports + +linters: + enable: + - forbidigo + - gocritic + - lll + - reassign + - unconvert + - gosec + - errorlint + - godot + - revive + - testpackage + - unused + + settings: + godot: + scope: all + lll: + line-length: 120 + tab-width: 4 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0e6d57d --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +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 diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..5f963c3 --- /dev/null +++ b/doc.go @@ -0,0 +1,8 @@ +// Package option provides a type-safe way to represent optional values in Go. +// An Optional[T] can either contain a value of type T (Some) or be empty (None). +// +// This is useful for: +// - Clearly representing nullable fields in structs. +// - Avoiding nil pointer dereferences. +// - Providing explicit intent about optional values. +package option diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e69de29