Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@ on:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Run golangci-lint v2
uses: golangci/golangci-lint-action@v9
with:
version: v2.12.2

unit-test:
needs: [lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
191 changes: 108 additions & 83 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,95 +1,21 @@
version: "2"
run:
timeout: 5m
# include test files
tests: true

linters:
enable-all: true
default: standard
disable:
- exhaustivestruct # The owner seems to have abandoned the linter. Replaced by exhaustruct.
- ifshort # The repository of the linter has been deprecated by the owner.
- maligned # The repository of the linter has been archived by the owner. Replaced by govet 'fieldalignment'.
- interfacer # The repository of the linter has been archived by the owner.
- deadcode # The owner seems to have abandoned the linter. Replaced by unused.
- golint # The repository of the linter has been archived by the owner. Replaced by revive.
- varcheck # The owner seems to have abandoned the linter. Replaced by unused.
- structcheck # The owner seems to have abandoned the linter. Replaced by unused.
- nosnakecase # The repository of the linter has been deprecated by the owner. Replaced by revive(var-naming).
- scopelint # The repository of the linter has been deprecated by the owner. Replaced by exportloopref.
- varnamelen # useless in the scope of this project

# Run all the linters from enabled linters set
fast: false

issues:
# skipping non-go dirs
exclude-dirs:
- bin
- config
- debian
- docs
- scripts
- tests
include:
- EXC0001 # Check return values of os funcs
- EXC0004 # govet
- EXC0005 # C-style breaks

exclude-rules:
- linters:
- ireturn
text: "returns generic interface"

- linters:
- lll
source: "^//go:generate "

- linters:
- errcheck
source: "defer\\s+[^\\s]+.Close()"

- linters:
- revive
text: "unexported-return: exported func .+ returns unexported type .+, which can be annoying to use"

- path: cmd/[^/]+/.+\.go
text: exitAfterDefer

# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec
- gochecknoglobals
- exhaustruct
- ireturn
- funlen
- unparam
- lll

linters-settings:
gci:
# Section configuration to compare against.
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/easyp-tech) # Custom section: groups all imports with the specified Prefix.
skip-generated: false
# Enable custom order of sections.
# If true, make the section order the same as the order of sections.
custom-order: true
depguard:
- varnamelen
settings:
depguard:
rules:
main:
cmd:
files:
- !$test
- cmd/*/*.go
allow:
- $gostd
cmd:
main:
files:
- "cmd/*/*.go"
- ""
allow:
- $gostd
tests:
Expand All @@ -98,3 +24,102 @@ linters-settings:
allow:
- $gostd
- github.com/stretchr/testify
exclusions:
generated: lax
presets:
- comments
- common-false-positives
rules:
- linters:
- ireturn
text: returns generic interface
- linters:
- lll
source: '^//go:generate '
- linters:
- errcheck
source: defer\s+[^\s]+.Close()
- linters:
- revive
text: 'unexported-return: exported func .+ returns unexported type .+, which can be annoying to use'
- path: cmd/[^/]+/.+\.go
text: exitAfterDefer
- path: internal/connect/commits_helpers.go
linters:
- staticcheck
- path: internal/providers/bitbucket/repos.go
linters:
- staticcheck
- path: internal/providers/github/repos.go
linters:
- staticcheck
- path: internal/providers/bitbucket/getrepo_test.go
linters:
- staticcheck
- path: internal/providers/multisource/repo.go
linters:
- ineffassign
- staticcheck
- path: internal/connect/api.go
linters:
- errcheck
- path: e2e/testutil/server.go
linters:
- errcheck
- path: internal/providers/content/helpers.go
linters:
- staticcheck
- linters:
- dupl
- errcheck
- exhaustruct
- funlen
- gci
- gochecknoglobals
- gocyclo
- gosec
- ineffassign
- ireturn
- lll
- staticcheck
- unused
- unparam
path: _test\.go
paths:
- bin
- config
- debian
- docs
- scripts
- tests
- third_party$
- builtin$
- examples$
formatters:
enable:
- gci
- gofmt
- gofumpt
- goimports
settings:
gci:
sections:
- standard
- default
- prefix(github.com/easyp-tech)
custom-order: true
exclusions:
generated: lax
paths:
- cmd/easyp/main\.go
- internal/connect/api\.go
- internal/connect/bynames\.go
- bin
- config
- debian
- docs
- scripts
- tests
- third_party$
- builtin$
- examples$
27 changes: 27 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Consumer template — copy into easyp-buf-proxy (or any Go module) as mise.toml.
#
# The [plugins] section lets `mise install` auto-install the custom plugin
# without a manual `mise plugin install` step.

[plugins]
tools = "git::https://github.com/onokonem/mise-repo.git//.tools"

[tools]
"tools:go" = "1.26" # bare version -> host os/arch cell
"tools:golangci-lint" = "2.12-go1.26"

# ---- tasks ----------------------------------------------------------------
# All tasks run on the host OS/arch (no cross-compile for test/lint).
# Cross-compile: mise run build

[tasks.build]
description = "Build all packages with CGO disabled."
run = "CGO_ENABLED=0 go build ./..."

[tasks.test]
description = "Run tests with -race."
run = "go test ./... -race -count=1"

