Avoid GitHub action buffering

I have a Github repo that contains some Linux utilites.

To run test I use GitHub actions and some simple custom workflow that runs on a remote Linux server using self-hosted runner:

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

The workflow is very simple - I compile the source using cmake and then run a script from the same repo to test the build. The test script is a bash script and looks as following:

#!/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

Here the scripts starts up an compiled application from my code (run_server) and then run the testing utility that communicates with it and prints a result.

Actually I use C printf() inside run_tests to print the output strings. If I run that on a local machine I get output like the following:

Starting the tests
test1 executed Ok
test2 executed Ok
test3 executed Ok
successful

Each test takes about 1 sec. so I the application prints a line like testX executed Ok one per second.

But if it runs using Github actions the output looks a bit different (copied from the Github actions console):

./testing/test.sh
  shell: /bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    BUILD_TYPE: Release
    
Starting the tests   
successful

And even in this case the output from the bash script printed out only after the script has finished. So I have 2 problems:

  • no printf() output from the test application
  • the script output (printed using echo ) come only after the script has finished

I expected the same behavior from the Github action as I get on a local machine i.e. I see a lines printed ~ 1/sec. immediately.

It looks like Github action buffers all the output until a step executed and ignores all the print from the application that run inside the bash script.

Is there a way to get all the output in real time while a step executes?

@folibis,

I tested on the GitHub-hosted runners, and the output of printf() in the C file can be displayed normally in the logs of the step.

You can try to upgrade or install Git and GCC with the latest version on your Linux machine, then try the workflow again to see if the problem still exists.

Ok, I see that your workflow is almost the same as mine. For some reason I see no output from the application. I see output from the bash echo but not from the C printf. Currently I’ve found the following workaround:
in the bash:

./run_tests > test_result

in the workflow:

- name: Get result
      working-directory: ${{runner.workspace}}/Utils
      id: results
      if: ${{ failure() }}
      run: echo ::set-output name=result::$(cat ./test_result)

    - name: Test output
      run: echo "${{ steps.results.outputs.result }}"

It prints the application’s output but only after the step has finished. I want to see the output in the realtime but as I understand currently it’s impossible. And for some reason I see the output as one line. replacing \n with \r\n takes no effect.

@folibis,

Which version of the GCC are you using in your Linux machine?
As I suggested above, please try to install the GCC with the latest version on your machine to see if the problems can be solved.

The problems may be caused by the older version of GCC (may also include the Git Bash version).