Skip to content

Commit c2b39e3

Browse files
alexle0nteLuni-4
authored andcommitted
Update coverage report deployment in PR
1 parent a2e4b35 commit c2b39e3

File tree

1 file changed

+64
-29
lines changed

1 file changed

+64
-29
lines changed

.github/workflows/weighted-code-coverage.yml

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ env:
3333

3434
UDEPS_VERSION: "0.1.35"
3535

36-
CAREFUL_VERSION: "0.3.4"
36+
CAREFUL_VERSION: "0.4.3"
3737

3838

3939
jobs:
@@ -204,27 +204,87 @@ jobs:
204204
weighted-code-coverage --project-path ./ --grcov-format coveralls --grcov-path ./coveralls.json -m functions --json $HOME/wcc-output/wcc.json --html $HOME/wcc-output/
205205
206206
- name: Setup GitHub Pages
207+
if: github.event_name != 'pull_request'
207208
uses: actions/[email protected]
208209
with:
209210
enablement: true
210211

211-
- name: Upload Wcc html output
212+
- name: Upload Wcc HTML output
213+
if: github.event_name != 'pull_request'
212214
uses: actions/[email protected]
213215
with:
214216
path: ${{ steps.wcc-run.outputs.html }}
215217

216218
- name: Deploy to GitHub Pages
219+
if: github.event_name != 'pull_request'
217220
id: deployment
218221
uses: actions/[email protected]
219222

223+
- name: Set up Python
224+
if: github.event_name == 'pull_request'
225+
uses: actions/setup-python@v5
226+
with:
227+
python-version: '>=3.7'
228+
229+
- name: Install smokeshow
230+
if: github.event_name == 'pull_request'
231+
run: pip install smokeshow
232+
233+
- name: Deploy to smokeshow
234+
id: deploy_site
235+
if: github.event_name == 'pull_request'
236+
env:
237+
SMOKESHOW_AUTH_KEY: ${{ secrets.SMOKESHOW_AUTH_KEY }}
238+
run: |
239+
# Upload to Smokeshow and extract the URL of the generated site matching 'https://smokeshow.helpmanual.io/<random_string>' from the output
240+
url=$(smokeshow upload $HOME/wcc-output | grep -m 1 -o 'https://smokeshow.helpmanual.io/[^"]*')
241+
echo "url=$url" >> $GITHUB_OUTPUT
242+
shell: bash
243+
220244
- name: Extract metric values
245+
if: github.event_name == 'pull_request'
221246
id: metrics
222247
env:
223248
JSON: ${{ steps.wcc-run.outputs.json }}
224249
run: |
225250
content=`cat ${JSON}`
226251
echo "json=$content" >> $GITHUB_OUTPUT
227252
253+
# Search for an existing comment containing 'Weighted Code Coverage'; if found, it will later be updated with new metric values, otherwise a new comment will be created
254+
- name: Find comment
255+
if: github.event_name == 'pull_request'
256+
uses: peter-evans/find-comment@v3
257+
id: fc
258+
with:
259+
issue-number: ${{ github.event.pull_request.number }}
260+
comment-author: 'github-actions[bot]'
261+
body-includes: Weighted Code Coverage
262+
263+
- name: Create or update comment
264+
if: github.event_name == 'pull_request'
265+
uses: peter-evans/create-or-update-comment@v4
266+
env:
267+
COVERAGE: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.coverage }}
268+
WCC_CYC: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cyclomatic.wcc }}
269+
WCC_COG: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cognitive.wcc }}
270+
CRAP_CYC: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cyclomatic.crap }}
271+
CRAP_COG: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cognitive.crap }}
272+
SKUNK_CYC: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cyclomatic.skunk }}
273+
SKUNK_COG: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cognitive.skunk }}
274+
with:
275+
comment-id: ${{ steps.fc.outputs.comment-id }}
276+
issue-number: ${{ github.event.pull_request.number }}
277+
body: |
278+
## [Weighted Code Coverage](${{ steps.deploy_site.outputs.url }})
279+
Project metrics:
280+
- **Coverage**: ${{ env.COVERAGE }}%
281+
282+
| | Wcc | CRAP | Skunk |
283+
|-------------|----------------------|---------------------|----------------------|
284+
| Cyclomatic | ${{ env.WCC_CYC }}% | ${{ env.CRAP_CYC }} | ${{ env.SKUNK_CYC }} |
285+
| Cognitive | ${{ env.WCC_COG }}% | ${{ env.CRAP_COG }} | ${{ env.SKUNK_COG }} |
286+
edit-mode: replace
287+
228288
- name: Extract branch name
229289
id: extract-branch
230290
if: github.event_name != 'pull_request'
@@ -236,7 +296,7 @@ jobs:
236296
env:
237297
BADGE_PATH: .github/badges/wcc.svg
238298
run: echo "path=${BADGE_PATH}" >> "${GITHUB_OUTPUT}"
239-
299+
240300
- name: Create badge directory
241301
if: github.event_name != 'pull_request'
242302
env:
@@ -271,7 +331,7 @@ jobs:
271331
id: badge-changed
272332
with:
273333
files: ${{ steps.badge-path.outputs.path }}
274-
334+
275335
- name: Commit badge
276336
if: ${{ github.event_name != 'pull_request' && steps.badge-changed.outputs.files_changed == 'true' }}
277337
env:
@@ -289,31 +349,6 @@ jobs:
289349
github_token: ${{ secrets.GITHUB_TOKEN }}
290350
branch: ${{ steps.extract-branch.outputs.branch }}
291351

292-
- name: Create or update comment
293-
if: github.event_name == 'pull_request'
294-
uses: peter-evans/create-or-update-comment@v4
295-
env:
296-
COVERAGE: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.coverage }}
297-
WCC_CYC: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cyclomatic.wcc }}
298-
WCC_COG: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cognitive.wcc }}
299-
CRAP_CYC: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cyclomatic.crap }}
300-
CRAP_COG: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cognitive.crap }}
301-
SKUNK_CYC: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cyclomatic.skunk }}
302-
SKUNK_COG: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cognitive.skunk }}
303-
with:
304-
comment-id: ${{ github.event.comment.id }}
305-
issue-number: ${{ github.event.pull_request.number }}
306-
body: |
307-
## Weighted Code Coverage
308-
Project metrics:
309-
- **Coverage**: ${{ env.COVERAGE }}%
310-
311-
| | Wcc | CRAP | Skunk |
312-
|-------------|----------------------|---------------------|----------------------|
313-
| Cyclomatic | ${{ env.WCC_CYC }}% | ${{ env.CRAP_CYC }} | ${{ env.SKUNK_CYC }} |
314-
| Cognitive | ${{ env.WCC_COG }}% | ${{ env.CRAP_COG }} | ${{ env.SKUNK_COG }} |
315-
edit-mode: replace
316-
317352
################################## DEPENDENCY LAYER ###########################
318353

319354
audit:

0 commit comments

Comments
 (0)