From 6880f1b0d326f8dccaa9b78ce5f23f1d557f2eb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 7 May 2026 10:11:17 +0200 Subject: [PATCH 1/2] ci: run golangci-lint on the Caddy module Adds a second golangci-lint step scoped to caddy/ on the same job as the root lint. Fixes the pre-existing issues that surfaced: - admin.go: propagate the success() error instead of dropping it - admin_test.go: assert resp.Body.Close() with require.NoError - app.go: rename iniError to errIni (ST1012) - mercure.go: lowercase the leading article in error strings (ST1005) --- .github/workflows/tests.yaml | 6 ++++++ caddy/admin.go | 3 +-- caddy/admin_test.go | 5 +++-- caddy/app.go | 8 ++++---- caddy/mercure.go | 4 ++-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index d98b61ac18..e4dc11f922 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -91,6 +91,12 @@ jobs: if: matrix.php-versions == '8.5' with: version: latest + - name: Lint Caddy module Go code + uses: golangci/golangci-lint-action@v9 + if: matrix.php-versions == '8.5' + with: + version: latest + working-directory: caddy - name: Ensure go.mod is tidy if: matrix.php-versions == '8.5' run: go mod tidy -diff diff --git a/caddy/admin.go b/caddy/admin.go index 8515f11326..c973df239d 100644 --- a/caddy/admin.go +++ b/caddy/admin.go @@ -41,9 +41,8 @@ func (admin *FrankenPHPAdmin) restartWorkers(w http.ResponseWriter, r *http.Requ frankenphp.RestartWorkers() caddy.Log().Info("workers restarted from admin api") - admin.success(w, "workers restarted successfully\n") - return nil + return admin.success(w, "workers restarted successfully\n") } func (admin *FrankenPHPAdmin) threads(w http.ResponseWriter, _ *http.Request) error { diff --git a/caddy/admin_test.go b/caddy/admin_test.go index f5ec8c4c7a..91ec386f3e 100644 --- a/caddy/admin_test.go +++ b/caddy/admin_test.go @@ -15,6 +15,7 @@ import ( "github.com/caddyserver/caddy/v2/caddytest" "github.com/dunglas/frankenphp" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestRestartWorkerViaAdminApi(t *testing.T) { @@ -245,7 +246,7 @@ func getAdminResponseBody(t *testing.T, tester *caddytest.Tester, method string, r, err := http.NewRequest(method, adminUrl+path, nil) assert.NoError(t, err) resp := tester.AssertResponseCode(r, http.StatusOK) - defer resp.Body.Close() + defer func() { require.NoError(t, resp.Body.Close()) }() bytes, err := io.ReadAll(resp.Body) assert.NoError(t, err) @@ -319,7 +320,7 @@ func TestAddModuleWorkerViaAdminApi(t *testing.T) { assert.NoError(t, err) r.Header.Set("Content-Type", "text/caddyfile") resp := tester.AssertResponseCode(r, http.StatusOK) - defer resp.Body.Close() + defer func() { require.NoError(t, resp.Body.Close()) }() // Get the updated debug state to check if the worker was added updatedDebugState := getDebugState(t, tester) diff --git a/caddy/app.go b/caddy/app.go index fbe72eb620..f10bf965bf 100644 --- a/caddy/app.go +++ b/caddy/app.go @@ -66,7 +66,7 @@ type FrankenPHPApp struct { logger *slog.Logger } -var iniError = errors.New(`"php_ini" must be in the format: php_ini "" ""`) +var errIni = errors.New(`"php_ini" must be in the format: php_ini "" ""`) // CaddyModule returns the Caddy module information. func (f FrankenPHPApp) CaddyModule() caddy.ModuleInfo { @@ -274,14 +274,14 @@ func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { parseIniLine := func(d *caddyfile.Dispenser) error { key := d.Val() if !d.NextArg() { - return d.WrapErr(iniError) + return d.WrapErr(errIni) } if f.PhpIni == nil { f.PhpIni = make(map[string]string) } f.PhpIni[key] = d.Val() if d.NextArg() { - return d.WrapErr(iniError) + return d.WrapErr(errIni) } return nil @@ -298,7 +298,7 @@ func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { if !isBlock { if !d.NextArg() { - return d.WrapErr(iniError) + return d.WrapErr(errIni) } err := parseIniLine(d) if err != nil { diff --git a/caddy/mercure.go b/caddy/mercure.go index 841c062ea2..502f32895c 100644 --- a/caddy/mercure.go +++ b/caddy/mercure.go @@ -40,12 +40,12 @@ func (f *FrankenPHPModule) assignMercureHub(ctx caddy.Context) { func createMercureRoute() (caddyhttp.Route, error) { mercurePublisherJwtKey := os.Getenv("MERCURE_PUBLISHER_JWT_KEY") if mercurePublisherJwtKey == "" { - return caddyhttp.Route{}, errors.New(`The "MERCURE_PUBLISHER_JWT_KEY" environment variable must be set to use the Mercure.rocks hub`) + return caddyhttp.Route{}, errors.New(`the "MERCURE_PUBLISHER_JWT_KEY" environment variable must be set to use the Mercure.rocks hub`) } mercureSubscriberJwtKey := os.Getenv("MERCURE_SUBSCRIBER_JWT_KEY") if mercureSubscriberJwtKey == "" { - return caddyhttp.Route{}, errors.New(`The "MERCURE_SUBSCRIBER_JWT_KEY" environment variable must be set to use the Mercure.rocks hub`) + return caddyhttp.Route{}, errors.New(`the "MERCURE_SUBSCRIBER_JWT_KEY" environment variable must be set to use the Mercure.rocks hub`) } mercureRoute := caddyhttp.Route{ From 6af5c351c5ff033daec67e743b072102e38a9e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Thu, 7 May 2026 10:51:47 +0200 Subject: [PATCH 2/2] directories with slashes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Kévin Dunglas --- .github/workflows/tests.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index e4dc11f922..b4299db99c 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -96,7 +96,7 @@ jobs: if: matrix.php-versions == '8.5' with: version: latest - working-directory: caddy + working-directory: caddy/ - name: Ensure go.mod is tidy if: matrix.php-versions == '8.5' run: go mod tidy -diff