Skip to content

Commit 6000836

Browse files
Update tests.yml
ci: improve GitHub Actions workflow reliability - Add timeouts for all steps - Add Composer dependency caching - Fix RabbitMQ startup issues - Improve error logging and debugging - Add cleanup step - Set specific Composer version - Disable fail-fast strategy Environment: - Date: 2025-04-04 19:00:37 UTC - Runner: ubuntu-24.04 - Composer: 2.8.6 - Git: 2.49.0 Test by: @miladshakerdn
1 parent 4e0343d commit 6000836

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

.github/workflows/tests.yml

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ on:
99
jobs:
1010
tests:
1111
runs-on: ubuntu-24.04
12+
timeout-minutes: 20
1213

1314
strategy:
14-
fail-fast: true
15+
fail-fast: false
1516
matrix:
1617
php: ['8.2', '8.3']
1718
stability: ['prefer-lowest', 'prefer-stable']
@@ -31,48 +32,80 @@ jobs:
3132
php-version: ${{ matrix.php }}
3233
extensions: dom, curl, libxml, mbstring, zip, json
3334
coverage: none
35+
tools: composer:v2.8.6
36+
37+
- name: Get Composer Cache Directory
38+
id: composer-cache
39+
run: |
40+
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
41+
42+
- name: Cache Composer dependencies
43+
uses: actions/cache@v4
44+
with:
45+
path: ${{ steps.composer-cache.outputs.dir }}
46+
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.stability }}-${{ hashFiles('**/composer.json') }}
47+
restore-keys: |
48+
${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.stability }}-
49+
${{ runner.os }}-composer-${{ matrix.php }}-
50+
${{ runner.os }}-composer-
3451
3552
- name: Set up Docker
53+
timeout-minutes: 5
3654
run: |
3755
docker-compose up -d rabbitmq
3856
3957
- name: Install dependencies
58+
timeout-minutes: 5
4059
run: |
4160
composer update --with='laravel/framework:${{matrix.laravel}}' --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress
4261
4362
- name: Run Laravel Pint
63+
timeout-minutes: 2
4464
run: ./vendor/bin/pint --test
4565

4666
- name: Wait for RabbitMQ
67+
timeout-minutes: 2
4768
run: |
48-
timeout=30
49-
until docker exec $(docker ps -qf "name=rabbitmq") rabbitmqctl status >/dev/null 2>&1 || [ $timeout -eq 0 ]; do
50-
echo "Waiting for RabbitMQ to be ready... ($timeout seconds left)"
69+
echo "Waiting for RabbitMQ to be ready..."
70+
for i in {1..30}; do
71+
if docker exec $(docker ps -qf "name=rabbitmq") rabbitmqctl status >/dev/null 2>&1; then
72+
echo "RabbitMQ is ready!"
73+
exit 0
74+
fi
75+
echo "Attempt $i/30 - Waiting for RabbitMQ..."
5176
sleep 1
52-
((timeout--))
5377
done
54-
if [ $timeout -eq 0 ]; then
55-
echo "Timeout waiting for RabbitMQ"
56-
exit 1
57-
fi
58-
echo "RabbitMQ is ready!"
78+
echo "RabbitMQ failed to start"
79+
docker ps
80+
docker logs $(docker ps -qf "name=rabbitmq")
81+
exit 1
5982
6083
- name: Execute tests
61-
run: vendor/bin/phpunit
84+
timeout-minutes: 5
85+
run: vendor/bin/phpunit --verbose
6286
env:
6387
HOST: localhost
6488
PORT: 5672
6589
RABBITMQ_USER: guest
6690
RABBITMQ_PASSWORD: guest
6791
RABBITMQ_VHOST: /
92+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6893

6994
- name: Store test logs
7095
if: failure()
7196
uses: actions/upload-artifact@v4
97+
timeout-minutes: 1
7298
with:
73-
name: test-logs-php${{ matrix.php }}-laravel${{ matrix.laravel }}-${{ github.sha }}
99+
name: test-logs-${{ matrix.php }}-${{ matrix.stability }}-${{ github.sha }}
74100
path: |
75101
./storage/logs
76102
./phpunit.xml
77103
./.env.testing
104+
./docker-compose.logs
78105
retention-days: 5
106+
107+
- name: Cleanup
108+
if: always()
109+
run: |
110+
docker-compose down -v
111+
docker system prune -f

0 commit comments

Comments
 (0)