From 5400a1424c544d00ad591701fe6cd91b5ef18f92 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Wed, 2 Jul 2025 22:17:25 +0800 Subject: [PATCH] do not check third party response when run tests in ci pipeline --- .gitea/workflows/docker-release.yml | 2 ++ .gitea/workflows/docker-snapshot.yml | 4 +++- .github/workflows/docker-release.yml | 2 ++ .github/workflows/docker-snapshot.yml | 2 ++ .github/workflows/non-main-branch-build.yml | 2 ++ Dockerfile | 6 ++++++ pkg/exchangerates/http_exchange_rates_datasource_test.go | 5 +++++ 7 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.gitea/workflows/docker-release.yml b/.gitea/workflows/docker-release.yml index e5186131..0acca35e 100644 --- a/.gitea/workflows/docker-release.yml +++ b/.gitea/workflows/docker-release.yml @@ -54,6 +54,8 @@ jobs: push: true build-args: | RELEASE_BUILD=1 + BUILD_PIPELINE=1 + CHECK_3RD_API=${{ vars.CHECK_3RD_API }} SKIP_TESTS=${{ vars.SKIP_TESTS }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/.gitea/workflows/docker-snapshot.yml b/.gitea/workflows/docker-snapshot.yml index b5696985..1356d796 100644 --- a/.gitea/workflows/docker-snapshot.yml +++ b/.gitea/workflows/docker-snapshot.yml @@ -53,6 +53,8 @@ jobs: platforms: ${{ vars.BUILD_SNAPSHOT_PLATFORMS }} push: true build-args: | - SKIP_TESTS=${{ vars.SKIP_TESTS }} + BUILD_PIPELINE=1 + CHECK_3RD_API=${{ vars.CHECK_3RD_API }} + SKIP_TESTS=${{ vars.SKIP_TESTS }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index e9d359c8..97bbc3a0 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -50,6 +50,8 @@ jobs: push: true build-args: | RELEASE_BUILD=1 + BUILD_PIPELINE=1 + CHECK_3RD_API=${{ vars.CHECK_3RD_API }} 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 3ae6c643..b93d6997 100644 --- a/.github/workflows/docker-snapshot.yml +++ b/.github/workflows/docker-snapshot.yml @@ -48,6 +48,8 @@ jobs: linux/arm/v6 push: true build-args: | + BUILD_PIPELINE=1 + CHECK_3RD_API=${{ vars.CHECK_3RD_API }} SKIP_TESTS=${{ vars.SKIP_TESTS }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/non-main-branch-build.yml b/.github/workflows/non-main-branch-build.yml index 1b2fe5a4..e162de30 100644 --- a/.github/workflows/non-main-branch-build.yml +++ b/.github/workflows/non-main-branch-build.yml @@ -27,4 +27,6 @@ jobs: platforms: linux/amd64 push: false build-args: | + BUILD_PIPELINE=1 + CHECK_3RD_API=${{ vars.CHECK_3RD_API }} SKIP_TESTS=${{ vars.SKIP_TESTS }} diff --git a/Dockerfile b/Dockerfile index 09b52e68..45d81864 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,12 @@ # Build backend binary file FROM golang:1.24.4-alpine3.22 AS be-builder ARG RELEASE_BUILD +ARG BUILD_PIPELINE +ARG CHECK_3RD_API ARG SKIP_TESTS ENV RELEASE_BUILD=$RELEASE_BUILD +ENV BUILD_PIPELINE=$BUILD_PIPELINE +ENV CHECK_3RD_API=$CHECK_3RD_API ENV SKIP_TESTS=$SKIP_TESTS WORKDIR /go/src/github.com/mayswind/ezbookkeeping COPY . . @@ -13,7 +17,9 @@ RUN ./build.sh backend # Build frontend files FROM --platform=$BUILDPLATFORM node:22.16.0-alpine3.22 AS fe-builder ARG RELEASE_BUILD +ARG BUILD_PIPELINE ENV RELEASE_BUILD=$RELEASE_BUILD +ENV BUILD_PIPELINE=$BUILD_PIPELINE WORKDIR /go/src/github.com/mayswind/ezbookkeeping COPY . . RUN docker/frontend-build-pre-setup.sh diff --git a/pkg/exchangerates/http_exchange_rates_datasource_test.go b/pkg/exchangerates/http_exchange_rates_datasource_test.go index 593b4884..a3f41468 100644 --- a/pkg/exchangerates/http_exchange_rates_datasource_test.go +++ b/pkg/exchangerates/http_exchange_rates_datasource_test.go @@ -2,6 +2,7 @@ package exchangerates import ( "net/http/httptest" + "os" "testing" "github.com/gin-gonic/gin" @@ -310,6 +311,10 @@ func TestExchangeRatesApiLatestExchangeRateHandler_InternationalMonetaryFundData } func executeLatestExchangeRateHandler(t *testing.T, dataSourceType string) *models.LatestExchangeRateResponse { + if os.Getenv("BUILD_PIPELINE") == "1" && os.Getenv("CHECK_3RD_API") != "1" { + return nil + } + config := &settings.Config{ ExchangeRatesDataSource: dataSourceType, ExchangeRatesRequestTimeout: 10000,