-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
142 lines (136 loc) · 4.12 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
142 lines (136 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
stages:
- test
- test-coverage
- build
- deploy
unit_tests:
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push"
image:
name: python:3.13.11
variables:
PRE_COMMIT_HOME: "$CI_PROJECT_DIR/.cache/pre-commit"
cache:
key: $CI_COMMIT_REF_NAME
paths:
- $PRE_COMMIT_HOME
- .venv
before_script:
- python3 -m venv .venv
- source .venv/bin/activate
- pip install poetry==2.1.3
- poetry config virtualenvs.in-project true
- poetry install --with test,dev
script:
- poetry run pre-commit run --all-files
- poetry run pytest --ignore test/core/ --cov --cov-report term --cov-report xml:coverage.xml
- poetry run pytest test/core/
coverage: '/TOTAL.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
paths:
- coverage.xml
test_coverage_threshold:
stage: test-coverage
dependencies:
- unit_tests
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push"
image:
name: python:3.13.11
before_script:
- apt-get update && apt-get install -y bc
script:
- coverage="$(grep -oP '<coverage[^>]+line-rate="\K[0-9.]+' "coverage.xml")"
- |
if (( $(echo "$coverage < 0.8" | bc -l) )); then
echo "Code coverage is only $(echo "$coverage*100" | bc)%. We recommend a minimum of 80%." && exit 1;
else
exit 0;
fi
allow_failure:
exit_codes:
- 1
optional_linting:
stage: test
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
image:
name: python:3.13.11
variables:
PRE_COMMIT_HOME: "$CI_PROJECT_DIR/.cache/pre-commit"
cache:
key: $CI_COMMIT_REF_NAME
paths:
- $PRE_COMMIT_HOME
- .venv
before_script:
- python3 -m venv .venv
- source .venv/bin/activate
- pip install pre-commit
script:
- pre-commit run -c .pre-commit-config-optional-linting.yaml --all-files
allow_failure:
exit_codes:
- 1
build_staging:
stage: build
tags: [ k8s ]
rules:
- if: $CI_COMMIT_BRANCH == "main" && $CI_PIPELINE_SOURCE == "push"
image: docker.io/docker:cli
before_script:
- echo ${CI_DOCKER_TOKEN} | docker --config ~/ca_config login ${REGISTRY_URL} -u ${CI_DOCKER_USER} --password-stdin
- docker --config ~/ca_config buildx create --use --name=kube --driver remote tcp://amd64-buildkit-service.ci-cd.svc:1234
script:
- |
docker --config ~/ca_config \
buildx build \
--builder=kube \
--build-arg "CI_COMMIT_SHORT_SHA=${CI_COMMIT_SHORT_SHA}" \
--cache-from=type=registry,ref=${REGISTRY_URL}/${GROUP_NAME}/${CI_PROJECT_NAME}:buildcache \
--cache-to=type=registry,ref=${REGISTRY_URL}/${GROUP_NAME}/${CI_PROJECT_NAME}:buildcache,mode=max \
--tag ${REGISTRY_URL}/${GROUP_NAME}/${CI_PROJECT_NAME}:devel \
--tag ${REGISTRY_URL}/${GROUP_NAME}/${CI_PROJECT_NAME}:staging \
--push \
.
build_release:
stage: build
tags: [ k8s ]
rules:
- if: $CI_COMMIT_TAG
image: docker.io/docker:cli
before_script:
- echo ${CI_DOCKER_TOKEN} | docker --config ~/ca_config login ${REGISTRY_URL} -u ${CI_DOCKER_USER} --password-stdin
- docker --config ~/ca_config buildx create --use --name=kube --driver remote tcp://amd64-buildkit-service.ci-cd.svc:1234
script:
- |
docker --config ~/ca_config \
buildx build \
--builder=kube \
--platform=linux/amd64 \
--tag ${REGISTRY_URL}/${GROUP_NAME}/${CI_PROJECT_NAME}:${CI_COMMIT_TAG} \
--push \
.
deploy_staging:
stage: deploy
tags: [ k8s-kta ]
needs:
- build_staging
rules:
- !reference [ build_staging, rules ]
image: repo.heigit.org/heigit/argocd-cli:latest
script:
- |
argocd app actions \
run ca-staging/${ARGOCD_STAGING_APPLICATION_NAME} \
restart --kind Deployment \
--server ${ARGOCD_SERVER} \
--auth-token ${ARGOCD_AUTH_TOKEN}\
--resource-name can-${CI_PROJECT_NAME}