|
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 |
6 | 2 |
|
7 | 3 | on: |
8 | 4 | pull_request: |
9 | 5 |
|
10 | 6 | jobs: |
11 | | - |
12 | 7 | run-smoke-tests: |
13 | 8 | runs-on: ubuntu-latest |
14 | 9 | 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 |
19 | 14 |
|
20 | 15 | - name: Cache Composer packages |
21 | 16 | id: composer-cache |
22 | 17 | uses: actions/cache@v4 |
23 | 18 | with: |
24 | | - path: vendor |
| 19 | + path: src/vendor |
25 | 20 | key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} |
26 | 21 | restore-keys: | |
27 | 22 | ${{ runner.os }}-php- |
28 | 23 |
|
29 | 24 | - 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 |
31 | 27 |
|
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 . |
35 | 43 |
|
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 |
38 | 45 | 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 |
42 | 48 |
|
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 |
48 | 76 |
|
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 |
53 | 82 | fi |
54 | 83 |
|
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 | +
|
62 | 126 | - name: Ping statistics server with test results |
| 127 | + if: always() |
63 | 128 | run: | |
64 | 129 | curl https://raw.githubusercontent.com/hydephp/develop/6e9d17f31879f4ccda13a3fec4029c9663bccec0/monorepo/scripts/ping-openanalytics-testrunner.php -o ping.php |
65 | 130 | php ping.php "Monorepo Smoke Tests" ${{ secrets.OPENANALYTICS_TOKEN }} ${{ github.ref_name }} |
0 commit comments