1
1
name : 🌊 Ocean Core Tests
2
2
3
3
on :
4
+ push :
5
+ branches :
6
+ - main
4
7
pull_request :
5
8
workflow_dispatch :
6
9
31
34
32
35
- name : Unit Test Core
33
36
env :
34
- PYTEST_ADDOPTS : --junitxml=junit/unit-test-results-ocean/core.xml
37
+ PYTEST_ADDOPTS : --cov --cov-report= --cov-append -- junitxml=junit/unit-test-results-ocean/core.xml
35
38
run : |
36
39
make test
37
40
50
53
51
54
- name : Smoke Test Core
52
55
env :
53
- PYTEST_ADDOPTS : --junitxml=junit/smoke-test-results-ocean/core.xml
56
+ PYTEST_ADDOPTS : --cov --cov-report= --cov-append -- junitxml=junit/smoke-test-results-ocean/core.xml
54
57
PORT_CLIENT_ID : ${{ secrets.PORT_CLIENT_ID }}
55
58
PORT_CLIENT_SECRET : ${{ secrets.PORT_CLIENT_SECRET }}
56
59
PORT_BASE_URL : ${{ secrets.PORT_BASE_URL }}
61
64
- name : Cleanup Smoke Test
62
65
if : always()
63
66
env :
64
- PYTEST_ADDOPTS : --junitxml=junit/smoke-test-results-ocean/core.xml
67
+ PYTEST_ADDOPTS : --cov --cov-report= --cov-append -- junitxml=junit/smoke-test-results-ocean/core.xml
65
68
PORT_CLIENT_ID : ${{ secrets.PORT_CLIENT_ID }}
66
69
PORT_CLIENT_SECRET : ${{ secrets.PORT_CLIENT_SECRET }}
67
70
PORT_BASE_URL : ${{ secrets.PORT_BASE_URL }}
@@ -77,7 +80,112 @@ jobs:
77
80
- name : Test all integrations with current core
78
81
run : |
79
82
echo "Testing all integrations with local core"
80
- SCRIPT_TO_RUN="PYTEST_ADDOPTS=--junitxml=${PWD}/junit/test-results-core-change/\`pwd | xargs basename\`.xml make test" make execute/all
83
+ SCRIPT_TO_RUN="PYTEST_ADDOPTS=\"--cov --cov-report= --cov-append --junitxml=${PWD}/junit/test-results-core-change/\`pwd | xargs basename\`.xml\" make test" make execute/all
84
+
85
+ - name : Get PR_NUMBER
86
+ id : pr-number
87
+ run : |
88
+ if [ ! -z ${{ inputs.PR_NUMBER }} ]; then
89
+ echo "PR_NUMBER=${{ inputs.PR_NUMBER }}" >> $GITHUB_OUTPUT
90
+ elif [ ! -z ${{ github.event.pull_request.number }} ]; then
91
+ echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT
92
+ else
93
+ echo "PR_NUMBER=0" >> $GITHUB_OUTPUT
94
+ fi
95
+
96
+ - name : Produce coverage report
97
+ run : |
98
+ mkdir -p coverage-merge
99
+ i=0
100
+ find . -type f -name ".coverage" | while read -r file; do
101
+ i=$((i + 1))
102
+ cp "$file" "coverage-merge/.coverage.$i"
103
+ done
104
+ make coverage
105
+
106
+ - name : Upload coverage report
107
+ id : upload-coverage
108
+ uses : actions/upload-artifact@v4
109
+ with :
110
+ name : coverage-report
111
+ path : htmlcov
112
+
113
+ - name : Set repo code coverage percentage by the percentage of statements covered in the tests
114
+ id : set-stmts-coverage
115
+ run : |
116
+ stmts=$(jq '.totals.percent_covered | . * 100 | round | . / 100' coverage.json)
117
+ echo "STMTS_COVERAGE=$stmts" >> $GITHUB_OUTPUT
118
+
119
+ - name : Comment PR with code coverage summary
120
+ uses : actions/github-script@v7
121
+ env :
122
+ CODE_COVERAGE_ARTIFACT_URL : ${{ steps.upload-coverage.outputs.artifact-url }}
123
+ PR_NUMBER : ${{ steps.pr-number.outputs.PR_NUMBER }}
124
+ with :
125
+ github-token : ${{ secrets.GITHUB_TOKEN }}
126
+ script : |
127
+ const output = `#### Code Coverage Artifact 📈: ${{ env.CODE_COVERAGE_ARTIFACT_URL }}
128
+ #### Code Coverage Total Percentage: \`${{ steps.set-stmts-coverage.outputs.STMTS_COVERAGE }}%\``;
129
+
130
+ github.rest.issues.createComment({
131
+ issue_number: ${{ env.PR_NUMBER }},
132
+ owner: context.repo.owner,
133
+ repo: context.repo.repo,
134
+ body: output
135
+ })
136
+
137
+ - name : Get current repo coverage percentage from Port
138
+ uses : port-labs/port-github-action@v1
139
+ id : get-current-coverage
140
+ with :
141
+ clientId : ${{ secrets.PORT_MAIN_CLIENT_ID }}
142
+ clientSecret : ${{ secrets.PORT_MAIN_CLIENT_SECRET }}
143
+ baseUrl : https://api.getport.io
144
+ operation : GET
145
+ identifier : ocean
146
+ blueprint : repository
147
+
148
+ - name : Set current code coverage
149
+ id : set-current-coverage
150
+ run : echo "CURRENT_COVERAGE=${{ fromJson(steps.get-current-coverage.outputs.entity).properties.coverage_percent }}" >> $GITHUB_OUTPUT
151
+
152
+ - name : Comment if Coverage Regression
153
+ if : ${{ (fromJson(steps.set-stmts-coverage.outputs.STMTS_COVERAGE) < fromJson(steps.set-current-coverage.outputs.CURRENT_COVERAGE)) && (steps.pr-number.outputs.PR_NUMBER != 0) }}
154
+ uses : actions/github-script@v7
155
+ env :
156
+ PR_NUMBER : ${{ steps.pr-number.outputs.PR_NUMBER }}
157
+ CURRENT_COVERAGE : ${{ steps.set-current-coverage.outputs.CURRENT_COVERAGE }}
158
+ NEW_COVERAGE : ${{ steps.set-stmts-coverage.outputs.STMTS_COVERAGE }}
159
+ with :
160
+ github-token : ${{ secrets.GITHUB_TOKEN }}
161
+ script : |
162
+ const output = `🚨 The new code coverage percentage is lower than the current one. Current coverage: \`${{ env.CURRENT_COVERAGE }}\`\n While the new one is: \`${{ env.NEW_COVERAGE }}\``;
163
+
164
+ github.rest.issues.createComment({
165
+ issue_number: ${{ env.PR_NUMBER }},
166
+ owner: context.repo.owner,
167
+ repo: context.repo.repo,
168
+ body: output
169
+ })
170
+
171
+ - name : Fail PR if current code coverage percentage is higher than the new one
172
+ if : ${{ (fromJson(steps.set-stmts-coverage.outputs.STMTS_COVERAGE) < fromJson(steps.set-current-coverage.outputs.CURRENT_COVERAGE)) && (vars.CODE_COVERAGE_ENFORCEMENT == 'true') }}
173
+ run : exit 1
174
+
175
+ - name : Update service code coverage percentage in Port
176
+ if : ${{ (github.event_name == 'push') }}
177
+ uses : port-labs/port-github-action@v1
178
+ with :
179
+ clientId : ${{ secrets.PORT_MAIN_CLIENT_ID }}
180
+ clientSecret : ${{ secrets.PORT_MAIN_CLIENT_SECRET }}
181
+ baseUrl : https://api.getport.io
182
+ operation : UPSERT
183
+ identifier : ocean
184
+ blueprint : repository
185
+ properties : |-
186
+ {
187
+ "coverage_percent": "${{ steps.set-stmts-coverage.outputs.STMTS_COVERAGE }}"
188
+ }
81
189
82
190
- name : Publish Test Report
83
191
uses : mikepenz/action-junit-report@v5
0 commit comments