Skip to content

Commit 75c05a6

Browse files
committed
ci: combine coverage
1 parent edf976b commit 75c05a6

5 files changed

Lines changed: 150 additions & 42 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Setup Python Environment
2+
description: Install pip, dependencies, and run foreach.sh install
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Install Python dependencies
7+
shell: bash
8+
run: |
9+
pip install -U pip
10+
export PIP_EXTRA_INDEX_URL="https://dl.espressif.com/pypi"
11+
pip install cryptography --prefer-binary
12+
pip install -r requirements.txt
13+
bash foreach.sh install
14+
15+
# Dynamically generate coverage arguments for all pytest-embedded directories
16+
COV_ARGS="--cov-report=term-missing"
17+
for pkg in pytest-embedded*/; do
18+
# Strip trailing slash and replace hyphens with underscores
19+
pkg_name=$(basename "$pkg" | sed 's/-/_/g')
20+
COV_ARGS="$COV_ARGS --cov=$pkg_name"
21+
done
22+
echo "PYTEST_COV_ARGS=$COV_ARGS" >> $GITHUB_ENV
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Upload Test Results
2+
description: Saves PR number and uploads test results
3+
inputs:
4+
name:
5+
description: "Name of the artifact"
6+
required: true
7+
runs:
8+
using: "composite"
9+
steps:
10+
- name: Save PR number
11+
if: github.event_name == 'pull_request'
12+
shell: bash
13+
run: echo ${{ github.event.pull_request.number }} > pr_number.txt
14+
- name: Upload test results
15+
uses: actions/upload-artifact@v6
16+
if: always()
17+
with:
18+
name: ${{ inputs.name }}
19+
include-hidden-files: true
20+
path: |
21+
pr_number.txt
22+
pytest-coverage-*.txt
23+
pytest-*.xml
24+
retention-days: 7

.github/workflows/report.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Report
2+
on:
3+
workflow_run:
4+
workflows:
5+
- Target Tests
6+
types:
7+
- completed
8+
9+
permissions:
10+
actions: read
11+
checks: write
12+
pull-requests: write
13+
14+
jobs:
15+
report:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Download test results
19+
uses: dawidd6/action-download-artifact@v16
20+
with:
21+
workflow: ${{ github.event.workflow_run.workflow_id }}
22+
run_id: ${{ github.event.workflow_run.id }}
23+
name_is_regexp: true
24+
name: "test-results-.*"
25+
path: test-results
26+
if_no_artifact_found: ignore
27+
28+
- name: Read PR number
29+
id: pr-number
30+
run: |
31+
PR_FILE=$(find test-results -name pr_number.txt | head -n 1)
32+
if [ -n "$PR_FILE" ] && [ -f "$PR_FILE" ]; then
33+
echo "PR_NUMBER=$(cat $PR_FILE)" >> $GITHUB_ENV
34+
else
35+
echo "No pr_number.txt found, skipping comment."
36+
exit 0
37+
fi
38+
39+
- name: Prepare multiple files string
40+
if: env.PR_NUMBER != ''
41+
id: generate-files
42+
run: |
43+
MULTIPLE_FILES=""
44+
for xml_file in $(find test-results -name "pytest-*.xml"); do
45+
dir_name=$(dirname "$xml_file")
46+
# title from directory name test-results-qemu -> qemu
47+
title=$(basename "$dir_name" | sed 's/^test-results-//')
48+
# Capitalize first letter and replace hyphens with spaces
49+
title=$(echo "$title" | awk '{print toupper(substr($0,1,1)) substr($0,2)}' | tr '-' ' ')
50+
51+
cov_file="$dir_name/pytest-coverage.txt"
52+
# Add to multiple files string
53+
MULTIPLE_FILES="${MULTIPLE_FILES}${title}, ${cov_file}, ${xml_file}"$'\n'
54+
done
55+
56+
echo "FILES<<EOF" >> $GITHUB_OUTPUT
57+
echo -e "$MULTIPLE_FILES" >> $GITHUB_OUTPUT
58+
echo "EOF" >> $GITHUB_OUTPUT
59+
60+
- name: Comment on PR
61+
uses: MishaKav/pytest-coverage-comment@v1
62+
if: env.PR_NUMBER != '' && steps.generate-files.outputs.FILES != ''
63+
with:
64+
issue-number: ${{ env.PR_NUMBER }}
65+
multiple-files: ${{ steps.generate-files.outputs.FILES }}

