Warm tip: This article is reproduced from stackoverflow.com, please click
codeception functional-testing github github-actions php

How to stop Github Actions step when functional tests failed (using Codeception)

发布于 2020-09-19 05:34:16

I'm new with Github Actions and I try to make some continuous integration with functional tests.

I use Codeception and my workflow run perfectly, but when some tests fail the step is written as success. Github don't stop the action and continue to run the nexts steps.

Here is my workflow yml file :

name: Run codeception tests

on:
  push:
    branches: [ feature/functional-tests/codeception ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:

    # —— Setup Github Actions ???? —————————————————————————————————————————————
    - name: Checkout
      uses: actions/checkout@v2

    # —— Setup PHP Version 7.3 ???? —————————————————————————————————————————————
    - name: Setup PHP environment
      uses: shivammathur/setup-php@master
      with:
        php-version: '7.3'

    # —— Setup Docker Environment ???? ————————————————————————————————————————————— 
    - name: Build containers
      run: docker-compose build

    - name: Start all container
      run: docker-compose up -d

    - name: Execute www container
      run: docker exec -t my_container developer

    - name: Create parameter file
      run: cp app/config/parameters.yml.dist app/config/parameters.yml

    # —— Composer ????‍️ —————————————————————————————————————————————————————————
    - name: Install dependancies
      run: composer install

    # —— Check Requirements ???? —————————————————————————————————————————————
    - name: Check PHP version
      run: php --version

    # —— Setup Database ???? —————————————————————————————————————————————
    - name: Create database
      run: docker exec -t mysql_container mysql -P 3306 --protocol=tcp -u root --password=**** -e "CREATE DATABASE functional_tests"

    - name: Copy database
      run: cat tests/_data/test.sql | docker exec -i mysql_container mysql -u root --password=**** functional_tests

    - name: Switch database
      run: docker exec -t php /var/www/bin/console app:dev:marketplace:switch functional_tests

    - name: Execute migrations
      run: docker exec -t php /var/www/bin/console --no-interaction doctrine:migrations:migrate

    - name: Populate database
      run: docker exec -t my_container php /var/www/bin/console fos:elastica:populate

    # —— Generate Assets ???? ———————————————————————————————————————————————————————————
    - name: Install assets
      run: |
        docker exec -t my_container php /var/www/bin/console assets:install
        docker exec -t my_container php /var/www/bin/console assetic:dump

    # —— Tests ✅ ———————————————————————————————————————————————————————————
    - name: Run functional tests
      run: docker exec -t my_container php codeception:functional

    - name: Run Unit Tests
      run: php vendor/phpunit/phpunit/phpunit -c app/

And here is the logs of the action step :

Github Action log

Anyone know why the step don't faile and how to throw an error ?

Questioner
Samuel
Viewed
6
riQQ 2020-06-10 23:28

Probably codeception:functional set an exit code = 0 even though an error occured. docker exec passes the exit code of the process through. GitHub Actions fails the step if a command returns with an exit code != 0.