I want to use mysql in a composite action, but it fails with:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 2
It works fine when I run the steps directly in the workflow, but not when I want to have them defined in a composite action.
my workflow:
on:
push:
branches:
- master
jobs:
test-backend:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
ports:
- 3306:3306
env:
MYSQL_DATABASE: 'test'
MYSQL_ROOT_PASSWORD: 'root'
strategy:
matrix:
suite: [ 'unit', 'job', 'api' ]
shard: [ 1, 2, 3 ]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run ${{ matrix.suite }} tests with shard ${{ matrix.shard }}
uses: ./.github/actions/test-backend
with:
test-suite: ${{ matrix.suite }}
shard: ${{ matrix.shard }}
total-shards: 3
and this is the composite action:
inputs:
test-suite:
description: 'Test suite to run (e.g., unit, api, job, acceptance, functional)'
required: false
default: ''
type: string
shard:
description: 'Shard number to run'
required: false
default: 1
type: number
total-shards:
description: 'Total number of shards'
required: false
default: 1
type: number
runs:
using: 'composite'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mbstring, intl, pdo_mysql
coverage: none
- name: Setup testing env variables
working-directory: ./backend
shell: bash
run: |
cp ./.env.testing.example ./.env.testing
while IFS= read -r line || [ -n "$line" ]; do
echo "$line" >> $GITHUB_ENV
done < ./.env.testing
- name: Create databases
working-directory: ./backend
shell: bash
run: sh create_databases.sh
- name: Install Composer dependencies
working-directory: ./backend
shell: bash
run: composer install --no-progress --no-suggest --prefer-dist --ignore-platform-reqs
- name: Run migrations
working-directory: ./backend
shell: bash
run: sh run_migrations.sh --force
- name: Build Codeception helpers
working-directory: ./backend
shell: bash
run: vendor/bin/codecept build
- name: Run Codeception tests
working-directory: ./backend
shell: bash
run: vendor/bin/codecept run ${{ inputs.test-suite }} --shard ${{ inputs.shard }}/${{ inputs.total-shards }}