From cf96ac5cb02ddddb73acc04110bc5a2e1a5ece49 Mon Sep 17 00:00:00 2001 From: DoDiODev Date: Mon, 28 Sep 2026 12:56:14 +0200 Subject: [PATCH] fix(build): make go mod tidy work on a fresh clone backend/mocks/ is git-ignored, but helpers/unithelper and 22 test files import five of its packages. On a fresh clone those import paths do not exist inside the main module, so go mod tidy tries to resolve them as external modules and fails with "no matching versions for query latest". This also keeps Dependabot's gomod updater from producing any update. Track one doc.go placeholder (package mocks, no code) in each imported mock package, so the paths resolve locally. The generated mocks stay git-ignored, and make mock now removes only the generated files instead of the whole directory. Add a step to the unit-test workflow that runs go mod tidy on the fresh checkout, before any mocks are generated, and fails on a diff. A new mock import without a placeholder, or an untidy go.mod, is caught there. Refs #9088 --- .github/workflows/test.yml | 5 ++++ .gitignore | 5 +++- backend/Makefile | 4 ++- backend/mocks/core/context/doc.go | 25 +++++++++++++++++++ backend/mocks/core/dal/doc.go | 25 +++++++++++++++++++ backend/mocks/core/log/doc.go | 25 +++++++++++++++++++ backend/mocks/core/plugin/doc.go | 25 +++++++++++++++++++ backend/mocks/helpers/pluginhelper/api/doc.go | 25 +++++++++++++++++++ 8 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 backend/mocks/core/context/doc.go create mode 100644 backend/mocks/core/dal/doc.go create mode 100644 backend/mocks/core/log/doc.go create mode 100644 backend/mocks/core/plugin/doc.go create mode 100644 backend/mocks/helpers/pluginhelper/api/doc.go diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5fe88805b49..1e2542b2c4f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,6 +51,11 @@ jobs: run: backend/scripts/install-libgit2.sh - name: Install Go 1.26.6 run: backend/scripts/install-go.sh + - name: Check go.mod is tidy without generated mocks + run: | + cd backend + go mod tidy + git diff --exit-code -- go.mod go.sum - name: Install mockery 3.7.4 run: backend/scripts/install-mockery.sh - name: Build Python diff --git a/.gitignore b/.gitignore index 88f07eb195b..0877343e6bc 100644 --- a/.gitignore +++ b/.gitignore @@ -154,7 +154,10 @@ libgit2 .playwright-cli/ # auto generated code -backend/mocks/ +# backend/mocks: only the doc.go placeholders are tracked, they keep the mock +# import paths resolvable for `go mod tidy` on a fresh clone +backend/mocks/**/*.go +!backend/mocks/**/doc.go backend/server/api/docs/swagger.json backend/server/api/docs/swagger.yaml backend/server/api/docs/docs.go diff --git a/backend/Makefile b/backend/Makefile index e5aa539d59a..aeab9c379d5 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -72,7 +72,9 @@ debug: build-plugin-debug dlv debug server/main.go mock: - rm -rf mocks + # Remove previously generated mocks but keep the tracked doc.go placeholders, + # which keep the mock import paths resolvable for `go mod tidy`. + if [ -d mocks ]; then find mocks -type f ! -name doc.go -delete && find mocks -type d -empty -delete; fi # mockery v3 is configured via YAML instead of CLI flags. Two invocations are # required (and must run in this order): `helpers/unithelper` imports the # generated `mocks/core/...` packages, and v3 type-checks the sources it diff --git a/backend/mocks/core/context/doc.go b/backend/mocks/core/context/doc.go new file mode 100644 index 00000000000..df7d32afd2c --- /dev/null +++ b/backend/mocks/core/context/doc.go @@ -0,0 +1,25 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package mocks holds the mockery-generated mocks for +// github.com/apache/devlake/core/context. +// +// Only this file is tracked. The mocks themselves are generated by +// `make mock` and git-ignored; this placeholder keeps the import path +// resolvable inside the main module, so that `go mod tidy` works on a +// fresh clone. +package mocks diff --git a/backend/mocks/core/dal/doc.go b/backend/mocks/core/dal/doc.go new file mode 100644 index 00000000000..8d47a63a3df --- /dev/null +++ b/backend/mocks/core/dal/doc.go @@ -0,0 +1,25 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package mocks holds the mockery-generated mocks for +// github.com/apache/devlake/core/dal. +// +// Only this file is tracked. The mocks themselves are generated by +// `make mock` and git-ignored; this placeholder keeps the import path +// resolvable inside the main module, so that `go mod tidy` works on a +// fresh clone. +package mocks diff --git a/backend/mocks/core/log/doc.go b/backend/mocks/core/log/doc.go new file mode 100644 index 00000000000..dc5b4aa3ab9 --- /dev/null +++ b/backend/mocks/core/log/doc.go @@ -0,0 +1,25 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package mocks holds the mockery-generated mocks for +// github.com/apache/devlake/core/log. +// +// Only this file is tracked. The mocks themselves are generated by +// `make mock` and git-ignored; this placeholder keeps the import path +// resolvable inside the main module, so that `go mod tidy` works on a +// fresh clone. +package mocks diff --git a/backend/mocks/core/plugin/doc.go b/backend/mocks/core/plugin/doc.go new file mode 100644 index 00000000000..3f75e2bf22a --- /dev/null +++ b/backend/mocks/core/plugin/doc.go @@ -0,0 +1,25 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package mocks holds the mockery-generated mocks for +// github.com/apache/devlake/core/plugin. +// +// Only this file is tracked. The mocks themselves are generated by +// `make mock` and git-ignored; this placeholder keeps the import path +// resolvable inside the main module, so that `go mod tidy` works on a +// fresh clone. +package mocks diff --git a/backend/mocks/helpers/pluginhelper/api/doc.go b/backend/mocks/helpers/pluginhelper/api/doc.go new file mode 100644 index 00000000000..9b121974935 --- /dev/null +++ b/backend/mocks/helpers/pluginhelper/api/doc.go @@ -0,0 +1,25 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package mocks holds the mockery-generated mocks for +// github.com/apache/devlake/helpers/pluginhelper/api. +// +// Only this file is tracked. The mocks themselves are generated by +// `make mock` and git-ignored; this placeholder keeps the import path +// resolvable inside the main module, so that `go mod tidy` works on a +// fresh clone. +package mocks