ci: added go test job

This commit is contained in:
ITQ
2025-12-15 22:54:22 +03:00
parent 4e5199c69d
commit e51f228079
+40 -59
View File
@@ -1,5 +1,6 @@
stages: stages:
- build - build
- lint
- test - test
- sast - sast
- tag - tag
@@ -201,7 +202,7 @@ build-migrate:
SERVICE_NAME: migrate SERVICE_NAME: migrate
golangci-lint: golangci-lint:
stage: test stage: lint
image: docker.io/golangci/golangci-lint:latest-alpine image: docker.io/golangci/golangci-lint:latest-alpine
variables: variables:
GOLANGCI_LINT_CACHE: $CI_PROJECT_DIR/.cache/golangci-lint GOLANGCI_LINT_CACHE: $CI_PROJECT_DIR/.cache/golangci-lint
@@ -218,64 +219,31 @@ golangci-lint:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_TAG - if: $CI_COMMIT_TAG
# test: go-test:
# <<: *docker-job stage: test
# stage: test image: docker.io/library/golang:1.24-alpine
# tags: variables:
# - beta CGO_ENABLED: "0"
# variables: cache:
# COMPOSE_PROFILES: | key: "${CI_COMMIT_REF_SLUG}-go-mod"
# --profile migrations paths:
# --profile tests - /go/pkg/mod
# --profile ml - /root/.cache/go-build
# script: script:
# - apk add --no-cache docker-compose - apk add --no-cache git
# - export PROFILES="$(printf '%s ' $COMPOSE_PROFILES)" - go test ./... -coverprofile=coverage.out
# - cp "$TEST_STAGE_FIREBASE_CONF" ./infrastructure/configs/backend/firebase.json - go tool cover -func=coverage.out | tee coverage-func.txt
# - | - TOTAL=$(go tool cover -func=coverage.out | awk '/total:/ {print $3}' | sed 's/%//')
# ( - |
# while true; do echo "Total coverage: $TOTAL"
# docker compose -f compose.yaml $PROFILES logs -f 2>&1 echo "$TOTAL" | awk -v threshold=30 '{ if ($1+0 < threshold) { print "Coverage below threshold: " $1 "%"; exit 1 } }'
# sleep 1 artifacts:
# done paths:
# ) | tee -a compose.log & - coverage.out
# - LOGS_PID=$! - coverage-func.txt
# - | expire_in: 1 week
# REGISTRY_PREFIX=$CI_REGISTRY_IMAGE IMAGE_TAG=$CI_COMMIT_SHA \ when: always
# docker compose -f compose.yaml -f compose.prod.yaml \ coverage: '/TOTAL.+ ([0-9]{1,3}%)/'
# $PROFILES up -d --quiet-pull --quiet-build 2>&1 | tee compose.log
# - |
# TEST_CONTAINER_ID=$(docker compose -f compose.yaml $PROFILES ps -q tests -a)
# timeout 600 docker wait $TEST_CONTAINER_ID
# TEST_EXIT_CODE=$(docker inspect --format "{{.State.ExitCode}}" $TEST_CONTAINER_ID)
# if [ $TEST_EXIT_CODE -eq 0 ]; then
# echo "Tests passed."
# else
# echo "Tests failed with exit code $TEST_EXIT_CODE."
# exit 1
# fi
# - |
# docker compose -f compose.yaml $PROFILES down
# - cat .cov/coverage.txt
# artifacts:
# paths:
# - ./.cov
# - ./compose.log
# reports:
# coverage_report:
# coverage_format: cobertura
# path: .cov/coverage.xml
# expire_in: 1 week
# when: always
# coverage: /TOTAL.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/
# rules:
# - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# - if: $CI_PIPELINE_SOURCE == 'merge_request_event'
# dependencies:
# - build-runtime
# - build-tests
# - build-migrations
sast-filesystem: sast-filesystem:
<<: *trivy-fs-scan <<: *trivy-fs-scan
@@ -288,11 +256,24 @@ sast-image-auth:
dependencies: dependencies:
- build-auth - build-auth
sast-image-migrate:
<<: *trivy-image-scan
variables:
IMAGE_NAME: $BASE_IMAGE_NAME/migrate
IMAGE_TYPE: migrate
dependencies:
- build-migrate
tag-auth: tag-auth:
<<: *tag-config <<: *tag-config
variables: variables:
IMAGE_NAME: $BASE_IMAGE_NAME/auth IMAGE_NAME: $BASE_IMAGE_NAME/auth
tag-migrate:
<<: *tag-config
variables:
IMAGE_NAME: $BASE_IMAGE_NAME/migrate
# webhook-backend-deploy: # webhook-backend-deploy:
# <<: *webhook-config # <<: *webhook-config
# stage: deploy # stage: deploy