-
Notifications
You must be signed in to change notification settings - Fork 21
/
.gitlab-ci.yml
183 lines (164 loc) · 6.47 KB
/
.gitlab-ci.yml
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#variables: # global variables section
# PIPELINE_VERSION: &pipeline-tag adrian.marza/CI-1172_add_extra_git_fetch_to_sonar_merge_jobs
#
#include:
# - project: 'mambucom/product/sre/release-engineering/templates/gitlab-ci-pipeline'
# ref: *pipeline-tag
# file: '/sonarqube/sonarqube-enterprise-no-compilation.yml'
image: registry.gitlab.com/mambucom/product/sre/release-engineering/selfmanagedservices/tools/docker/python:3.9-bullseye
stages:
- test
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' || $CI_PIPELINE_SOURCE == 'web'
- if: $CI_COMMIT_BRANCH =~ /^release\/[0-9]+/
unit-test-job:
stage: test
artifacts:
expire_in: 20 minutes
paths:
- coverage.xml
before_script:
- python3 -m pip install --upgrade -e ".[mambu-tests]"
script:
- echo "Running unit tests..."
- coverage run --branch --source=tap_mambu -m pytest mambu_tests
- coverage json
- coverage xml -i
- mkdir coverage-reports
- python3 -c "import json; coverage_json = json.loads(open('coverage.json', 'r').read()); print('Coverage is', round(coverage_json['totals']['percent_covered'], 2))"
lint-test-job:
stage: test
before_script:
- python3 -m pip install --upgrade -e ".[mambu-tests]"
script:
- echo "Linting code..."
- pylint tap_mambu --exit-zero
- pylint tap_mambu -d C -d R -d W || true
snyk-dependency-test-job:
image:
snyk/snyk-cli:python-3.9
# registry.gitlab.com/mambucom/product/sre/release-engineering/selfmanagedservices/tools/docker/snyk/snyk-cli:python-3.9
stage: test
before_script:
- python3 -m venv venv
- source venv/bin/activate
- pip install --upgrade pip
- pip install --upgrade "setuptools<58"
- pip install wheel
- pip install --upgrade -e .
- pip freeze > requirements.txt
script:
- snyk test --severity-threshold=high
snyk-dev-dependency-test-job:
image:
snyk/snyk-cli:python-3.9
# registry.gitlab.com/mambucom/product/sre/release-engineering/selfmanagedservices/tools/docker/snyk/snyk-cli:python-3.9
stage: test
before_script:
- python3 -m venv venv
- source venv/bin/activate
- pip install --upgrade pip
- pip install --upgrade "setuptools<58"
- pip install wheel
- pip install --upgrade -e ".[mambu-tests]"
- pip freeze > requirements.txt
script:
- snyk test --severity-threshold=critical
snyk-code-test-job:
image:
snyk/snyk-cli:python-3.9
# registry.gitlab.com/mambucom/product/sre/release-engineering/selfmanagedservices/tools/docker/snyk/snyk-cli:python-3.9
stage: test
script:
- snyk code test
sonarqube_enterprise_nocompile_branch_analysis_poc:
image: registry.gitlab.com/mambucom/product/sre/release-engineering/selfmanagedservices/tools/sonar-scanner-cli:1.4.0-ef55044f
stage: test
needs: ["unit-test-job"]
allow_failure: true
variables:
SONAR_EXCLUSIONS: '**/*.xml'
# this variable can be overridden in the job or the project
# space-separated values, e.g."-Dsonar.foo.bar=baz -Dsonar.cheese.ham=eggs"
SONAR_EXTRA_PARAMETERS: ''
script:
- set -euo pipefail
- export SONAR_SCANNER_OPTS="-Xmx3072m"
- sonar-scanner -X
-Dsonar.host.url='https://sonarqube-enterprise.infra.mambucloud.com'
-Dsonar.login="$SONAR_ENTERPRISE_LOGIN"
-Dsonar.gitlab.project_id="$CI_PROJECT_PATH"
-Dsonar.gitlab.commit_sha="$CI_COMMIT_SHA"
-Dsonar.gitlab.ref_name="$CI_COMMIT_REF_NAME"
-Dsonar.gitlab.max_blocker_issues_gate=-1
-Dsonar.gitlab.max_critical_issues_gate=-1
-Dsonar.gitlab.failure_notification_mode=exit-code
-Dsonar.sonar.qualitygate.wait=true
-Dsonar.projectVersion="${CI_COMMIT_SHA:0:8}"
-Dsonar.branch.name="$CI_COMMIT_REF_NAME"
-Dsonar.projectKey="${CI_PROJECT_PATH//\//.}"
-Dsonar.projectName="$CI_PROJECT_NAME"
-Dsonar.exclusions="$SONAR_EXCLUSIONS"
$SONAR_EXTRA_PARAMETERS
except:
refs:
- tags
sonarqube_enterprise_nocompile_pr_decoration_poc:
image: registry.gitlab.com/mambucom/product/sre/release-engineering/selfmanagedservices/tools/sonar-scanner-cli:1.4.0-ef55044f
stage: test
needs: ["unit-test-job"]
allow_failure: true
variables:
SONAR_EXCLUSIONS: '**/*.xml'
# this variable can be overridden in the job or the project
# space-separated values, e.g."-Dsonar.foo.bar=baz -Dsonar.cheese.ham=eggs"
SONAR_EXTRA_PARAMETERS: ''
script:
- set -euo pipefail
- set -x
# needing the variable: GITLAB_READ_API_TOKEN to be present
# exporting MR-based variables because sonar-scanner needs them for pr decoration
- export CI_MERGE_REQUEST_IID="$(mrepo gitlab get-mr-for-branch --project-id $CI_PROJECT_ID --branch $CI_COMMIT_REF_NAME --format=iid)"
- >
if [ -z "$CI_MERGE_REQUEST_IID" ];
then
echo "Can't find a merge request for this branch: $CI_COMMIT_REF_NAME Exiting...";
exit 0;
fi
- export CI_MERGE_REQUEST_SOURCE_BRANCH_NAME="$CI_COMMIT_REF_NAME"
- export CI_MERGE_REQUEST_TARGET_BRANCH_NAME="$(mrepo gitlab get-mr-for-branch --project-id $CI_PROJECT_ID --branch $CI_COMMIT_REF_NAME --format=target_branch --fatal)"
- export SONAR_SCANNER_OPTS="-Xmx3072m"
- sonar-scanner -X
-Dsonar.host.url='https://sonarqube-enterprise.infra.mambucloud.com'
-Dsonar.login="$SONAR_ENTERPRISE_LOGIN"
-Dsonar.gitlab.project_id="$CI_PROJECT_PATH"
-Dsonar.gitlab.commit_sha="$CI_COMMIT_SHA"
-Dsonar.gitlab.ref_name="$CI_COMMIT_REF_NAME"
-Dsonar.gitlab.max_blocker_issues_gate=-1
-Dsonar.gitlab.max_critical_issues_gate=-1
-Dsonar.gitlab.failure_notification_mode=exit-code
-Dsonar.projectVersion="${CI_COMMIT_SHA:0:8}"
-Dsonar.projectKey="${CI_PROJECT_PATH//\//.}"
-Dsonar.projectName="${CI_PROJECT_PATH//\//.}"
-Dsonar.exclusions="$SONAR_EXCLUSIONS"
-Dsonar.qualitygate.wait=true
-Dsonar.gitlab.unique_issue_per_inline=true
$SONAR_EXTRA_PARAMETERS
except:
refs:
- master
- tags
tap-tester-job:
image: registry.gitlab.com/mambucom/product/ecosystem/mambu-marketplace/connectors/singer/taptester/tap-tester:dev-6
stage: test
before_script:
- pip install --upgrade -e .
script:
- source /tap_tester/tap_tester_venv/bin/activate
- >
STITCH_TARGET_PATH=/tap_tester/target_stitch_venv/bin/target-stitch
TAP_MAMBU_SUBDOMAIN="$TAP_MAMBU_SUBDOMAIN"
TAP_MAMBU_USERNAME="$TAP_MAMBU_USERNAME"
TAP_MAMBU_PASSWORD="$TAP_MAMBU_PASSWORD"
/tap_tester/tap_tester_raw/bin/run-test --tap=/usr/local/bin/tap-mambu tests