diff --git a/.devcontainer/devcontainer-lock.json b/.devcontainer/devcontainer-lock.json new file mode 100644 index 0000000..dd8b384 --- /dev/null +++ b/.devcontainer/devcontainer-lock.json @@ -0,0 +1,14 @@ +{ + "features": { + "ghcr.io/devcontainers-extra/features/mise:1": { + "version": "1.0.0", + "resolved": "ghcr.io/devcontainers-extra/features/mise@sha256:5c389ab1e3c8e44e5e0ff119f6868d54dbb781bc860bd8587dc66209cb8c4a8c", + "integrity": "sha256:5c389ab1e3c8e44e5e0ff119f6868d54dbb781bc860bd8587dc66209cb8c4a8c" + }, + "ghcr.io/devcontainers/features/github-cli:1": { + "version": "1.1.0", + "resolved": "ghcr.io/devcontainers/features/github-cli@sha256:d22f50b70ed75339b4eed1ba9ecde3a1791f90e88d37936517e3bace0bbad671", + "integrity": "sha256:d22f50b70ed75339b4eed1ba9ecde3a1791f90e88d37936517e3bace0bbad671" + } + } +} diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d134ae2..e7d3c58 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,4 +1,4 @@ - // For format details, see https://aka.ms/devcontainer.json. +// For format details, see https://aka.ms/devcontainer.json. { "name": "Ubuntu", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile @@ -6,13 +6,15 @@ // Features to add to the dev container. More info: https://containers.dev/features. "features": { "ghcr.io/devcontainers-extra/features/mise:1": {}, - "ghcr.io/devcontainers/features/docker-in-docker:2": {} + "ghcr.io/devcontainers/features/github-cli:1": {} }, "postCreateCommand": "bash .devcontainer/post_create.sh", "customizations": { "vscode": { "extensions": [ - "golang.go" + "golang.go", + "hverlin.mise-vscode", + "tamasfe.even-better-toml" ] } } diff --git a/.devcontainer/post_create.sh b/.devcontainer/post_create.sh index a190145..ec19e0a 100644 --- a/.devcontainer/post_create.sh +++ b/.devcontainer/post_create.sh @@ -1,9 +1,9 @@ #!/bin/bash -# note that bash will read from ~/.profile or ~/.bash_profile if the latter exists -# ergo, you may want to check to see which is defined on your system and only append to the existing file -echo 'eval "$(mise activate bash --shims)"' >>~/.bash_profile # this sets up non-interactive sessions -echo 'eval "$(mise activate bash)"' >>~/.bashrc # this sets up interactive sessions +set -euo pipefail + +echo 'eval "$(mise activate bash --shims)"' >>~/.bash_profile +echo 'eval "$(mise activate bash)"' >>~/.bashrc mise trust . @@ -13,3 +13,7 @@ mise exec -- go mod download mise exec -- go install -v golang.org/x/tools/gopls@latest mise exec -- go install -v github.com/go-delve/delve/cmd/dlv@latest + +if [[ -f ".devcontainer/post_create.local.sh" ]]; then + source ".devcontainer/post_create.local.sh" +fi diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 820bfcf..1b9aa0d 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -3,49 +3,99 @@ # # You may wish to alter this file to override the set of languages analyzed, # or to provide custom queries or build logic. -name: "CodeQL" +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL Advanced" on: push: - branches: - - main + branches: [ "main" ] pull_request: - # The branches below must be a subset of the branches above - branches: - - main + branches: [ "main" ] schedule: - - cron: "0 17 * * 5" + - cron: '29 23 * * 6' jobs: analyze: - name: Analyze - runs-on: ubuntu-latest - + name: Analyze (${{ matrix.language }}) + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners (GitHub.com only) + # Consider using larger runners or machines with greater resources for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} permissions: # required for all workflows security-events: write + # required to fetch internal or private CodeQL packs + packages: read + + # only required for workflows in private repositories + actions: read + contents: read + strategy: fail-fast: false matrix: - # Override automatic language detection by changing the below list - # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] - # TODO: Enable for javascript later - language: ["go"] - + include: + - language: actions + build-mode: none + - language: go + build-mode: autobuild + # CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift' + # Use `c-cpp` to analyze code written in C, C++ or both + # Use 'java-kotlin' to analyze code written in Java, Kotlin or both + # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both + # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, + # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. + # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how + # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages steps: - - name: Checkout repository - uses: actions/checkout@v5 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v4 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v4 + - name: Checkout repository + uses: actions/checkout@v6 + + # Add any setup steps before running the `github/codeql-action/init` action. + # This includes steps like installing compilers or runtimes (`actions/setup-node` + # or others). This is typically only required for manual builds. + # - name: Setup runtime (example) + # uses: actions/setup-example@v1 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v4 + with: + languages: ${{ matrix.language }} + build-mode: ${{ matrix.build-mode }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + # If the analyze step fails for one of the languages you are analyzing with + # "We were unable to automatically build your code", modify the matrix above + # to set the build mode to "manual" for that language. Then modify this step + # to build your code. + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + - name: Run manual build steps + if: matrix.build-mode == 'manual' + shell: bash + run: | + echo 'If you are using a "manual" build mode for one or more of the' \ + 'languages you are analyzing, replace this with the commands to build' \ + 'your code, for example:' + echo ' make bootstrap' + echo ' make release' + exit 1 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v4 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..24cc2d8 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,56 @@ +name: Coverage + +on: + push: + branches: + - main + tags: + - 'v*' + pull_request: + branches: + - main + +permissions: + contents: read + +concurrency: + group: coverage-${{ github.ref }} + cancel-in-progress: true + +jobs: + coverage: + name: Coverage + runs-on: ubuntu-latest + timeout-minutes: 15 + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Install mise + uses: jdx/mise-action@v4 + + - name: Cache Go modules and build + uses: actions/cache@v4 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: go-${{ runner.os }}-${{ hashFiles('**/go.sum') }} + restore-keys: go-${{ runner.os }}- + + - name: Download Go dependencies + run: go mod download + + - name: Run tests with coverage + run: make cover + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v5 + with: + files: coverage.out + # Fork PRs upload tokenlessly, which can be flaky; don't fail their CI. + fail_ci_if_error: ${{ github.event_name != 'pull_request' }} + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 29e78aa..5626fb9 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -5,10 +5,18 @@ on: branches: - main +permissions: + contents: read + +concurrency: + group: pr-check-${{ github.ref }} + cancel-in-progress: true + jobs: check: name: Check runs-on: ubuntu-latest + timeout-minutes: 15 steps: - name: Checkout uses: actions/checkout@v6 @@ -18,6 +26,22 @@ jobs: - name: Install mise uses: jdx/mise-action@v4 + - name: Cache Go modules and build + uses: actions/cache@v4 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: go-${{ runner.os }}-${{ hashFiles('**/go.sum') }} + restore-keys: go-${{ runner.os }}- + + - name: Cache golangci-lint + uses: actions/cache@v4 + with: + path: ~/.cache/golangci-lint + key: golangci-lint-${{ runner.os }}-${{ hashFiles('mise.toml', '.golangci.yaml') }} + restore-keys: golangci-lint-${{ runner.os }}- + - name: Download Go dependencies run: go mod download diff --git a/.gitignore b/.gitignore index 6f72f89..1eaac08 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,8 @@ go.work.sum # env file .env + +# Local configuration files +*.local.* +*.local/ +*.local diff --git a/.golangci.yaml b/.golangci.yaml index eb3c803..16a0424 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -10,10 +10,6 @@ issues: severity: default: error - # rules: - # - linters: - # - dupl - # severity: error formatters: enable: @@ -22,7 +18,7 @@ formatters: - gofumpt - goimports - golines - - swaggo + settings: gofmt: rewrite-rules: @@ -30,8 +26,8 @@ formatters: replacement: "any" gofumpt: extra-rules: true - exclusions: - paths: [] + golines: + max-len: 120 linters: default: none @@ -45,33 +41,66 @@ linters: # Additional - bodyclose + - canonicalheader + - copyloopvar - depguard + - dupword + - durationcheck + - errchkjson - errname - errorlint + - exptostd + - fatcontext + - gocheckcompilerdirectives - gocognit - goconst - - goheader - - gomodguard + - gocritic + - gomodguard_v2 - goprintffuncname - gosec + - intrange + - loggercheck + - mirror + - misspell + - modernize + - musttag - nakedret + - nestif - nilerr + - nilnesserr - nilnil - noctx - nolintlint + - nosprintfhostport + - perfsprint - prealloc - promlinter + - recvcheck - revive + - rowserrcheck + - sloglint + - spancheck + - sqlclosecheck - testifylint - testpackage - thelper + - unconvert + - unparam - usestdlibvars + - usetesting - wastedassign + - whitespace - wsl_v5 - disable: [] - settings: + govet: + enable: + - nilness + + modernize: + disable: + - omitzero + depguard: rules: main: @@ -84,16 +113,3 @@ linters: desc: Use github.com/go-resty/resty/v2 instead - pkg: github.com/aws/smithy-go/ptr$ desc: Use github.com/aws/aws-sdk-go-v2/aws instead - govet: - enable: - - nilness - - # exclusions: - # paths: - # - (.+)_test\.go - # rules: - # - path: (.+)_test\.go - # linters: - # - dupl - # - mnd - # - lll diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..01498bd --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "ms-vscode-remote.remote-containers", + "golang.go", + "hverlin.mise-vscode", + "tamasfe.even-better-toml" + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 74473b0..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Launch test function", - "type": "go", - "request": "launch", - "mode": "test", - "program": "${workspaceFolder}", - "args": [ - "-test.run", - "MyTestFunction" - ] - }, - { - "name": "Launch Workspace", - "type": "go", - "request": "launch", - "mode": "debug", - "program": "${workspaceFolder}", - "cwd": "${workspaceFolder}", - } - ] -} diff --git a/AGENTS.md b/CLAUDE.md similarity index 60% rename from AGENTS.md rename to CLAUDE.md index d8bd7a7..e7f36cd 100644 --- a/AGENTS.md +++ b/CLAUDE.md @@ -1,4 +1,4 @@ -# AGENTS.md +# CLAUDE.md This file provides instructions and conventions for AI coding agents working in this repository. @@ -8,26 +8,31 @@ This file provides instructions and conventions for AI coding agents working in ### Packages -| Path | Module path | Description | -|------|-------------|-------------| -| `/` (root) | `github.com/min0625/errgroup` | Drop-in replacement for `golang.org/x/sync/errgroup` | -| `x/errgroup/` | `github.com/min0625/errgroup/x/errgroup` | Context-aware variant — passes `context.Context` into each goroutine function | +A single Go module (`github.com/min0625/errgroup`) holds two packages: + +| Import path | Description | +|-------------|-------------| +| `github.com/min0625/errgroup` | Drop-in replacement for `golang.org/x/sync/errgroup` | +| `github.com/min0625/errgroup/x/errgroup` | Context-aware variant — passes `context.Context` into each goroutine function | ## Repository Structure ``` -errgroup.go # Core Group type and methods -panic.go # PanicError, PanicValue types and exception() helper +errgroup.go # Core Group type and methods (WithContext, Go, TryGo, Wait, SetLimit) +panic.go # PanicError, PanicValue types and the exception() helper errgroup_test.go # Tests for the root package example_test.go # Runnable examples for the root package -go.mod # Module definition +README.md # Root package docs +go.mod / go.sum # Module definition Makefile # Developer commands mise.toml # Pinned tool versions (Go, golangci-lint) +.golangci.yaml # Linter configuration x/errgroup/ - errgroup.go # Context-aware Group type - panic.go # Re-exports panic types from the root package (if any) + errgroup.go # Context-aware Group type (New constructor instead of WithContext) + panic.go # Type-alias re-exports of PanicError / PanicValue from the root package errgroup_test.go # Tests for the x/errgroup package example_test.go # Runnable examples for the x/errgroup package + README.md # x/errgroup package docs ``` ## Tool Versions @@ -40,7 +45,7 @@ mise install | Tool | Version | |------|---------| -| Go | 1.24.x | +| Go | 1.26.x (module requires go 1.25) | | golangci-lint | 2.x | ## Common Commands @@ -49,10 +54,14 @@ All commands should be run from the repository root. | Command | Description | |---------|-------------| -| `make lint` | Run linter (`golangci-lint run`) | -| `make fix` | Run linter with auto-fix (`golangci-lint run --fix`) | -| `make test` | Run all tests with race detector (`go test -v -race -failfast ./...`) | -| `make check` | Run `lint` then `test` (full CI gate) | +| `make lint` | Verify lint config, then run `golangci-lint run` (new issues vs `HEAD`) | +| `make fix` | `go mod tidy`, then `golangci-lint run --fix` (new issues vs `HEAD`) | +| `make test` | Run all tests with race detector (`go test -race -failfast ./...`) | +| `make check-tidy` | Verify `go.mod` is tidy (`go mod tidy -diff`) | +| `make cover` | Run tests with coverage and print the per-function summary | +| `make check` | Run `check-tidy`, `lint`, then `test` (full CI gate) | + +`lint`/`fix` compare against `NEW_FROM_REV` (default `HEAD`); override it to widen the range, e.g. `make lint NEW_FROM_REV=main`. Always run `make check` before considering a change complete. @@ -81,7 +90,7 @@ Always run `make check` before considering a change complete. ### Dual-Package Consistency -Changes to the root package (`errgroup.go`, `panic.go`) that affect the public API or panic-recovery behaviour must be reflected in `x/errgroup/` where applicable, and vice versa. +Changes to the root package (`errgroup.go`, `panic.go`) that affect the public API or panic-recovery behaviour must be reflected in `x/errgroup/` where applicable, and vice versa. The `x/errgroup` panic types are type aliases of the root types, so they stay in sync automatically. ### Dependencies @@ -90,5 +99,7 @@ Changes to the root package (`errgroup.go`, `panic.go`) that affect the public A ### Linting -- The project uses `golangci-lint`. Lint rules are configured in the repository (check for `.golangci.yml` or inline `//nolint` directives). +- The project uses `golangci-lint`, configured in `.golangci.yaml`. - Suppress a lint warning with `//nolint: // ` only when genuinely necessary, not to silence legitimate issues. + + diff --git a/Makefile b/Makefile index 78bf91e..b6c2428 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,27 @@ NEW_FROM_REV ?= HEAD +.PHONY: fix fix: go mod tidy - golangci-lint run -v --new-from-rev=$(NEW_FROM_REV) --fix ./... + golangci-lint run --new-from-rev=$(NEW_FROM_REV) --fix ./... +.PHONY: lint lint: - golangci-lint run -v --new-from-rev=$(NEW_FROM_REV) ./... + golangci-lint config verify + golangci-lint run --new-from-rev=$(NEW_FROM_REV) ./... +.PHONY: test test: - go test -v -race -failfast ./... + go test -race -failfast ./... +.PHONY: check-tidy check-tidy: go mod tidy -diff +.PHONY: cover +cover: + go test -race -covermode=atomic -coverprofile=coverage.out ./... + go tool cover -func=coverage.out + +.PHONY: check check: check-tidy lint test diff --git a/README.md b/README.md index a6ff80e..539ff19 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # errgroup [![Go Reference](https://pkg.go.dev/badge/github.com/min0625/errgroup.svg)](https://pkg.go.dev/github.com/min0625/errgroup) +[![codecov](https://codecov.io/gh/min0625/errgroup/branch/main/graph/badge.svg)](https://codecov.io/gh/min0625/errgroup) A recoverable errgroup based on `golang.org/x/sync/errgroup` that can recover from panics. Panics are caught and re-panicked in the `Wait` call. diff --git a/mise.toml b/mise.toml index 88b0dbf..7847d7f 100644 --- a/mise.toml +++ b/mise.toml @@ -1,3 +1,3 @@ [tools] -go = "1.25.9" -golangci-lint = "2.11.2" +go = "1.26.4" +golangci-lint = "2.12.2" diff --git a/x/errgroup/README.md b/x/errgroup/README.md index f80d5b4..b039b58 100644 --- a/x/errgroup/README.md +++ b/x/errgroup/README.md @@ -1,5 +1,6 @@ # errgroup/x/errgroup [![Go Reference](https://pkg.go.dev/badge/github.com/min0625/errgroup/x/errgroup.svg)](https://pkg.go.dev/github.com/min0625/errgroup/x/errgroup) +[![codecov](https://codecov.io/gh/min0625/errgroup/branch/main/graph/badge.svg)](https://codecov.io/gh/min0625/errgroup) A context-aware variant of [`github.com/min0625/errgroup`](../../README.md) that passes a derived `context.Context` directly into each goroutine function, eliminating the need to capture the context via closure.