避免 GitHub 操作缓冲

fol*_*bis 7 github github-actions

我有一个 Github 存储库,其中包含一些 Linux 实用程序。

为了运行测试,我使用 GitHub 操作和一些简单的自定义工作流程,这些工作流程使用自托管运行器在远程 Linux 服务器上运行:

name: CMake
on: [push]
env:  
  BUILD_TYPE: Release
jobs:
  build:
    runs-on: self-hosted
    steps:
    - uses: actions/checkout@v2
    - name: Build
      working-directory: ${{runner.workspace}}/Utils
      shell: bash
      run: cmake --build . --config $BUILD_TYPE

    - name: Run test
      working-directory: ${{runner.workspace}}/Utils
      shell: bash
      run: ./testing/test.sh
Run Code Online (Sandbox Code Playgroud)

工作流程非常简单 - 我使用编译源代码cmake,然后运行来自同一存储库的脚本来测试构建。测试脚本是一个 bash 脚本,如下所示:

#!/bin/bash

export LD_LIBRARY_PATH=/path/to/bin

cd /path/to/bin

echo -e "Starting the tests"

./run_server &
./run_tests

if [ $? -eq 0 ]; then
    echo "successful"
else
    echo "failed"
    exit 1
fi
Run Code Online (Sandbox Code Playgroud)

这里的脚本从我的代码(run_server)启动一个已编译的应用程序,然后运行与其通信并打印结果的测试实用程序。

实际上我printf()在里面使用Crun_tests来打印输出字符串。如果我在本地计算机上运行它,我会得到如下输出:

Starting the tests
test1 executed Ok
test2 executed Ok
test3 executed Ok
successful
Run Code Online (Sandbox Code Playgroud)

每次测试大约需要 1 秒。所以我的应用程序testX executed Ok每秒打印一行。

但如果它使用 Github actions 运行,输出看起来会有点不同(从 Github actions 控制台复制):

./testing/test.sh
  shell: /bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    BUILD_TYPE: Release
    
Starting the tests   
successful
Run Code Online (Sandbox Code Playgroud)

即使在这种情况下,bash 脚本的输出也只有在脚本完成后才会打印出来。所以我有两个问题:

  • printf()测试应用程序没有输出
  • 脚本输出(使用 打印echo)仅在脚本完成后出现

我期望 Github 操作的行为与我在本地计算机上得到的行为相同,即我看到打印的行约为 1/秒。立即地。

看起来 Github 操作会缓冲所有输出,直到执行一个步骤,并忽略 bash 脚本内运行的应用程序的所有打印。

有没有办法在步骤执行时实时获取所有输出?