Skip to content

Commit ceb6f6d

Browse files
committed
Update coverage report deployment in PR
1 parent a2e4b35 commit ceb6f6d

File tree

1 file changed

+69
-28
lines changed

1 file changed

+69
-28
lines changed

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

Lines changed: 69 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -204,27 +204,93 @@ 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: Generate upload key for smokeshow
234+
if: github.event_name == 'pull_request'
235+
id: generate_key
236+
run: |
237+
SMOKESHOW_AUTH_KEY=$(smokeshow generate-key | grep -o "SMOKESHOW_AUTH_KEY='[^']*'" | sed "s/^SMOKESHOW_AUTH_KEY='\([^']*\)'$/\1/")
238+
echo "SMOKESHOW_AUTH_KEY=$SMOKESHOW_AUTH_KEY" >> $GITHUB_ENV
239+
shell: bash
240+
241+
- name: Deploy to smokeshow
242+
id: deploy_site
243+
if: github.event_name == 'pull_request'
244+
env:
245+
SMOKESHOW_AUTH_KEY: ${{ env.SMOKESHOW_AUTH_KEY }}
246+
run: |
247+
url=$(smokeshow upload $HOME/wcc-output | grep -m 1 -o 'https://smokeshow.helpmanual.io/[^"]*')
248+
echo "url=$url" >> $GITHUB_OUTPUT
249+
shell: bash
250+
220251
- name: Extract metric values
252+
if: github.event_name == 'pull_request'
221253
id: metrics
222254
env:
223255
JSON: ${{ steps.wcc-run.outputs.json }}
224256
run: |
225257
content=`cat ${JSON}`
226258
echo "json=$content" >> $GITHUB_OUTPUT
227259
260+
- name: Find comment
261+
if: github.event_name == 'pull_request'
262+
uses: peter-evans/find-comment@v3
263+
id: fc
264+
with:
265+
issue-number: ${{ github.event.pull_request.number }}
266+
comment-author: 'github-actions[bot]'
267+
body-includes: Weighted Code Coverage
268+
269+
- name: Create or update comment
270+
if: github.event_name == 'pull_request'
271+
uses: peter-evans/create-or-update-comment@v4
272+
env:
273+
COVERAGE: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.coverage }}
274+
WCC_CYC: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cyclomatic.wcc }}
275+
WCC_COG: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cognitive.wcc }}
276+
CRAP_CYC: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cyclomatic.crap }}
277+
CRAP_COG: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cognitive.crap }}
278+
SKUNK_CYC: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cyclomatic.skunk }}
279+
SKUNK_COG: ${{ fromJson(steps.metrics.outputs.json).projectMetrics.total.cognitive.skunk }}
280+
with:
281+
comment-id: ${{ steps.fc.outputs.comment-id }}
282+
issue-number: ${{ github.event.pull_request.number }}
283+
body: |
284+
## [Weighted Code Coverage](${{ steps.deploy_site.outputs.url }})
285+
Project metrics:
286+
- **Coverage**: ${{ env.COVERAGE }}%
287+
288+
| | Wcc | CRAP | Skunk |
289+
|-------------|----------------------|---------------------|----------------------|
290+
| Cyclomatic | ${{ env.WCC_CYC }}% | ${{ env.CRAP_CYC }} | ${{ env.SKUNK_CYC }} |
291+
| Cognitive | ${{ env.WCC_COG }}% | ${{ env.CRAP_COG }} | ${{ env.SKUNK_COG }} |
292+
edit-mode: replace
293+
228294
- name: Extract branch name
229295
id: extract-branch
230296
if: github.event_name != 'pull_request'
@@ -236,7 +302,7 @@ jobs:
236302
env:
237303
BADGE_PATH: .github/badges/wcc.svg
238304
run: echo "path=${BADGE_PATH}" >> "${GITHUB_OUTPUT}"
239-
305+
240306
- name: Create badge directory
241307
if: github.event_name != 'pull_request'
242308
env:
@@ -271,7 +337,7 @@ jobs:
271337
id: badge-changed
272338
with:
273339
files: ${{ steps.badge-path.outputs.path }}
274-
340+
275341
- name: Commit badge
276342
if: ${{ github.event_name != 'pull_request' && steps.badge-changed.outputs.files_changed == 'true' }}
277343
env:
@@ -289,31 +355,6 @@ jobs:
289355
github_token: ${{ secrets.GITHUB_TOKEN }}
290356
branch: ${{ steps.extract-branch.outputs.branch }}
291357

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-
317358
################################## DEPENDENCY LAYER ###########################
318359

319360
audit:

0 commit comments

Comments
 (0)