Skip to content

Commit c6d0ca0

Browse files
authored
Merge pull request #1928 from hydephp/parallel-coverage-testing
Internal: Parallel smoke testing
2 parents 5d6ae26 + a180d59 commit c6d0ca0

File tree

2 files changed

+105
-38
lines changed

2 files changed

+105
-38
lines changed

.github/workflows/coverage-tests.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
pull_request:
55

66
jobs:
7-
87
test-coverage:
98
runs-on: ubuntu-latest
109
steps:
@@ -15,6 +14,9 @@ jobs:
1514
extensions: fileinfo
1615
- uses: actions/checkout@v4
1716

17+
- name: Validate composer.json and composer.lock
18+
run: composer validate --strict --no-check-all
19+
1820
- name: Cache Composer packages
1921
id: composer-cache
2022
uses: actions/cache@v4
@@ -41,4 +43,4 @@ jobs:
4143
- name: Ping statistics server with test results
4244
run: |
4345
curl https://raw.githubusercontent.com/hydephp/develop/6e9d17f31879f4ccda13a3fec4029c9663bccec0/monorepo/scripts/ping-openanalytics-testrunner.php -o ping.php
44-
php ping.php "Monorepo Coverage Tests" ${{ secrets.OPENANALYTICS_TOKEN }} ${{ github.ref_name }}
46+
php ping.php "Monorepo Coverage Tests" ${{ secrets.OPENANALYTICS_TOKEN }} ${{ github.ref_name }}

.github/workflows/smoke-tests.yml

Lines changed: 101 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,130 @@
1-
# This workflow is especially helpful for pull requests to quickly see if the other tests will definitely fail.
2-
# In order to get even quicker feedback, we also ping our Continuous Integration server to get a status check
3-
# as soon as we know the outcome, as the GitHub Actions Pull Request UI takes a little bit to update.
4-
5-
name: 🔥 Smoke Tests
1+
name: 🔥 Parallel Smoke Tests
62

73
on:
84
pull_request:
95

106
jobs:
11-
127
run-smoke-tests:
138
runs-on: ubuntu-latest
149
steps:
15-
- uses: actions/checkout@v4
16-
17-
- name: Validate composer.json and composer.lock
18-
run: composer validate --strict --no-check-all
10+
- name: Checkout code
11+
uses: actions/checkout@v4
12+
with:
13+
path: src
1914

