diff --git a/.gitea/workflows/docker-snapshot.yml b/.gitea/workflows/docker-snapshot.yml index ec9b2349..c278418d 100644 --- a/.gitea/workflows/docker-snapshot.yml +++ b/.gitea/workflows/docker-snapshot.yml @@ -50,5 +50,7 @@ jobs: context: . platforms: ${{ vars.BUILD_SNAPSHOT_PLATFORMS }} push: true + build-args: | + SKIP_TESTS="${{ vars.SKIP_TESTS }}" tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/docker-snapshot.yml b/.github/workflows/docker-snapshot.yml index 97b6e196..2a40e8cd 100644 --- a/.github/workflows/docker-snapshot.yml +++ b/.github/workflows/docker-snapshot.yml @@ -45,5 +45,7 @@ jobs: linux/arm/v7 linux/arm/v6 push: true + build-args: | + SKIP_TESTS="${{ vars.SKIP_TESTS }}" tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/non-main-branch-build.yml b/.github/workflows/non-main-branch-build.yml index 67a1fcc1..6ddfaafc 100644 --- a/.github/workflows/non-main-branch-build.yml +++ b/.github/workflows/non-main-branch-build.yml @@ -25,4 +25,6 @@ jobs: file: Dockerfile context: . platforms: linux/amd64 - push: false \ No newline at end of file + push: false + build-args: | + SKIP_TESTS="${{ vars.SKIP_TESTS }}" diff --git a/Dockerfile b/Dockerfile index 3dc984b4..bdc25eb7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,9 @@ # Build backend binary file FROM golang:1.22.8-alpine3.20 AS be-builder ARG RELEASE_BUILD +ARG SKIP_TESTS ENV RELEASE_BUILD=$RELEASE_BUILD +ENV SKIP_TESTS=$SKIP_TESTS WORKDIR /go/src/github.com/mayswind/ezbookkeeping COPY . . RUN docker/backend-build-pre-setup.sh diff --git a/build.bat b/build.bat index e9fcfc1e..b7aa23f4 100644 --- a/build.bat +++ b/build.bat @@ -3,6 +3,7 @@ set "TYPE=" set "NO_LINT=0" set "NO_TEST=0" +set "SKIP_TESTS=%SKIP_TESTS%" set "RELEASE=%RELEASE_BUILD%" set "RELEASE_TYPE=unknown" set "VERSION=" @@ -56,7 +57,7 @@ goto :pre_parse_args echo /r, --release Build release (The script will use environment variable "RELEASE_BUILD" to detect whether this is release building by default) echo /o, --output ^ Package file name (For "package" type only) echo --no-lint Do not execute lint check before building - echo --no-test Do not execute unit testing before building + echo --no-test Do not execute unit testing before building (You can use environment variable "SKIP_TESTS" to skip specified tests) echo /h, --help Show help goto :eof @@ -139,7 +140,13 @@ goto :pre_parse_args if "%NO_TEST%"=="0" ( echo Executing backend unit testing... call go clean -cache - call go test .\... -v + + if "%SKIP_TESTS%"=="" ( + call go test .\... -v + ) else ( + echo (Skip unit test "%SKIP_TESTS%") + call go test .\... -v -skip "%SKIP_TESTS%" + ) if !errorlevel! neq 0 ( call :echo_red "Error: Failed to pass unit testing" diff --git a/build.sh b/build.sh index f37563ba..f9cd27f1 100755 --- a/build.sh +++ b/build.sh @@ -3,6 +3,7 @@ TYPE="" NO_LINT="0" NO_TEST="0" +SKIP_TESTS="${SKIP_TESTS}" RELEASE=${RELEASE_BUILD:-"0"} RELEASE_TYPE="unknown" VERSION="" @@ -43,7 +44,7 @@ Options: -o, --output Package file name (For "package" type only) -t, --tag Docker tag (For "docker" type only) --no-lint Do not execute lint check before building - --no-test Do not execute unit testing before building + --no-test Do not execute unit testing before building (You can use environment variable "SKIP_TESTS" to skip specified tests) -h, --help Show help EOF } @@ -137,7 +138,13 @@ build_backend() { if [ "$NO_TEST" = "0" ]; then echo "Executing backend unit testing..." go clean -cache - go test ./... -v + + if [ -z "$SKIP_TESTS" ]; then + go test ./... -v + else + echo "(Skip unit test \"$SKIP_TESTS\")" + go test ./... -v -skip "$SKIP_TESTS" + fi if [ "$?" != "0" ]; then echo_red "Error: Failed to pass unit testing"