infra-dashboard/.gitlab-ci.yml

103 lines
2.9 KiB
YAML

workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: never
# NO DEPLOYMENT
- if: '$CI_COMMIT_TAG == null'
variables:
IMAGE_TAG: $CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA
CONTAINER_IMAGE: $CI_REGISTRY_IMAGE:$IMAGE_TAG
# STAGING/PRODUCTION - tags only
- if: '$CI_COMMIT_TAG =~ /(alpha)|(beta)|(rc)/'
variables:
IMAGE_TAG: $CI_COMMIT_TAG
CONTAINER_IMAGE: $CI_REGISTRY_IMAGE:$IMAGE_TAG
ENVIRONMENT: 'staging'
ENVIRONMENT_SHORT: 'stg'
- if: '$CI_COMMIT_TAG'
variables:
IMAGE_TAG: $CI_COMMIT_TAG
CONTAINER_IMAGE: $CI_REGISTRY_IMAGE:$IMAGE_TAG
ENVIRONMENT: 'production'
ENVIRONMENT_SHORT: 'prd'
variables:
SRC_ROOT_PATH: ./app
stages:
- lint
- build
- test
- release
# ###########################################
# Lint
# ###########################################
linter:
image: golangci/golangci-lint:v2.0.2-alpine
rules:
- changes:
- .gitlab-ci.yml
- app/*
- app/*/*
when: always
stage: lint
before_script:
- cd $SRC_ROOT_PATH
script:
- go mod tidy
- golangci-lint run --output.code-climate.path gl-code-quality-report.json --path-prefix /app/
artifacts:
reports:
codequality: $SRC_ROOT_PATH/gl-code-quality-report.json
build:application_test:
extends: .build:image
stage: build
variables:
BUILD_TARGET: dev
BUILD_IMAGE_DESTINATION: ${CONTAINER_IMAGE}_dev
BUILD_ARGS: ""
# ###########################################
# Test
# ###########################################
go:tests:
image: ${CONTAINER_IMAGE}_dev
stage: test
before_script:
- cd $SRC_ROOT_PATH
- go mod download
- go install github.com/jstemmer/go-junit-report@latest
- go install github.com/boumenot/gocover-cobertura@latest
script:
- echo "Execute tests"
- go test ./... -v 2>&1 | go-junit-report > report-gotest.xml
- echo "Compute coverage"
- go test ./... -v -coverprofile=coverage.txt -covermode count
- gocover-cobertura < coverage.txt > report-coverage.xml
coverage: '/^coverage: \d+.\d+% of statements/'
artifacts:
reports:
junit: $SRC_ROOT_PATH/report-gotest.xml
coverage_report:
coverage_format: cobertura
path: $SRC_ROOT_PATH/report-coverage.xml
# ###########################################
# Build
# ###########################################
build:application:
extends: .build:image
stage: release
rules:
- if: '$CI_COMMIT_TAG'
when: on_success
variables:
BUILD_TARGET: prod
BUILD_IMAGE_DESTINATION: ${CONTAINER_IMAGE}
BUILD_ARGS: ""