Skip to content

Commit 16b400d

Browse files
committed
feat(tests): update GitHub Actions workflow to parse merged JUnit results and improve directory structure
1 parent d558949 commit 16b400d

File tree

2 files changed

+38
-51
lines changed

2 files changed

+38
-51
lines changed

.github/workflows/pr-test.yml

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,36 +47,35 @@ jobs:
4747
")
4848
echo "COVERAGE_PERCENT=$percentage" >> "$GITHUB_OUTPUT"
4949
50-
- name: Parse JUnit Results for Summary
50+
- name: Parse Merged JUnit Results for Summary (only merged-results.xml)
5151
id: junit-summary
5252
run: |
5353
summary=$(poetry run python -c "
5454
import xml.etree.ElementTree as ET
55-
import glob
55+
56+
tree = ET.parse('test-results/merged-results.xml')
57+
root = tree.getroot()
58+
59+
# 'testsuites' 또는 'testsuite'에 따라 동작 다름 (방어코드)
60+
if root.tag == 'testsuites':
61+
suites = root.findall('testsuite')
62+
elif root.tag == 'testsuite':
63+
suites = [root]
64+
else:
65+
raise ValueError(f'Unexpected root tag: {root.tag}')
5666
5767
total_tests = 0
5868
total_failures = 0
5969
total_skipped = 0
6070
total_errors = 0
6171
total_time = 0.0
6272
63-
for file in glob.glob('test-results/*.xml'):
64-
tree = ET.parse(file)
65-
root = tree.getroot()
66-
67-
if root.tag == 'testsuites':
68-
suites = root.findall('testsuite')
69-
elif root.tag == 'testsuite':
70-
suites = [root]
71-
else:
72-
raise ValueError(f'Unexpected root tag: {root.tag}')
73-
74-
for suite in suites:
75-
total_tests += int(suite.attrib.get('tests', 0))
76-
total_failures += int(suite.attrib.get('failures', 0))
77-
total_skipped += int(suite.attrib.get('skipped', 0))
78-
total_errors += int(suite.attrib.get('errors', 0))
79-
total_time += float(suite.attrib.get('time', 0))
73+
for suite in suites:
74+
total_tests += int(suite.attrib.get('tests', 0))
75+
total_failures += int(suite.attrib.get('failures', 0))
76+
total_skipped += int(suite.attrib.get('skipped', 0))
77+
total_errors += int(suite.attrib.get('errors', 0))
78+
total_time += float(suite.attrib.get('time', 0))
8079
8180
passed = total_tests - total_failures - total_skipped
8281
print(f'PASSED={passed}')
@@ -87,10 +86,10 @@ jobs:
8786
8887
echo "$summary" >> "$GITHUB_OUTPUT"
8988
90-
- name: Publish Test Results Summary (optional)
89+
- name: Publish Merged Test Results Summary
9190
uses: test-summary/action@v2
9291
with:
93-
paths: "test-results/*.xml"
92+
paths: "test-results/merged-results.xml"
9493
if: always()
9594

9695
- name: Upload Coverage HTML Report
@@ -99,7 +98,7 @@ jobs:
9998
name: coverage-html
10099
path: htmlcov/
101100

102-
- name: Upload JUnit XML (for archive)
101+
- name: Upload All JUnit XML Files (for archive)
103102
uses: actions/upload-artifact@v4
104103
with:
105104
name: junit-xml-reports

Makefile

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
.PHONY: test test-all test-ch01 test-ch04 test-ch06 test-ch07 clean clean-coverage clean-results combine-coverage merge-junit
1+
.PHONY: test test-all clean clean-coverage clean-results combine-coverage merge-junit
22

33
CHAPTERS = ch01 ch04 ch06 ch07
44
TEST_RESULTS_DIR = test-results
5+
COVERAGE_DIR = $(TEST_RESULTS_DIR)/coverage
6+
JUNIT_DIR = $(TEST_RESULTS_DIR)/junit
57

68
# Poetry 환경 강제
79
POETRY ?= poetry run
@@ -18,43 +20,29 @@ clean-results:
1820

1921
clean-coverage:
2022
$(POETRY) coverage erase
21-
rm -f $(TEST_RESULTS_DIR)/.coverage*
23+
rm -f $(COVERAGE_DIR)/.coverage*
2224

23-
test-all: clean-results clean-coverage $(TEST_RESULTS_DIR) test-ch01 test-ch04 test-ch06 test-ch07 combine-coverage merge-junit
25+
test-all: clean-results clean-coverage $(TEST_RESULTS_DIR) run-all combine-coverage merge-junit
2426

25-
test-ch01:
26-
cd chapter01 && \
27-
COVERAGE_FILE=../$(TEST_RESULTS_DIR)/.coverage.ch01 $(POETRY) coverage run -m pytest -v \
28-
--junitxml=../$(TEST_RESULTS_DIR)/ch01-results.xml
29-
30-
test-ch04:
31-
cd chapter04 && \
32-
COVERAGE_FILE=../$(TEST_RESULTS_DIR)/.coverage.ch04 $(POETRY) coverage run -m pytest -v \
33-
--junitxml=../$(TEST_RESULTS_DIR)/ch04-results.xml
34-
35-
test-ch06:
36-
cd chapter06 && \
37-
COVERAGE_FILE=../$(TEST_RESULTS_DIR)/.coverage.ch06 $(POETRY) coverage run -m pytest -v \
38-
--junitxml=../$(TEST_RESULTS_DIR)/ch06-results.xml
39-
40-
test-ch07:
41-
cd chapter07 && \
42-
COVERAGE_FILE=../$(TEST_RESULTS_DIR)/.coverage.ch07 $(POETRY) coverage run -m pytest -v \
43-
--junitxml=../$(TEST_RESULTS_DIR)/ch07-results.xml
27+
run-all:
28+
@for chapter in $(CHAPTERS); do \
29+
echo "Running tests for $$chapter..."; \
30+
(cd $$chapter && \
31+
COVERAGE_FILE=../$(COVERAGE_DIR)/.coverage.$$chapter \
32+
$(POETRY) coverage run -m pytest -v \
33+
--junitxml=../$(JUNIT_DIR)/$$chapter-results.xml) || exit $$?; \
34+
done
4435

4536
combine-coverage:
46-
$(POETRY) coverage combine $(TEST_RESULTS_DIR)
37+
$(POETRY) coverage combine $(COVERAGE_DIR)
4738
$(POETRY) coverage report
4839
$(POETRY) coverage html
4940

5041
merge-junit:
5142
$(POETRY) python -m pip show junitparser > /dev/null || $(POETRY) python -m pip install junitparser
5243
$(POETRY) python -m junitparser merge \
53-
$(TEST_RESULTS_DIR)/ch01-results.xml \
54-
$(TEST_RESULTS_DIR)/ch04-results.xml \
55-
$(TEST_RESULTS_DIR)/ch06-results.xml \
56-
$(TEST_RESULTS_DIR)/ch07-results.xml \
57-
$(TEST_RESULTS_DIR)/merged-results.xml
44+
$(JUNIT_DIR)/*.xml \
45+
$(TEST_RESULTS_DIR)/merged-results.xml
5846

5947
$(TEST_RESULTS_DIR):
60-
mkdir -p $(TEST_RESULTS_DIR)
48+
mkdir -p $(COVERAGE_DIR) $(JUNIT_DIR)

0 commit comments

Comments
 (0)