[tasks.lint]
description = "Auto-fix then check against .golangci.yml."
run = ["golangci-lint --version", "golangci-lint run --fix", "golangci-lint run"]
3 changes: 1 addition & 2 deletions cmd/easyp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import (
"encoding/hex"
"flag"
"fmt"
"log/slog"
"net/http"
"os"
"runtime/debug"
"strings"
"time"

"log/slog"

"github.com/easyp-tech/server/cmd/easyp/internal/config"
"github.com/easyp-tech/server/cmd/easyp/internal/config/cachetype"
"github.com/easyp-tech/server/internal/connect"
Expand Down
3 changes: 2 additions & 1 deletion e2e/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"strings"
"testing"

"github.com/easyp-tech/server/e2e/testutil"
"github.com/stretchr/testify/require"

"github.com/easyp-tech/server/e2e/testutil"
)

// generatePinnedRef is the ref used by TestGenerateWithPinnedBufLock. It
Expand Down
2 changes: 1 addition & 1 deletion e2e/old_proto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestOldProtocolBufModUpdateTwice(t *testing.T) {
deps:
- 127.0.0.1:%d/googleapis/googleapis
`, srv.Port)
if err := os.WriteFile(filepath.Join(tmpDir, "buf.yaml"), []byte(bufYAML), 0600); err != nil {
if err := os.WriteFile(filepath.Join(tmpDir, "buf.yaml"), []byte(bufYAML), 0o600); err != nil {
t.Fatalf("writing buf.yaml: %v", err)
}

Expand Down
16 changes: 10 additions & 6 deletions e2e/testutil/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ func runBufUpdate(t *testing.T, bufBinary string, port int, ref, subcommand stri
deps:
- %s
`, depRef)
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "buf.yaml"), []byte(bufYAML), 0600), "writing buf.yaml")
require.NoError(t,
os.WriteFile(filepath.Join(tmpDir, "buf.yaml"), []byte(bufYAML), 0o600),
"writing buf.yaml")

// Write a dummy proto file so modern buf CLI versions don't complain about empty workspace.
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "dummy.proto"), []byte(`syntax = "proto3"; package dummy;`), 0600), "writing dummy.proto")
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "dummy.proto"), []byte(`syntax = "proto3"; package dummy;`), 0o600), "writing dummy.proto")

// Run buf update.
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
Expand Down Expand Up @@ -258,11 +260,13 @@ func runBufGenerate(t *testing.T, bufBinary string, port int, pinnedCommit strin
deps:
- %s
`, depRef)
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "buf.yaml"), []byte(bufYAML), 0600), "writing buf.yaml")
require.NoError(t,
os.WriteFile(filepath.Join(tmpDir, "buf.yaml"), []byte(bufYAML), 0o600),
"writing buf.yaml")

// Write a dummy proto so modern buf CLI versions don't complain about
// an empty workspace.
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "dummy.proto"), []byte(`syntax = "proto3"; package dummy;`), 0600), "writing dummy.proto")
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "dummy.proto"), []byte(`syntax = "proto3"; package dummy;`), 0o600), "writing dummy.proto")

// Write buf.gen.yaml. The remote plugin version is pinned; the v1
// buf.gen.yaml format is understood by both v1.30.1 and v1.69.0.
Expand All @@ -274,7 +278,7 @@ plugins:
- plugin: buf.build/protocolbuffers/go:v1.28.1
out: gen/go
`
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "buf.gen.yaml"), []byte(bufGenYAML), 0600), "writing buf.gen.yaml")
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, "buf.gen.yaml"), []byte(bufGenYAML), 0o600), "writing buf.gen.yaml")

// Step 1: buf mod update to populate a real buf.lock.
{
Expand Down Expand Up @@ -308,7 +312,7 @@ plugins:
modified := strings.Replace(string(lockContent), originalCommit, pinnedCommit, 1)
require.NotEqual(t, string(lockContent), modified,
"overwrite did not change buf.lock: commit %q not found", originalCommit)
require.NoError(t, os.WriteFile(lockPath, []byte(modified), 0600), "writing overwritten buf.lock")
require.NoError(t, os.WriteFile(lockPath, []byte(modified), 0o600), "writing overwritten buf.lock")

// Step 3: buf generate with the overwritten lock. Longer timeout
// than the mod update step because the plugin fetch + codegen
Expand Down
5 changes: 3 additions & 2 deletions e2e/testutil/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ func TestConfigGeneration(t *testing.T) {
// Verify file mode is 0600.
info, err := os.Stat(cfgPath)
require.NoError(t, err, "stat config file")
assert.Equal(t, os.FileMode(0600), info.Mode().Perm(), "config file mode should be 0600")
assert.Equal(t, os.FileMode(0o600), info.Mode().Perm(),
"config file mode should be 0600")
}

func TestRequireEnvToken_Skips(t *testing.T) {
Expand Down Expand Up @@ -113,7 +114,7 @@ func TestGetBuf_CachePath(t *testing.T) {

// Check execute bit is set.
mode := info.Mode()
assert.NotZero(t, mode.Perm()&0111,
assert.NotZero(t, mode.Perm()&0o111,
"buf binary should be executable (at least one execute bit set)")

// Verify it is actually a binary (starts with Mach-O or ELF magic, or is a script).
Expand Down
3 changes: 1 addition & 2 deletions internal/connect/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package connect

import (
"context"
"log/slog"
"net/http"
"time"

"log/slog"

"connectrpc.com/connect"

v1alpha1connect "github.com/easyp-tech/server/gen/proto/buf/alpha/registry/v1alpha1/v1alpha1connect"
Expand Down
Loading
Loading