2015
- name: Cache Composer packages
2116
id: composer-cache
2217
uses: actions/cache@v4
2318
with:
24-
path: vendor
19+
path: src/vendor
2520
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
2621
restore-keys: |
2722
${{ runner.os }}-php-
2823
2924
- name: Install Composer Dependencies
30-
run: composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
25+
run: |
26+
cd src && composer install --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
3127
32-
- name: Run smoke tests
33-
id: smoke-tests
34-
run: vendor/bin/pest --stop-on-failure --log-junit report.xml
28+
- name: Prepare test directories
29+
run: |
30+
setup_directory() {
31+
local suite=$1
32+
mkdir -p "${suite}_tests"
33+
cp -al src/. "${suite}_tests/"
34+
}
35+
36+
# Create hard links for all suites
37+
for suite in unit feature_hyde feature_framework publications realtime_compiler; do
38+
setup_directory $suite
39+
done
40+
41+
# Move the .git directory out of src
42+
mv src/.git .
3543
36-
- name: Ping continuous integration server with test status
37-
if: always() && github.event.repository.full_name == 'hydephp/develop'
44+
- name: Execute Tests in Parallel
3845
run: |
39-
bearerToken="${{ secrets.CI_SERVER_TOKEN }}"
40-
commit="${{ github.event.pull_request.head.sha }}"
41-
url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
46+
mkdir -p test_results
47+
mkdir -p test_outputs
4248
43-
# If bearerToken is not set, we we exit early as we are probably running on a fork
44-
if [ -z "$bearerToken" ]; then
45-
echo "Exiting early as bearerToken is not set"
46-
exit 0
47-
fi
49+
# Function to run tests
50+
run_tests() {
51+
local suite=$1
52+
local testsuite=$2
53+
echo "${suite^} tests started"
54+
cd ${suite}_tests
55+
if vendor/bin/pest --colors=always --log-junit="../test_results/${suite}_junit.xml" --testsuite="$testsuite" > "../test_outputs/${suite}.log" 2>&1; then
56+
echo "${suite^} tests completed successfully"
57+
else
58+
echo "${suite^} tests failed"
59+
return 1
60+
fi
61+
}
62+
63+
# Run tests in parallel and capture exit codes
64+
run_tests unit UnitFramework & pid1=$!
65+
run_tests feature_hyde FeatureHyde & pid2=$!
66+
run_tests feature_framework FeatureFramework & pid3=$!
67+
run_tests publications Publications & pid4=$!
68+
run_tests realtime_compiler "Realtime Compiler" & pid5=$!
69+
70+
# Wait for all background jobs to finish and capture exit codes
71+
wait $pid1 || echo "Unit tests failed" >> test_failures
72+
wait $pid2 || echo "Feature Hyde tests failed" >> test_failures
73+
wait $pid3 || echo "Feature Framework tests failed" >> test_failures
74+
wait $pid4 || echo "Publications tests failed" >> test_failures
75+
wait $pid5 || echo "Realtime Compiler tests failed" >> test_failures
4876
49-
if [ ${{ steps.smoke-tests.outcome }} == "failure" ]; then
50-
status=false
51-
else
52-
status=true
77+
# Check if any tests failed
78+
if [ -f test_failures ]; then
79+
echo "The following test suites failed:"
80+
cat test_failures
81+
exit 1
5382
fi
5483
55-
curl -X POST --fail-with-body \
56-
-H "Authorization: Bearer $bearerToken" \
57-
-H "Content-Type: application/json" \
58-
-H "Accept: application/json" \
59-
-d '{"commit":"'"$commit"'", "status":'$status', "url":"'"$url"'"}' \
60-
https://ci.hydephp.com/api/test-run-reports
61-
84+
- name: Display Unit Tests Output
85+
if: always()
86+
run: cat test_outputs/unit.log
87+
88+
- name: Display Feature Hyde Tests Output
89+
if: always()
90+
run: cat test_outputs/feature_hyde.log
91+
92+
- name: Display Feature Framework Tests Output
93+
if: always()
94+
run: cat test_outputs/feature_framework.log
95+
96+
- name: Display Publications Tests Output
97+
if: always()
98+
run: cat test_outputs/publications.log
99+
100+
- name: Display Realtime Compiler Tests Output
101+
if: always()
102+
run: cat test_outputs/realtime_compiler.log
103+
104+
- name: Merge JUnit XML Reports
105+
if: always()
106+
run: |
107+
php -r '
108+
$files = glob("test_results/*_junit.xml");
109+
$totalTests = $totalAssertions = $totalTime = 0;
110+
foreach ($files as $file) {
111+
$xml = simplexml_load_file($file);
112+
$totalTests += (int)$xml->testsuite["tests"];
113+
$totalAssertions += (int)$xml->testsuite["assertions"];
114+
$totalTime += (float)$xml->testsuite["time"];
115+
}
116+
$output = sprintf(
117+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<testsuites>\n <testsuite name=\"%s\" tests=\"%d\" assertions=\"%d\" errors=\"0\" failures=\"0\" skipped=\"0\" time=\"%.6f\">\n </testsuite>\n</testsuites>",
118+
"H:\\monorepo\\phpunit.xml.dist",
119+
$totalTests,
120+
$totalAssertions,
121+
$totalTime
122+
);
123+
file_put_contents("report.xml", $output);
124+
'
125+
62126
- name: Ping statistics server with test results
127+
if: always()
63128
run: |
64129
curl https://raw.githubusercontent.com/hydephp/develop/6e9d17f31879f4ccda13a3fec4029c9663bccec0/monorepo/scripts/ping-openanalytics-testrunner.php -o ping.php
65130
php ping.php "Monorepo Smoke Tests" ${{ secrets.OPENANALYTICS_TOKEN }} ${{ github.ref_name }}

0 commit comments

Comments
 (0)