Skip to content

Commit

Permalink
skip specified tests when build snapshot image
Browse files Browse the repository at this point in the history
  • Loading branch information
mayswind committed Dec 8, 2024
1 parent 964ad6d commit 5b6f245
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitea/workflows/docker-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
4 changes: 3 additions & 1 deletion .github/workflows/docker-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
labels: ${{ steps.meta.outputs.labels }}
4 changes: 3 additions & 1 deletion .github/workflows/non-main-branch-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ jobs:
file: Dockerfile
context: .
platforms: linux/amd64
push: false
push: false
build-args: |
SKIP_TESTS="${{ vars.SKIP_TESTS }}"
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 9 additions & 2 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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="
Expand Down Expand Up @@ -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 ^<filename^> 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

Expand Down Expand Up @@ -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"
Expand Down
11 changes: 9 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
TYPE=""
NO_LINT="0"
NO_TEST="0"
SKIP_TESTS="${SKIP_TESTS}"
RELEASE=${RELEASE_BUILD:-"0"}
RELEASE_TYPE="unknown"
VERSION=""
Expand Down Expand Up @@ -43,7 +44,7 @@ Options:
-o, --output <filename> 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
}
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 5b6f245

Please sign in to comment.