Used service not being closed makes the pipeline fail

Hi folks,

Currently working on tests in PHP with MySQL database.

All is working fine but Github Actions service is not closing and makes the pipeline fail.

name: Test PHP
on: [push]
jobs:
  test:
    runs-on: ubuntu-latest
    services:
      mysql:
        image: mysql:5.7
        env:
          MYSQL_ALLOW_EMPTY_PASSWORD: yes
          MYSQL_DATABASE: default
        ports:
          - 3306:3306
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
    strategy:
      fail-fast: false
      matrix:
        version: ['7.2', '7.3', '7.4']
    steps:
      - uses: actions/checkout@v2

      - uses: shivammathur/setup-php@v2
        with:
          php-version: ${{ matrix.version }}

      - name: Setup Wordpress CLI
        run: |
          curl -sSO https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
          chmod +x wp-cli.phar
          sudo mv wp-cli.phar /usr/local/bin/wp

      - name: Execute tests
        env:
          DATABASE_NAME: default
          DATABASE_MYSQL_USERNAME: root
          VERSION: '5.4.1'
        run: |
          chmod +x test.sh
          ./test.sh

Am I doing something wrong in this configuration? Or does this depend on the platform?

Content of my test.sh file:

#!/bin/bash

# Initialize exit code
exit_code=0

cd ../
mv Product-WP/ product/
zip "product.zip" -r "product" -q

# Download, install, test, clean function
function testWP {
	wp core download --version=$VERSION
	wp core config --dbname=$DATABASE_NAME --dbuser=$DATABASE_MYSQL_USERNAME --dbpass=$DATABASE_MYSQL_PASSWORD --dbhost=127.0.0.1
	wp core install --url=127.0.0.1:8888 --title=Example --admin_user=supervisor --admin_password=strongpassword --admin_email=info@example.com --skip-email

	# Install plugin
	printf "\n\e[4mInstalling our plugin...\e[0m\n"
	install_output=$(wp plugin install product.zip --activate)
	num_errors=$(echo "$install_output" | grep -c "Error")
	if [[$num_errors == 0]]; then
		printf "\e[32mSuccess:\e[0m Plugin installed.\n"
	else
		echo "$install_output"
		printf "\e[31mError:\e[0m Plugin not installed.\n"
		exit_code=1
	fi

	# Test sync and pages
	printf "\n\e[4mTesting sync...\e[0m\n"
	sync_output=$(php ./wp-content/plugins/product/api/sync.php)
	num_categories=$(echo "$sync_output" | grep -c "Inserted category")
	num_courses=$(echo "$sync_output" | grep -c "Inserted course")
	if [[$num_categories > 0 && $num_courses > 0]]; then
		printf "\e[32mSuccess:\e[0m Synced %d categories and %d courses.\n" $num_categories $num_courses
	else
		echo "$sync_output"
		printf "\e[31mError:\e[0m Synced %d categories and %d courses.\n" $num_categories $num_courses
		exit_code=1
	fi

	# Start PHP server
	php -S 0.0.0.0:8888 &>/dev/null &
	sleep 1

	# Test several pages
	printf "\n\e[4mTesting pages...\e[0m\n"
	overview_output=$(curl -sS "http://127.0.0.1:8888/?post_type=product_course")
	test_title=$(echo "$overview_output" | grep -c "Example")
	if [[$test_title > 0]]; then
		printf "\e[32mSuccess:\e[0m Overview page is working.\n"
	else
		echo "$overview_output"
		printf "\e[31mError:\e[0m WordPress doesn't work.\n"
		exit_code=1
	fi
	category_output=$(curl -sS "http://127.0.0.1:8888/?product_category=opleidingen-management")
	test_block=$(echo "$category_output" | grep -c "block-course")
	if [[$test_block > 0]]; then
		printf "\e[32mSuccess:\e[0m Category page is working.\n"
	else
		echo "$category_output"
		printf "\e[31mError:\e[0m Category page doesn't work.\n"
		exit_code=1
	fi
	course_output=$(curl -sS "http://127.0.0.1:8888/?product_course=management-en-organisatie")
	test_header=$(echo "$course_output" | grep -c "blur-header")
	if [[$test_header > 0]]; then
		printf "\e[32mSuccess:\e[0m Course page is working.\n"
	else
		echo "$course_output"
		printf "\e[31mError:\e[0m Course page doesn't work.\n"
		exit_code=1
	fi
}

testWP

exit $exit_code

that looks right to me – what’s the contents of test.sh?

or… if you cannot divulge that – are you doing anything in that test that is changing the state of docker or your repo dir?

I’m just doing some basic bash stuff

#!/bin/bash

# Initialize exit code
exit_code=0

cd ../
mv Product-WP/ product/
zip "product.zip" -r "product" -q

