From 2c2ca47e827a93496ff339a61a51e91ed04ffb43 Mon Sep 17 00:00:00 2001 From: DoDiODev Date: Tue, 28 Jul 2026 11:47:34 +0200 Subject: [PATCH 1/3] =?UTF-8?q?build(deps):=20mockery=20v2=E2=86=92v3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upgrade the mock generator from mockery v2.53.6 to v3.7.2 at every install site (backend/Makefile, backend/Dockerfile, backend/Dockerfile.local, devops/docker/lake-builder/Dockerfile). mockery v3 dropped the CLI flags used by the `mock` target and is configured via YAML instead, so two config files are added: - backend/.mockery.core.yml - backend/.mockery.helpers.yml They reproduce the exact layout produced by the previous v2 invocations (--recursive --keeptree --dir=./ --output=./mocks/ --unroll-variadic=false --name='.*'): backend/mocks//.go, package `mocks`, un-prefixed mock struct names. Existing test imports such as `mockdal "github.com/apache/incubator-devlake/mocks/core/dal"` therefore keep working unchanged. Two configs (instead of one) are required because `helpers/unithelper` imports the generated `mocks/core/...` packages: unlike v2, v3 type-checks sources via go/packages, so the core mocks must exist before the helpers tree can be loaded. The `mock` target runs them in that order. Note: v3 only generates mocks for interfaces, no longer for function types. The affected mocks (e.g. plugin.ApiAsyncCallback, api.DataConvertHandler, errors.Option) were not used by any test. `backend/mocks/` is gitignored, so there is no generated-code churn in this diff. Validation: `make mock`, `go build ./...` and `scripts/unit-test-go.sh` (60 packages) all pass. Signed-off-by: DoDiODev --- backend/.mockery.core.yml | 39 +++++++++++++++++++++++++++ backend/.mockery.helpers.yml | 36 +++++++++++++++++++++++++ backend/Dockerfile | 2 +- backend/Dockerfile.local | 2 +- backend/Makefile | 10 ++++--- devops/docker/lake-builder/Dockerfile | 2 +- 6 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 backend/.mockery.core.yml create mode 100644 backend/.mockery.helpers.yml diff --git a/backend/.mockery.core.yml b/backend/.mockery.core.yml new file mode 100644 index 00000000000..067e79cfecc --- /dev/null +++ b/backend/.mockery.core.yml @@ -0,0 +1,39 @@ +# 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. + +# mockery v3 configuration for the ./core tree. +# +# Replaces the v2 command line +# mockery --recursive --keeptree --dir=./core --output=./mocks/core \ +# --unroll-variadic=false --name='.*' +# and reproduces the exact same layout: backend/mocks/core//.go +# with package name `mocks` and an un-prefixed mock struct name. +# +# NOTE: this config is deliberately kept separate from `.mockery.helpers.yml`. +# `helpers/unithelper` imports the generated `mocks/core/...` packages, so the +# core mocks have to exist before the helpers tree can be type-checked by +# mockery v3 (which, unlike v2, loads packages via go/packages). +all: true +recursive: true +template: testify +dir: "mocks/{{.InterfaceDirRelative}}" +filename: "{{.InterfaceName}}.go" +pkgname: "mocks" +structname: "{{.InterfaceName}}" +template-data: + unroll-variadic: false +packages: + github.com/apache/incubator-devlake/core: + diff --git a/backend/.mockery.helpers.yml b/backend/.mockery.helpers.yml new file mode 100644 index 00000000000..79f5014bf01 --- /dev/null +++ b/backend/.mockery.helpers.yml @@ -0,0 +1,36 @@ +# 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. + +# mockery v3 configuration for the ./helpers tree. +# +# Replaces the v2 command line +# mockery --recursive --keeptree --dir=./helpers --output=./mocks/helpers \ +# --unroll-variadic=false --name='.*' +# and reproduces the exact same layout: backend/mocks/helpers//.go +# with package name `mocks` and an un-prefixed mock struct name. +# +# Must run *after* `.mockery.core.yml` — see the note there. +all: true +recursive: true +template: testify +dir: "mocks/{{.InterfaceDirRelative}}" +filename: "{{.InterfaceName}}.go" +pkgname: "mocks" +structname: "{{.InterfaceName}}" +template-data: + unroll-variadic: false +packages: + github.com/apache/incubator-devlake/helpers: + diff --git a/backend/Dockerfile b/backend/Dockerfile index 87e9adaefd8..85fe1e258d1 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -49,7 +49,7 @@ RUN if [ "$(arch)" != "x86_64" ] ; then \ apt-get install -y gcc-x86-64-linux-gnu binutils-x86-64-linux-gnu ; \ fi -RUN go install github.com/vektra/mockery/v2@v2.53.6 +RUN go install github.com/vektra/mockery/v3@v3.7.2 RUN go install github.com/swaggo/swag/cmd/swag@v1.16.6 COPY --from=debian-amd64 /usr/include /rootfs-amd64/usr/include diff --git a/backend/Dockerfile.local b/backend/Dockerfile.local index 2fadbcec90e..c244a886a2f 100644 --- a/backend/Dockerfile.local +++ b/backend/Dockerfile.local @@ -47,7 +47,7 @@ RUN mkdir -p /tmp/build && cd /tmp/build && \ make -j$(nproc) install && \ ldconfig -RUN go install github.com/vektra/mockery/v2@v2.53.6 +RUN go install github.com/vektra/mockery/v3@v3.7.2 RUN go install github.com/swaggo/swag/cmd/swag@v1.16.6 WORKDIR /app diff --git a/backend/Makefile b/backend/Makefile index 7aca0a2e471..8dde31dc6bf 100644 --- a/backend/Makefile +++ b/backend/Makefile @@ -27,7 +27,7 @@ PYTHON_DIR ?= "./python" all: build go-dep: - go install github.com/vektra/mockery/v2@v2.53.6 + go install github.com/vektra/mockery/v3@v3.7.2 go install github.com/swaggo/swag/cmd/swag@v1.16.6 go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2 @@ -73,8 +73,12 @@ debug: build-plugin-debug mock: rm -rf mocks - mockery --recursive --keeptree --dir=./core --output=./mocks/core --unroll-variadic=false --name='.*' - mockery --recursive --keeptree --dir=./helpers --output=./mocks/helpers --unroll-variadic=false --name='.*' + # 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 + # parses, so the core mocks have to exist before the helpers tree loads. + mockery --config .mockery.core.yml + mockery --config .mockery.helpers.yml test: unit-test e2e-test diff --git a/devops/docker/lake-builder/Dockerfile b/devops/docker/lake-builder/Dockerfile index be6e31f3d7e..3ef2744522e 100644 --- a/devops/docker/lake-builder/Dockerfile +++ b/devops/docker/lake-builder/Dockerfile @@ -62,7 +62,7 @@ RUN mv /root/go /go &&\ # Install Golang Tools RUN export GOPATH=/go && \ - go install github.com/vektra/mockery/v2@v2.53.6 && \ + go install github.com/vektra/mockery/v3@v3.7.2 && \ go install github.com/swaggo/swag/cmd/swag@v1.16.1 # Golang Env From a5beab6e846e74ebf9a8ee023f4bbad67781cd60 Mon Sep 17 00:00:00 2001 From: DoDiODev Date: Tue, 11 Aug 2026 11:25:56 +0200 Subject: [PATCH 2/3] ci: bootstrap mockery 3 in lint workflow Signed-off-by: DoDiODev --- .github/workflows/golangci-lint.yml | 2 + backend/.mockery.core.yml | 1 - backend/.mockery.helpers.yml | 1 - backend/scripts/install-mockery.sh | 100 ++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 2 deletions(-) create mode 100755 backend/scripts/install-mockery.sh diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index cc68c18cac2..d625667ce44 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -32,6 +32,8 @@ jobs: - uses: actions/checkout@v6 - name: Install libgit2 1.5 for git2go v34 run: backend/scripts/install-libgit2.sh + - name: Install mockery 3.7.2 + run: backend/scripts/install-mockery.sh - name: Cache golangci-lint id: cache-golangci-lint uses: actions/cache@v5 diff --git a/backend/.mockery.core.yml b/backend/.mockery.core.yml index 067e79cfecc..352a9ab90cb 100644 --- a/backend/.mockery.core.yml +++ b/backend/.mockery.core.yml @@ -36,4 +36,3 @@ template-data: unroll-variadic: false packages: github.com/apache/incubator-devlake/core: - diff --git a/backend/.mockery.helpers.yml b/backend/.mockery.helpers.yml index 79f5014bf01..ef703c5931c 100644 --- a/backend/.mockery.helpers.yml +++ b/backend/.mockery.helpers.yml @@ -33,4 +33,3 @@ template-data: unroll-variadic: false packages: github.com/apache/incubator-devlake/helpers: - diff --git a/backend/scripts/install-mockery.sh b/backend/scripts/install-mockery.sh new file mode 100755 index 00000000000..b748fe5e218 --- /dev/null +++ b/backend/scripts/install-mockery.sh @@ -0,0 +1,100 @@ +#!/bin/sh +# +# 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. + +set -eu + +MOCKERY_VERSION=3.7.2 +INSTALL_DIR=/opt/mockery/$MOCKERY_VERSION +MOCKERY_BIN=$INSTALL_DIR/mockery + +get_version() { + if version_output=$("$1" version 2>/dev/null); then + : + else + version_output=$("$1" --version 2>&1 || true) + fi + printf '%s\n' "$version_output" | + tr ' =' '\n' | + sed -n 's/^v\{0,1\}\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)$/\1/p' | + head -n 1 +} + +use_installed_mockery() { + export PATH="$INSTALL_DIR:$PATH" + if [ -n "${GITHUB_PATH:-}" ]; then + echo "$INSTALL_DIR" >> "$GITHUB_PATH" + fi +} + +current_mockery=$(command -v mockery 2>/dev/null || true) +if [ -n "$current_mockery" ]; then + current_version=$(get_version "$current_mockery" || true) + if [ "$current_version" = "$MOCKERY_VERSION" ]; then + echo "mockery $current_version is already installed" + exit 0 + fi +fi + +if [ -x "$MOCKERY_BIN" ]; then + installed_version=$(get_version "$MOCKERY_BIN" || true) + if [ "$installed_version" = "$MOCKERY_VERSION" ]; then + use_installed_mockery + echo "mockery $installed_version is already installed in $INSTALL_DIR" + exit 0 + fi +fi + +case "$(uname -m)" in + x86_64|amd64) + archive_name=mockery_${MOCKERY_VERSION}_Linux_x86_64.tar.gz + archive_sha256=db819b897de126634cefeb3773a3b76eea7769c718f0e5e62e968ab00add12c6 + ;; + aarch64|arm64) + archive_name=mockery_${MOCKERY_VERSION}_Linux_arm64.tar.gz + archive_sha256=27141b83d8bccc29d66ed91093da69604b320d417bd562d819c8b0372f1444ad + ;; + *) + echo "unsupported architecture: $(uname -m)" >&2 + exit 1 + ;; +esac + +if [ "$(id -u)" -ne 0 ]; then + echo "install-mockery.sh must run as root" >&2 + exit 1 +fi + +download_url=https://github.com/vektra/mockery/releases/download/v${MOCKERY_VERSION}/${archive_name} +work_dir=$(mktemp -d) +trap 'rm -rf "$work_dir"' EXIT HUP INT TERM + +archive=$work_dir/$archive_name +curl --fail --location --retry 3 "$download_url" --output "$archive" +echo "$archive_sha256 $archive" | sha256sum --check --strict + +tar -xzf "$archive" -C "$work_dir" +mkdir -p "$INSTALL_DIR" +install -m 0755 "$work_dir/mockery" "$MOCKERY_BIN" + +use_installed_mockery +installed_version=$(get_version "$MOCKERY_BIN") +if [ "$installed_version" != "$MOCKERY_VERSION" ]; then + echo "expected mockery $MOCKERY_VERSION, found ${installed_version:-unknown}" >&2 + exit 1 +fi + +echo "installed mockery $installed_version in $INSTALL_DIR" From a6bd93dc34f64496e2b33cf77f978096e9be6edf Mon Sep 17 00:00:00 2001 From: DoDiODev Date: Wed, 12 Aug 2026 09:54:09 +0200 Subject: [PATCH 3/3] ci: bootstrap mockery 3 in unit-test workflow Signed-off-by: DoDiODev --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 485ae5c72f6..ae9d080e6ca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,6 +49,8 @@ jobs: run: git config --global --add safe.directory $(pwd) - name: Install libgit2 1.5 for git2go v34 run: backend/scripts/install-libgit2.sh + - name: Install mockery 3.7.2 + run: backend/scripts/install-mockery.sh - name: Build Python run: | cd backend