-
Notifications
You must be signed in to change notification settings - Fork 1
214 lines (200 loc) · 10.2 KB
/
pytest-reusable-workflow.yml
File metadata and controls
214 lines (200 loc) · 10.2 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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
name: Run Pytest and Upload Coverage
on:
workflow_call:
inputs:
service_name:
required: true
type: string
service_path:
required: true
type: string
docker_registry:
required: true
type: string
secrets:
aws_access_key_ztna:
required: true
aws_secret_key_ztna:
required: true
gcr_token_ztna:
required: true
repo_owner_ztna:
required: true
gcr_token:
required: true
aws_s3_bucket:
required: true
jobs:
Pytest-workflow:
name: Run Tests and Coverage
runs-on: ubuntu-latest
env:
SERVICE_NAME: ${{inputs.service_name}}
DOCKER_REGISTRY: ${{inputs.docker_registry}}
steps:
- name: Check Out Code
uses: actions/checkout@v2
with:
token: ${{ secrets.gcr_token_ztna }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.repo_owner_ztna }}
password: ${{ secrets.gcr_token_ztna }}
- name: Set AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.aws_access_key_ztna }}
aws-secret-access-key: ${{ secrets.aws_secret_key_ztna }}
aws-region: eu-west-1
- name: Set Environment Variables and Run Auth Test
if: ${{(github.event_name == 'pull_request') && (env.SERVICE_NAME == 'auth-service' )}}
# if: env.SERVICE_NAME == 'auth-service'
id: auth-coverage
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ZTNA }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY_ZTNA }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd local-deployment/tests/
echo "" > .env
SHORT_COMMIT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`
branch_name=${GITHUB_REF##*/}
component_name=${SERVICE_NAME}
S3_bucket=${{ secrets.aws_s3_bucket }}
S3_path="s3://${S3_bucket}/${branch_name}/${component_name}"
build_version=$(aws s3 cp --quiet ${S3_path}/${component_name}.version - | awk -F';' '{print $2}')
echo "AUTH_DOCKER_IMAGE_NAME=$DOCKER_REGISTRY/$component_name:${branch_name}-${SHORT_COMMIT_SHA}" >> .env
echo "IS_TESTING:true" >> .env
docker-compose -f docker-compose.auth-test.yml up -d
docker exec -u root tests_auth-service_1 python3 -m pytest --durations=10 -n 4 --cov --cov-report xml:/usr/src/app/coverage.xml --junitxml=pytest.xml || true
docker cp tests_auth-service_1:/usr/src/app/coverage.xml auth-coverage.xml
docker cp tests_auth-service_1:/usr/src/app/pytest.xml auth-pytest.xml
echo "coverage=true" >> $GITHUB_OUTPUT
- name: Set Environment Variables and Run Resource Test
if: ${{(github.event_name == 'pull_request') && (env.SERVICE_NAME == 'resource-service' )}}
id: resource-coverage
# if: env.SERVICE_NAME == 'resource-service'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ZTNA }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY_ZTNA }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd local-deployment/tests/
echo "" > .env
SHORT_COMMIT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`
branch_name=${GITHUB_REF##*/}
component_name=${SERVICE_NAME}
S3_bucket=${{ secrets.aws_s3_bucket }}
S3_path="s3://${S3_bucket}/${branch_name}/${component_name}"
build_version=$(aws s3 cp --quiet ${S3_path}/${component_name}.version - | awk -F';' '{print $2}')
echo "RESOURCE_DOCKER_IMAGE_NAME=$DOCKER_REGISTRY/$component_name:${branch_name}-${SHORT_COMMIT_SHA}" >> .env
echo "IS_TESTING:true" >> .env
docker-compose -f docker-compose.resource-test.yml up -d
docker exec -u root tests_resource-service_1 python3 -m pytest api/tests --durations=10 -n 4 --cov --cov-report xml:/usr/src/app/coverage.xml --junitxml=pytest.xml || true
docker cp tests_resource-service_1:/usr/src/app/coverage.xml resource-coverage.xml
docker cp tests_resource-service_1:/usr/src/app/pytest.xml resource-pytest.xml
echo "coverage=true" >> $GITHUB_OUTPUT
- name: Set Environment Variables and Run Analytics Test
if: ${{(github.event_name == 'pull_request') && (env.SERVICE_NAME == 'analytics-service' )}}
id: analytics-coverage
# if: env.SERVICE_NAME == 'analytics-service'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ZTNA }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY_ZTNA }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd local-deployment/
echo "" > .env
SHORT_COMMIT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`
branch_name=${GITHUB_REF##*/}
component_name=${SERVICE_NAME}
S3_bucket=${{ secrets.aws_s3_bucket }}
S3_path="s3://${S3_bucket}/${branch_name}/${component_name}"
build_version=$(aws s3 cp --quiet ${S3_path}/${component_name}.version - | awk -F';' '{print $2}')
echo "ANALYTICS_DOCKER_IMAGE_NAME=$DOCKER_REGISTRY/$component_name:${branch_name}-${SHORT_COMMIT_SHA}" >> .env
# echo "ANALYTICS_DOCKER_IMAGE_NAME=ghcr.io/extremenetworks/web-controller/${{ env.SERVICE_NAME }}:${{ env.branch_name }}-${{ env.build_version }}-${{ env.SHORT_COMMIT_SHA }}" >> .env
# echo "IS_TESTING:true" >> .env
echo "CLICKHOUSE_VERSION=23.5.3" >> .env
echo "IS_TESTING:true" >> .env
docker-compose -f docker-compose.activity-logs.yml up -d
docker exec -u root analytics-service python3 -m pytest --durations=10 --cov --cov-report xml:/usr/src/app/coverage.xml --junitxml=pytest.xml || true
docker cp analytics-service:/usr/src/app/coverage.xml analytics-coverage.xml
docker cp analytics-service:/usr/src/app/pytest.xml analytics-pytest.xml
echo "coverage=true" >> $GITHUB_OUTPUT
- name: Pytest coverage comment for auth service
if: steps.auth-coverage.outputs.coverage == 'true'
id: auth-coverageComment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-xml-coverage-path: local-deployment/tests/auth-coverage.xml
title: Auth Service Coverage Report
create-new-comment: true
junitxml-path: local-deployment/tests/auth-pytest.xml
junitxml-title: Auth Service Unit Tests Summary
report-only-changed-files: true
- name: Pytest coverage comment for resource service
if: steps.resource-coverage.outputs.coverage == 'true'
id: resource-coverageComment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-xml-coverage-path: local-deployment/tests/resource-coverage.xml
title: Resource Service Coverage Report
create-new-comment: true
junitxml-path: local-deployment/tests/resource-pytest.xml
junitxml-title: Resource Service Unit Tests Summary
report-only-changed-files: true
- name: Pytest coverage comment for analytics service
if: steps.analytics-coverage.outputs.coverage == 'true'
id: analytics-coverageComment
uses: MishaKav/pytest-coverage-comment@main
with:
pytest-xml-coverage-path: local-deployment/analytics-coverage.xml
title: Resource Service Coverage Report
create-new-comment: true
junitxml-path: local-deployment/analytics-pytest.xml
junitxml-title: Analytics Service Unit Tests Summary
report-only-changed-files: true
- name: Upload Auth Coverage Report
if: steps.auth-coverage.outputs.coverage == 'true'
uses: actions/upload-artifact@v2
with:
name: auth-coverage.xml
path: local-deployment/tests/auth-coverage.xml
- name: Upload Resource Coverage Report
if: steps.resource-coverage.outputs.coverage == 'true'
uses: actions/upload-artifact@v2
with:
name: resource-coverage.xml
path: local-deployment/tests/resource-coverage.xml
- name: Upload Analytics Coverage Report
if: steps.analytics-coverage.outputs.coverage == 'true'
uses: actions/upload-artifact@v2
with:
name: analytics-coverage.xml
path: local-deployment/analytics-coverage.xml
- name: terminate workflow on auth service unit test failure
if: env.SERVICE_NAME == 'auth-service'
run: |
failures=${{ steps.auth-coverageComment.outputs.failures }}
if [ "$failures" -ne 0 ]; then
echo "Pytest failures detected. Exiting workflow."
exit 1
fi
- name: terminate workflow on resource service unit test failure
if: env.SERVICE_NAME == 'resource-service'
run: |
failures=${{ steps.resource-coverageComment.outputs.failures }}
if [ "$failures" -ne 0 ]; then
echo "Pytest failures detected. Exiting workflow."
exit 1
fi
- name: terminate workflow on analytics service unit test failure
if: env.SERVICE_NAME == 'analytics-service'
run: |
failures=${{ steps.analytics-coverageComment.outputs.failures }}
if [ "$failures" -ne 0 ]; then
echo "Pytest failures detected. Exiting workflow."
exit 1
fi