# Download, install, test, clean function
function testWP {
	wp core download --version=$VERSION
	wp core config --dbname=$DATABASE_NAME --dbuser=$DATABASE_MYSQL_USERNAME --dbpass=$DATABASE_MYSQL_PASSWORD --dbhost=127.0.0.1
	wp core install --url=127.0.0.1:8888 --title=Example --admin_user=supervisor --admin_password=strongpassword --admin_email=info@example.com --skip-email

	# Install plugin
	printf "\n\e[4mInstalling our plugin...\e[0m\n"
	install_output=$(wp plugin install product.zip --activate)
	num_errors=$(echo "$install_output" | grep -c "Error")
	if [[$num_errors == 0]]; then
		printf "\e[32mSuccess:\e[0m Plugin installed.\n"
	else
		echo "$install_output"
		printf "\e[31mError:\e[0m Plugin not installed.\n"
		exit_code=1
	fi

	# Test sync and pages
	printf "\n\e[4mTesting sync...\e[0m\n"
	sync_output=$(php ./wp-content/plugins/product/api/sync.php)
	num_categories=$(echo "$sync_output" | grep -c "Inserted category")
	num_courses=$(echo "$sync_output" | grep -c "Inserted course")
	if [[$num_categories > 0 && $num_courses > 0]]; then
		printf "\e[32mSuccess:\e[0m Synced %d categories and %d courses.\n" $num_categories $num_courses
	else
		echo "$sync_output"
		printf "\e[31mError:\e[0m Synced %d categories and %d courses.\n" $num_categories $num_courses
		exit_code=1
	fi

	# Start PHP server
	php -S 0.0.0.0:8888 &>/dev/null &
	sleep 1

	# Test several pages
	printf "\n\e[4mTesting pages...\e[0m\n"
	overview_output=$(curl -sS "http://127.0.0.1:8888/?post_type=product_course")
	test_title=$(echo "$overview_output" | grep -c "Example")
	if [[$test_title > 0]]; then
		printf "\e[32mSuccess:\e[0m Overview page is working.\n"
	else
		echo "$overview_output"
		printf "\e[31mError:\e[0m WordPress doesn't work.\n"
		exit_code=1
	fi
	category_output=$(curl -sS "http://127.0.0.1:8888/?product_category=opleidingen-management")
	test_block=$(echo "$category_output" | grep -c "block-course")
	if [[$test_block > 0]]; then
		printf "\e[32mSuccess:\e[0m Category page is working.\n"
	else
		echo "$category_output"
		printf "\e[31mError:\e[0m Category page doesn't work.\n"
		exit_code=1
	fi
	course_output=$(curl -sS "http://127.0.0.1:8888/?product_course=management-en-organisatie")
	test_header=$(echo "$course_output" | grep -c "blur-header")
	if [[$test_header > 0]]; then
		printf "\e[32mSuccess:\e[0m Course page is working.\n"
	else
		echo "$course_output"
		printf "\e[31mError:\e[0m Course page doesn't work.\n"
		exit_code=1
	fi
}

testWP

exit $exit_code

Just some basic bash stuff!

#!/bin/bash

# Initialize exit code
exit_code=0

cd ../
mv Product-WP/ product/
zip "product.zip" -r "product" -q

# Download, install, test, clean function
function testWP {
	wp core download --version=$VERSION
	wp core config --dbname=$DATABASE_NAME --dbuser=$DATABASE_MYSQL_USERNAME --dbpass=$DATABASE_MYSQL_PASSWORD --dbhost=127.0.0.1
	wp core install --url=127.0.0.1:8888 --title=Example --admin_user=supervisor --admin_password=strongpassword --admin_email=info@example.com --skip-email

	# Install plugin
	printf "\n\e[4mInstalling our plugin...\e[0m\n"
	install_output=$(wp plugin install product.zip --activate)
	num_errors=$(echo "$install_output" | grep -c "Error")
	if [[$num_errors == 0]]; then
		printf "\e[32mSuccess:\e[0m Plugin installed.\n"
	else
		echo "$install_output"
		printf "\e[31mError:\e[0m Plugin not installed.\n"
		exit_code=1
	fi

	# Test sync and pages
	printf "\n\e[4mTesting sync...\e[0m\n"
	sync_output=$(php ./wp-content/plugins/product/api/sync.php)
	num_categories=$(echo "$sync_output" | grep -c "Inserted category")
	num_courses=$(echo "$sync_output" | grep -c "Inserted course")
	if [[$num_categories > 0 && $num_courses > 0]]; then
		printf "\e[32mSuccess:\e[0m Synced %d categories and %d courses.\n" $num_categories $num_courses
	else
		echo "$sync_output"
		printf "\e[31mError:\e[0m Synced %d categories and %d courses.\n" $num_categories $num_courses
		exit_code=1
	fi

	# Start PHP server
	php -S 0.0.0.0:8888 &>/dev/null &
	sleep 1

	# Test several pages
	printf "\n\e[4mTesting pages...\e[0m\n"
	overview_output=$(curl -sS "http://127.0.0.1:8888/?post_type=product_course")
	test_title=$(echo "$overview_output" | grep -c "Example")
	if [[$test_title > 0]]; then
		printf "\e[32mSuccess:\e[0m Overview page is working.\n"
	else
		echo "$overview_output"
		printf "\e[31mError:\e[0m WordPress doesn't work.\n"
		exit_code=1
	fi
	category_output=$(curl -sS "http://127.0.0.1:8888/?product_category=opleidingen-management")
	test_block=$(echo "$category_output" | grep -c "block-course")
	if [[$test_block > 0]]; then
		printf "\e[32mSuccess:\e[0m Category page is working.\n"
	else
		echo "$category_output"
		printf "\e[31mError:\e[0m Category page doesn't work.\n"
		exit_code=1
	fi
	course_output=$(curl -sS "http://127.0.0.1:8888/?product_course=management-en-organisatie")
	test_header=$(echo "$course_output" | grep -c "blur-header")
	if [[$test_header > 0]]; then
		printf "\e[32mSuccess:\e[0m Course page is working.\n"
	else
		echo "$course_output"
		printf "\e[31mError:\e[0m Course page doesn't work.\n"
		exit_code=1
	fi
}

testWP

exit $exit_code

@gieforce ,

I also tested the demo you shared. According to my test, the problem is most likely caused by the scripts in the test.sh file (like as @everops-alex mentioned).

If possible, please share your repository with us, so that we can check more detailed configurations in your repository to analyze the root cause.

Hi @brightran

It’s a private repo! How can I share this with you?

@gieforce ,

Maybe, you can share a demo that can reproduce the same problem in your public repository.