.github/workflows/test-python.yml

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,14 @@ jobs:
2323
timeout-minutes: 40
2424
runs-on: ubuntu-latest
2525
steps:
26-
- uses: actions/checkout@v4
27-
- uses: actions/setup-python@v5
26+
- uses: actions/checkout@v6
27+
- uses: actions/setup-python@v6
2828
with:
2929
python-version: "3.14"
30-
- name: Install dependencies
31-
run: |
32-
sudo apt update && sudo apt install -y libgcrypt20 libglib2.0-0 libpixman-1-0 libsdl2-2.0-0 libslirp0
33-
pip install -U pip
34-
export PIP_EXTRA_INDEX_URL="https://dl.espressif.com/pypi"
35-
pip install cryptography --prefer-binary
36-
pip install -r requirements.txt
37-
bash foreach.sh install
30+
- name: Install apt dependencies
31+
run: sudo apt update && sudo apt install -y libgcrypt20 libglib2.0-0 libpixman-1-0 libsdl2-2.0-0 libslirp0 zip
32+
- name: Setup Python environment
33+
uses: ./.github/actions/setup-python-env
3834
- name: Download and install QEMU
3935
run: |
4036
wget https://github.com/espressif/qemu/releases/download/esp-develop-9.2.2-20250817/qemu-xtensa-softmmu-esp_develop_9.2.2_20250817-x86_64-linux-gnu.tar.xz
@@ -43,7 +39,24 @@ jobs:
4339
tar -xf qemu-riscv32-softmmu-esp_develop_9.2.2_20250817-x86_64-linux-gnu.tar.xz
4440
echo "$PWD/qemu/bin" >> $GITHUB_PATH
4541
- name: Run QEMU tests
46-
run: pytest pytest-embedded-qemu/tests/test_qemu.py
42+
run: |
43+
pytest pytest-embedded-qemu/tests/test_qemu.py \
44+
--junitxml pytest-qemu.xml \
45+
$PYTEST_COV_ARGS | tee pytest-coverage-qemu.txt
46+
- name: Upload test results
47+
uses: ./.github/actions/upload-test-results
48+
if: always()
49+
with:
50+
name: test-results-qemu
51+
- name: Zip log files
52+
if: failure()
53+
run: |
54+
zip -r logs.zip /tmp/pytest-embedded
55+
- uses: actions/upload-artifact@v6
56+
if: failure()
57+
with:
58+
name: logs-qemu
59+
path: logs.zip
4760

4861
test-python:
4962
timeout-minutes: 40
@@ -64,36 +77,30 @@ jobs:
6477
options: --privileged
6578
steps:
6679
- uses: actions/checkout@v6
67-
- name: Install dependencies
68-
run: |
69-
apt update && apt install -y socat zip
70-
pip install -U pip
71-
export PIP_EXTRA_INDEX_URL="https://dl.espressif.com/pypi"
72-
pip install cryptography --prefer-binary
73-
pip install -r requirements.txt
74-
bash foreach.sh install
80+
- name: Install apt dependencies
81+
run: apt update && apt install -y socat zip
82+
- name: Setup Python environment
83+
uses: ./.github/actions/setup-python-env
7584
- name: Check ports
7685
run: ls -la /dev/ttyUSB*
7786
- name: Run Tests with coverage
87+
env:
88+
COVERAGE_FILE: ".coverage.${{ matrix.python-version }}-${{ matrix.arch }}"
7889
run: |
7990
pytest \
80-
--junitxml=pytest.xml \
81-
--cov-report=term-missing \
82-
--cov=pytest_embedded \
83-
--cov=pytest_embedded_arduino \
84-
--cov=pytest_embedded_idf \
85-
--cov=pytest_embedded_jtag \
86-
--cov=pytest_embedded_qemu \
87-
--cov=pytest_embedded_serial \
88-
--cov=pytest_embedded_serial_esp \
89-
--cov=pytest_embedded_wokwi \
90-
--cov=pytest_embedded_nuttx
91+
--junitxml=pytest-${{ matrix.python-version }}-${{ matrix.arch }}.xml \
92+
$PYTEST_COV_ARGS | tee pytest-coverage-${{ matrix.python-version }}-${{ matrix.arch }}.txt
93+
- name: Upload test results
94+
uses: ./.github/actions/upload-test-results
95+
if: always()
96+
with:
97+
name: test-results-${{ matrix.python-version }}-${{ matrix.arch }}
9198
- name: Zip log files
9299
if: failure()
93100
run: |
94101
zip -r logs.zip /tmp/pytest-embedded
95102
- uses: actions/upload-artifact@v6
96103
if: failure()
97104
with:
98-
name: logs-${{ matrix.python-version }}
105+
name: logs-${{ matrix.python-version }}-${{ matrix.arch }}
99106
path: logs.zip

foreach.sh

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,7 @@
22

33
set -euo pipefail
44

5-
DEFAULT_PACKAGES=" \
6-
pytest-embedded \
7-
pytest-embedded-serial \
8-
pytest-embedded-serial-esp \
9-
pytest-embedded-idf \
10-
pytest-embedded-jtag \
11-
pytest-embedded-qemu \
12-
pytest-embedded-arduino \
13-
pytest-embedded-wokwi \
14-
pytest-embedded-nuttx \
15-
"
5+
DEFAULT_PACKAGES=$(find . -maxdepth 1 -type d -name "pytest-embedded*" | sed 's|^\./||' | sort)
166

177
action=${1:-"install"}
188
res=0

0 commit comments

Comments
 (0)