Skip to content

Commit a4d9a8c

Browse files
chore: speed up pr-check-test workflow runtime (hiero-ledger#1895)
Signed-off-by: Aditya Giri <74224708+adityagiri3600@users.noreply.github.com>
1 parent 03160c8 commit a4d9a8c

2 files changed

Lines changed: 117 additions & 70 deletions

File tree

.github/workflows/pr-check-test.yml

Lines changed: 116 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,32 @@ name: Hiero Solo Integration & Unit Tests
33
on:
44
push:
55
branches:
6-
- "**"
6+
- "main"
7+
paths-ignore:
8+
- "**/*.md"
9+
- "docs/**"
10+
- "examples/**"
11+
- "tck/**"
12+
- ".github/**"
13+
- "!.github/workflows/pr-check-test.yml"
714
pull_request:
8-
workflow_dispatch:
15+
paths-ignore:
16+
- "**/*.md"
17+
- "docs/**"
18+
- "examples/**"
19+
- "tck/**"
20+
- ".github/**"
21+
- "!.github/workflows/pr-check-test.yml"
22+
workflow_dispatch: {}
923

1024
permissions:
1125
contents: read
1226

1327
jobs:
14-
build-and-test:
28+
unit-tests:
29+
name: Unit Tests (Python ${{ matrix.python-version }})
1530
runs-on: ubuntu-latest
16-
timeout-minutes: 30
17-
31+
timeout-minutes: 10
1832
strategy:
1933
fail-fast: false
2034
matrix:
@@ -27,40 +41,94 @@ jobs:
2741
egress-policy: audit
2842

2943
- name: Checkout repository
30-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
44+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3145

3246
- name: Set up Python ${{ matrix.python-version }}
3347
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
3448
with:
3549
python-version: ${{ matrix.python-version }}
36-
cache: "pip"
3750

3851
- name: Install uv
3952
uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1
53+
with:
54+
enable-cache: true
55+
56+
- name: Install dependencies
57+
run: uv sync --all-extras --dev
58+
59+
- name: Generate Proto Files
60+
run: uv run generate_proto.py
61+
62+
- name: Run unit tests
63+
id: unit
64+
continue-on-error: true
65+
shell: bash
66+
run: |
67+
set -o pipefail
68+
echo "🚀 Running unit tests..."
69+
set +e
70+
uv run pytest tests/unit -v --disable-warnings --continue-on-collection-errors 2>&1 | tee result_unit.log
71+
pytest_exit=${PIPESTATUS[0]}
72+
set -e
73+
echo "exit_code=$pytest_exit" >> "$GITHUB_OUTPUT"
74+
if [ $pytest_exit -ne 0 ]; then
75+
echo "❌ Some unit tests failed"
76+
grep -E 'FAILED |ERROR ' result_unit.log || true
77+
else
78+
echo "✅ All unit tests passed"
79+
fi
80+
81+
- name: Fail job if unit tests failed
82+
if: steps.unit.outputs.exit_code != '0'
83+
shell: bash
84+
run: |
85+
echo "❌ Unit tests failed. See logs above."
86+
exit 1
87+
88+
integration-tests:
89+
name: Integration Tests (Python ${{ matrix.python-version }})
90+
runs-on: ubuntu-latest
91+
timeout-minutes: 20
92+
needs:
93+
- unit-tests
94+
if: needs.unit-tests.result == 'success'
95+
strategy:
96+
fail-fast: false
97+
matrix:
98+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
99+
100+
steps:
101+
- name: Harden the runner (Audit all outbound calls)
102+
uses: step-security/harden-runner@58077d3c7e43986b6b15fba718e8ea69e387dfcc # v2.15.1
103+
with:
104+
egress-policy: audit
105+
106+
- name: Checkout repository
107+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
108+
109+
- name: Set up Python ${{ matrix.python-version }}
110+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
111+
with:
112+
python-version: ${{ matrix.python-version }}
40113

41-
- name: Install setuptools wheel
42-
run: pip install --upgrade pip setuptools wheel
114+
- name: Install uv
115+
uses: astral-sh/setup-uv@5a095e7a2014a4212f075830d4f7277575a9d098 # v7.3.1
116+
with:
117+
enable-cache: true
43118

44119
- name: Install dependencies
45120
run: uv sync --all-extras --dev
46121

47122
- name: Generate Proto Files
48-
run: uv run python generate_proto.py
123+
run: uv run generate_proto.py
49124

50125
- name: Prepare Hiero Solo
51126
id: solo
52127
uses: hiero-ledger/hiero-solo-action@4d42a74e8e644a2753f3bb7a2afa429305375b14 # v0.15.0
53128
with:
54129
installMirrorNode: true
55130

56-
- name: Install your package
57-
run: pip install -e .
58-
59-
##############################################
60-
# INTEGRATION TESTS
61-
##############################################
62-
63-
- name: Run all integration tests
131+
- name: Run integration tests
64132
id: integration
65133
continue-on-error: true
66134
shell: bash
@@ -73,86 +141,64 @@ jobs:
73141
run: |
74142
set -o pipefail
75143
echo "🚀 Running integration tests..."
76-
uv run pytest tests/integration -v --disable-warnings --continue-on-collection-errors 2>&1 | tee result_integration.log
144+
set +e
145+
uv run --with pytest-xdist pytest -n 2 --dist=loadfile tests/integration -v --disable-warnings --continue-on-collection-errors 2>&1 | tee result_integration.log
77146
pytest_exit=${PIPESTATUS[0]}
78-
echo "integration_failed=$pytest_exit" >> $GITHUB_OUTPUT
79-
cat result_integration.log
147+
set -e
148+
echo "exit_code=$pytest_exit" >> "$GITHUB_OUTPUT"
80149
if [ $pytest_exit -ne 0 ]; then
81150
echo "❌ Some integration tests failed"
82-
echo "Failed tests:"
83-
grep -E 'FAILED ' result_integration.log || true
151+
grep -E 'FAILED |ERROR ' result_integration.log || true
84152
else
85153
echo "✅ All integration tests passed"
86154
fi
87155
88-
##############################################
89-
# UNIT TESTS
90-
##############################################
91-
92-
- name: Run all unit tests
93-
id: unit
94-
continue-on-error: true
156+
- name: Fail job if integration tests failed
157+
if: steps.integration.outputs.exit_code != '0'
95158
shell: bash
96159
run: |
97-
set -o pipefail
98-
echo "🚀 Running unit tests..."
99-
uv run pytest tests/unit -v --disable-warnings --continue-on-collection-errors 2>&1 | tee result_unit.log
100-
pytest_exit=${PIPESTATUS[0]}
101-
echo "unit_failed=$pytest_exit" >> $GITHUB_OUTPUT
102-
cat result_unit.log
103-
if [ $pytest_exit -ne 0 ]; then
104-
echo "❌ Some unit tests failed"
105-
echo "Failed tests:"
106-
grep -E 'FAILED ' result_unit.log || true
107-
else
108-
echo "✅ All unit tests passed"
109-
fi
160+
echo "❌ Integration tests failed. See logs above."
161+
exit 1
110162
111-
##############################################
112-
# SUMMARY & FAIL CONDITIONS
113-
##############################################
163+
test-summary:
164+
name: Test Results Summary
165+
runs-on: ubuntu-latest
166+
needs:
167+
- unit-tests
168+
- integration-tests
169+
if: always()
114170

115-
- name: Fail workflow if any tests failed
171+
steps:
172+
- name: Print summary and fail when any test job failed
116173
shell: bash
117174
run: |
118-
integration_failed="${{ steps.integration.outputs.integration_failed }}"
119-
unit_failed="${{ steps.unit.outputs.unit_failed }}"
175+
unit_result="${{ needs.unit-tests.result }}"
176+
integration_result="${{ needs.integration-tests.result }}"
120177
121178
echo ""
122179
echo "==================== TEST SUMMARY ===================="
123180
124181
any_failed=false
125182
126-
if [ "$integration_failed" != "0" ]; then
127-
echo "❌ Integration tests FAILED"
128-
echo " → Check the integration test logs above for details."
129-
if [ -f result_integration.log ]; then
130-
grep -E 'FAILED ' result_integration.log || echo " (No FAILED lines found)"
131-
else
132-
echo " (Integration log not found)"
133-
fi
134-
any_failed=true
183+
if [ "$unit_result" = "success" ]; then
184+
echo "✅ Unit tests passed"
135185
else
136-
echo "✅ Integration tests passed"
137-
fi
138-
139-
if [ "$unit_failed" != "0" ]; then
140186
echo "❌ Unit tests FAILED"
141-
echo " → Check the unit test logs above for details."
142-
if [ -f result_unit.log ]; then
143-
grep -E 'FAILED ' result_unit.log || echo " (No FAILED lines found)"
144-
else
145-
echo " (Unit log not found)"
146-
fi
147187
any_failed=true
188+
fi
189+
190+
if [ "$integration_result" = "success" ]; then
191+
echo "✅ Integration tests passed"
192+
elif [ "$integration_result" = "skipped" ] && [ "$unit_result" != "success" ]; then
193+
echo "⏭️ Integration tests skipped (unit tests failed first)"
148194
else
149-
echo "✅ Unit tests passed"
195+
echo "❌ Integration tests FAILED"
196+
any_failed=true
150197
fi
151198
152199
echo "======================================================"
153200
echo ""
154201
155-
# Final outcome
156202
if [ "$any_failed" = true ]; then
157203
echo "❌ Some tests failed. Failing workflow."
158204
exit 1

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
2727

2828

2929
### .github
30+
- changed `pr-check-test` to run unit matrix first, run integration matrix only after unit success, skip docs/examples/.github-only changes, and parallelize integration tests with xdist (`#1878`)
3031
- archived workflows relating to PR reminders
3132
- chore: switch workflow runner from ubuntu-latest to hl-sdk-py-lin-md for bot-assignment-check.yml workflow
3233
- chore: update concurrency group for GFI assignment workflow to prevent race conditions (`#1910`)

0 commit comments

Comments
 (0)