Search code examples
automated-testsgithub-actionsrobotframework

Robot framework run on Github actions can't get test return codes


I am using Github actions to run my test with robot framework, when test complete, and in bash shell I can get return code in special variable via $?, but even test fail it also get 0

name: Test
on: [workflow_dispatch]

jobs:
  TEST-Run:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: install
      run: |
        pip3 install -r requirements.txt

    - name: Run Tests
      run: |
        robot test.robot

    - name: Set Robot Return Code
      run: |
        echo "ROBOT_RC=$?" >> "$GITHUB_ENV"

    - name: If Auto Test Pass Rate Not 100%, Job Will Fail
      if: env.ROBOT_RC != '0'
      run: |
        echo "Auto Test Pass Rate Not 100%, Please Check Test Result"
        exit 1

Any help or explanation is welcome! Thank you.


Solution

  • According to jobs.<job_id>.steps[*].run:

    Each run keyword represents a new process and shell in the runner environment. When you provide multi-line commands, each line runs in the same shell.

    So, you need to combine those steps in one:

        - name: Run Tests
          run: |
            robot test.robot
            echo "ROBOT_RC=$?" >> "$GITHUB_ENV"
    

    or,

        - name: Run Tests
          run: |
            robot test.robot; ROBOT_RC=$?
            echo "ROBOT_RC=$ROBOT_RC" >> "$GITHUB_ENV"
    

    See jobs.<job_id>.steps[*].shell for more details.