Skip to content

Commit cd6b29a

Browse files
Copilotevilsocket
andcommitted
ci: add error handling to coverage report script and explicit permissions
Co-authored-by: evilsocket <86922+evilsocket@users.noreply.github.com> Agent-Logs-Url: https://github.com/evilsocket/cake/sessions/d2ed747a-0779-48ff-a765-f2c0b0c0ed73
1 parent dd61fa0 commit cd6b29a

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ jobs:
289289
runs-on: ubuntu-latest
290290
if: ${{ always() }}
291291
needs: [test, test-android, test-ios, test-features]
292+
permissions:
293+
contents: read
292294
steps:
293295
- name: Download coverage artifacts
294296
uses: actions/download-artifact@v4
@@ -299,9 +301,11 @@ jobs:
299301
- name: Generate coverage table
300302
run: |
301303
python3 << 'PYEOF'
302-
import json, os
304+
import json, os, sys
303305
304306
artifact_dir = 'coverage-artifacts'
307+
# NOTE: artifact names must match the upload step names in each test job.
308+
# If matrix.os values or artifact names change, update this map accordingly.
305309
name_map = {
306310
'coverage-ubuntu-latest-cpu': ('Linux', 'CPU'),
307311
'coverage-macos-latest-cpu': ('macOS', 'CPU'),
@@ -321,10 +325,16 @@ jobs:
321325
cov_file = os.path.join(artifact_dir, dirname, 'coverage.json')
322326
if not os.path.isfile(cov_file):
323327
continue
324-
with open(cov_file) as f:
325-
data = json.load(f)
326-
totals = data['data'][0]['totals']
327-
platform, accel = name_map.get(dirname, (dirname, '?'))
328+
try:
329+
with open(cov_file) as f:
330+
data = json.load(f)
331+
totals = data['data'][0]['totals']
332+
except (json.JSONDecodeError, KeyError, IndexError) as e:
333+
print(f"WARNING: skipping {dirname}: {e}", file=sys.stderr)
334+
continue
335+
if dirname not in name_map:
336+
print(f"WARNING: unmapped artifact '{dirname}', using raw name", file=sys.stderr)
337+
platform, accel = name_map.get(dirname, (dirname, 'Unknown'))
328338
rows.append((platform, accel, totals['lines'], totals['functions'], totals['regions']))
329339
330340
summary = os.environ.get('GITHUB_STEP_SUMMARY', '/dev/stdout')

0 commit comments

Comments
 (0)