Robot framework在Github Actions上运行时无法获取测试返回代码。

huangapple go评论61阅读模式
英文:

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

问题

以下是代码部分的翻译:

name: 测试
on: [workflow_dispatch]

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

    - name: 运行测试
      run: |
                robot test.robot

    - name: 设置 Robot 返回码
      run: |
                echo "ROBOT_RC=$?" >> "$GITHUB_ENV"

    - name: 如果自动测试通过率不是100%,作业将失败
      if: env.ROBOT_RC != '0'
      run: |
        echo "自动测试通过率不是100%,请检查测试结果"
        exit 1        

请注意,我只翻译了代码部分,没有包含问题的其他内容。

英文:

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.

答案1

得分: 4

根据jobs.<job_id>.steps[*].run

每个run关键字代表运行 runner 环境中的新进程和 shell。当您提供多行命令时,每行在同一个 shell 中运行。

因此,您需要将这些步骤合并在一个中:

    - name: 运行测试
      run: |
        robot test.robot
        echo "ROBOT_RC=$?" >> "$GITHUB_ENV"        

或者,

    - name: 运行测试
      run: |
        robot test.robot; ROBOT_RC=$?
        echo "ROBOT_RC=$ROBOT_RC" >> "$GITHUB_ENV"        

有关更多详细信息,请参阅jobs.<job_id>.steps[*].shell

英文:

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.

huangapple
  • 本文由 发表于 2023年2月19日 22:43:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75500917.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定