Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Bug][Build] go mod tidy fails on a fresh clone because backend/mocks/ is gitignored but imported by tracked sources

未关闭
#9,088 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
52/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
git, go

调研方向

从 .gitignore、Makefile:101、backend/Makefile:85 以及 helpers/unithelper 和 helpers/pluginhelper/api 中提到的导入开始。使用 go mod tidy 在全新 clone 中重现该失败,然后将其与执行 make mock 后的 tree 进行比较。当维护者选择的方案能够让 go mod tidy、go build ./... 和 go vet ./... 在无需未提交的 mock 生成步骤的情况下正常工作时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

Search before asking
  • I had searched in the issues and found no similar issues.
What happened

On a fresh clone of the repository, any Go tooling that loads the whole module fails, because backend/mocks/ is listed in .gitignore while tracked, non-test sources import it.

backend/helpers/unithelper imports mocks/core/context, mocks/core/dal, mocks/core/log and mocks/core/plugin; the helpers/pluginhelper/api tests import mocks/helpers/pluginhelper/api.

Since the directory does not exist in a clean checkout, Go cannot resolve these paths inside the module and tries to fetch them as external modules:

go: finding module for package github.com/apache/incubator-devlake/mocks/core/context
go: github.com/apache/incubator-devlake/helpers/unithelper imports
        github.com/apache/incubator-devlake/mocks/core/context: no matching versions for query "latest"
go: github.com/apache/incubator-devlake/helpers/unithelper imports
        github.com/apache/incubator-devlake/mocks/core/dal: no matching versions for query "latest"
go: github.com/apache/incubator-devlake/helpers/unithelper imports
        github.com/apache/incubator-devlake/mocks/core/log: no matching versions for query "latest"
go: github.com/apache/incubator-devlake/helpers/unithelper imports
        github.com/apache/incubator-devlake/mocks/core/plugin: no matching versions for query "latest"
go: github.com/apache/incubator-devlake/helpers/pluginhelper/api tested by
        github.com/apache/incubator-devlake/helpers/pluginhelper/api.test imports
        github.com/apache/incubator-devlake/mocks/helpers/pluginhelper/api: no matching versions for query "latest"

This affects go mod tidy, go build ./..., go vet ./... and editors/IDEs loading the module. It goes unnoticed in day-to-day work because make unit-test depends on mock (Makefile:101, backend/Makefile:85), which runs mockery first.

It also blocks automated dependency tooling. While preparing a Dependabot configuration I hit exactly this error in the gomod ecosystem — Dependabot runs go mod tidy after every version bump and aborts:

ERROR Error processing github.com/gin-gonic/gin (Dependabot::DependabotError)
/home/dependabot/go_modules/lib/dependabot/go_modules/file_updater/go_mod_updater.rb:350
  :in 'GoModUpdater#run_go_mod_tidy'
What do you expect to happen

A fresh clone should load with standard Go tooling without a mandatory code-generation step.

How to reproduce
git clone https://github.com/apache/devlake.git
cd devlake/backend
go mod tidy   # fails with the output above

Counter-check — after generating the mocks the very same tree is clean:

cd ..           # repo root
make mock       # delegates to `make mock -C backend`
cd backend
go mod tidy     # exit 0, no output

go.mod and go.sum remain byte-identical afterwards, so the module itself is consistent — the only defect is the missing directory.

Anything else

backend/mocks/ has been gitignored since 243cc8a80 ("refactor: refactor files/dirs of the whole repo for better organization", #3884, Jan 2023).

Possible directions — happy to send a PR for whichever the maintainers prefer:

  1. Commit the generated mocks (remove the .gitignore entry). 65 files, ~644 KB. A fresh clone would then work with plain Go tooling. Staleness can be guarded by a CI step running make mock followed by git diff --exit-code.
  2. Stop importing generated packages from tracked non-test sources, e.g. by reworking helpers/unithelper. Larger change, but keeps generated code out of the tree.
  3. Document it as intended and require make mock before any Go tooling. This keeps the status quo but leaves automated dependency updates for the Go ecosystem unavailable.

Note that a build tag does not help here: go mod tidy considers all build tags except ignore, and an ignore tag would also drop the package from regular builds.

Version

main (c8288c0cd)

Are you willing to submit PR?
  • Yes I am willing to submit a PR!
Code of Conduct
主要语言
Go
星标
3.1k
派生
812
平均合并
1 天 23 小时
30 天内合并 PR
51

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/devlake 的其他 Issue

查看 apache/devlake 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。