diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml index 91c43e97..da19c1cd 100644 --- a/.github/workflows/ci-backend.yml +++ b/.github/workflows/ci-backend.yml @@ -32,7 +32,7 @@ jobs: - name: install go uses: actions/setup-go@v5 with: - go-version: "1.23" + go-version: "1.25" cache-dependency-path: backend - name: test and build backend @@ -53,15 +53,15 @@ jobs: TZ: "America/Chicago" - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: - version: "v1.64.7" + version: "v2.6.0" working-directory: backend/app - name: golangci-lint on example directory - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: - version: "v1.64.7" + version: "v2.6.0" args: --config ../../.golangci.yml working-directory: backend/_example/memory_store diff --git a/CLAUDE.md b/CLAUDE.md index c8aeae17..431272d7 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -8,12 +8,15 @@ - **Backend Testing**: - Run all tests: `cd backend/app && go test -timeout=60s -count 1 ./...` - Run single test: `cd backend/app && go test -run TestName ./path/to/package` + - **IMPORTANT**: Run example tests: `cd backend/_example/memory_store && go test -race ./... && go build -race ./...` - **Frontend**: - Development: `cd frontend && pnpm dev:app` - Tests: `cd frontend && pnpm test` - **Lint**: - - Backend: `golangci-lint run` + - Backend: `cd backend && golangci-lint run` + - **IMPORTANT**: Example lint: `cd backend/_example/memory_store && golangci-lint run --config ../../.golangci.yml` - Frontend: `cd frontend && pnpm lint` + - **Before committing**: Always run tests and linter on both main backend AND examples ## Code Style - **Backend**: Formatting with golangci-lint, strict error handling diff --git a/Dockerfile b/Dockerfile index d410f1da..9ced59e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,7 +45,7 @@ RUN \ echo 'Skip frontend build'; \ fi -FROM umputun/baseimage:buildgo-v1.14.0 AS build-backend +FROM umputun/baseimage:buildgo-v1.17.0 AS build-backend ARG CI ARG GITHUB_REF @@ -81,7 +81,7 @@ RUN \ echo "version=$version" && \ go build -o remark42 -ldflags "-X main.revision=${version} -s -w" ./app -FROM umputun/baseimage:app-v1.14.0 +FROM umputun/baseimage:app-v1.17.0 ARG GITHUB_SHA diff --git a/backend/.golangci.yml b/backend/.golangci.yml index e6929d67..024c0e92 100644 --- a/backend/.golangci.yml +++ b/backend/.golangci.yml @@ -1,29 +1,6 @@ -run: - timeout: 5m - -linters-settings: - govet: - enable: - - shadow - goconst: - min-len: 2 - min-occurrences: 2 - misspell: - locale: US - lll: - line-length: 140 - gocritic: - enabled-tags: - - performance - - style - - experimental - disabled-checks: - - wrapperFunc -# TODO: feel free to remove these excludes and fix the code - - hugeParam - - rangeValCopy - +version: "2" linters: + default: none enable: - bodyclose - copyloopvar @@ -32,7 +9,6 @@ linters: - gocritic - gocyclo - gosec - - gosimple - govet - ineffassign - misspell @@ -40,26 +16,51 @@ linters: - prealloc - revive - staticcheck - - stylecheck - - typecheck - unconvert - unparam - unused - fast: false - disable-all: true - -issues: - exclude-dirs: - - vendor - exclude-rules: - - text: "at least one file in a package should have a package comment" - linters: - - stylecheck - - text: "package-comments: should have a package comment" - linters: - - revive - - path: _test\.go - linters: - - gosec - - dupl - exclude-use-default: false + settings: + goconst: + min-len: 2 + min-occurrences: 2 + gocritic: + disabled-checks: + - wrapperFunc + - hugeParam + - rangeValCopy + enabled-tags: + - performance + - style + - experimental + govet: + enable: + - shadow + lll: + line-length: 140 + misspell: + locale: US + exclusions: + generated: lax + rules: + - linters: + - staticcheck + text: at least one file in a package should have a package comment + - linters: + - revive + text: 'package-comments: should have a package comment' + - linters: + - dupl + - gosec + path: _test\.go + paths: + - vendor + - third_party$ + - builtin$ + - examples$ +formatters: + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/backend/_example/memory_store/Dockerfile b/backend/_example/memory_store/Dockerfile index 3f1fd996..777aa432 100644 --- a/backend/_example/memory_store/Dockerfile +++ b/backend/_example/memory_store/Dockerfile @@ -1,11 +1,11 @@ -FROM umputun/baseimage:buildgo-v1.14.0 AS build-backend +FROM umputun/baseimage:buildgo-v1.17.0 AS build-backend ADD backend /build/backend WORKDIR /build/backend/_example/memory_store RUN go build -o /build/bin/memory_store -ldflags "-X main.revision=0.0.0 -s -w" -FROM umputun/baseimage:app-v1.14.0 +FROM umputun/baseimage:app-v1.17.0 ARG GITHUB_SHA diff --git a/backend/_example/memory_store/accessor/data.go b/backend/_example/memory_store/accessor/data.go index 2703aa46..6ac74465 100644 --- a/backend/_example/memory_store/accessor/data.go +++ b/backend/_example/memory_store/accessor/data.go @@ -391,10 +391,7 @@ func (m *MemData) checkFlag(req engine.FlagRequest) (val bool) { func (m *MemData) setFlag(req engine.FlagRequest) (res bool, err error) { - status := false - if req.Update == engine.FlagTrue { - status = true - } + status := req.Update == engine.FlagTrue switch req.Flag { diff --git a/backend/_example/memory_store/go.mod b/backend/_example/memory_store/go.mod index 6f8b4bf3..df7c7fa3 100644 --- a/backend/_example/memory_store/go.mod +++ b/backend/_example/memory_store/go.mod @@ -1,8 +1,6 @@ module github.com/umputun/remark42/memory_store -go 1.23.0 - -toolchain go1.24.1 +go 1.25 require ( github.com/go-pkgz/jrpc v0.3.1 diff --git a/backend/app/main_test.go b/backend/app/main_test.go index 68d5c33d..bb67eeac 100644 --- a/backend/app/main_test.go +++ b/backend/app/main_test.go @@ -98,9 +98,6 @@ func TestMain_WithWebhook(t *testing.T) { finished := make(chan struct{}) go func() { main() - assert.Eventually(t, func() bool { - return atomic.LoadInt32(&webhookSent) == int32(1) - }, time.Second, 100*time.Millisecond, "webhook was not sent") close(finished) }() @@ -117,6 +114,11 @@ func TestMain_WithWebhook(t *testing.T) { require.NoError(t, err) defer resp.Body.Close() assert.Equal(t, http.StatusCreated, resp.StatusCode) + + // wait for webhook to be sent before shutting down + assert.Eventually(t, func() bool { + return atomic.LoadInt32(&webhookSent) == int32(1) + }, time.Second, 100*time.Millisecond, "webhook was not sent") } func TestGetDump(t *testing.T) { diff --git a/backend/app/notify/notify_mock.go b/backend/app/notify/notify_mock.go index 0a50df1d..9244f6c1 100644 --- a/backend/app/notify/notify_mock.go +++ b/backend/app/notify/notify_mock.go @@ -66,4 +66,15 @@ func (m *MockDest) GetVerify() []VerificationRequest { return res } -func (m *MockDest) String() string { return fmt.Sprintf("mock id=%d, closed=%v", m.id, m.closed) } +// IsClosed returns closed status safely +func (m *MockDest) IsClosed() bool { + m.lock.Lock() + defer m.lock.Unlock() + return m.closed +} + +func (m *MockDest) String() string { + m.lock.Lock() + defer m.lock.Unlock() + return fmt.Sprintf("mock id=%d, closed=%v", m.id, m.closed) +} diff --git a/backend/app/notify/notify_test.go b/backend/app/notify/notify_test.go index 07b88c30..260a27c5 100644 --- a/backend/app/notify/notify_test.go +++ b/backend/app/notify/notify_test.go @@ -102,15 +102,17 @@ func TestService_Many(t *testing.T) { time.Sleep(time.Millisecond * time.Duration(rand.Int31n(20))) } s.Close() - time.Sleep(time.Millisecond * 10) + + // wait for destinations to close + assert.Eventually(t, func() bool { return d1.IsClosed() && d2.IsClosed() }, 100*time.Millisecond, 10*time.Millisecond) assert.NotEqual(t, 10, len(d1.Get()), "some comments dropped from d1") assert.NotEqual(t, 10, len(d1.GetVerify()), "some verifications dropped from d1") assert.NotEqual(t, 10, len(d2.Get()), "some comments dropped from d2") assert.NotEqual(t, 10, len(d2.GetVerify()), "some verifications dropped from d2") - assert.True(t, d1.closed) - assert.True(t, d2.closed) + assert.True(t, d1.IsClosed()) + assert.True(t, d2.IsClosed()) assert.Equal(t, "mock id=1, closed=true", d1.String()) } diff --git a/backend/go.mod b/backend/go.mod index 41797fe2..1f9303a1 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -1,8 +1,6 @@ module github.com/umputun/remark42/backend -go 1.23.0 - -toolchain go1.24.2 +go 1.25 require ( github.com/Depado/bfchroma/v2 v2.0.0