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

风格不统一 提交于 2021-01-28 13:47:41

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/62303997/how-to-stop-github-actions-step-when-functional-tests-failed-using-codeception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!