Search code examples
pythongithub-actions

Print all python logs within GitHub Action


I have a GitHub Action that calls a python script:

- name: Test Python Script
  run: |
     python python_script.py

This runs fine and prints me the logs from within here:

if __name__ == "__ main __":
   print('Calling function')
   func_call()
   print('End of script')

However, I don't get the print statements from func_call itself:

def func_call() :
  print('inside func_call')

When I run from my own terminal, the output is:

Calling function
inside func_call
End of script

Yet when I run from a GitHub Action I only get:

Calling function
End of script

Is there a way I can propagate all print statements to the GitHub Action logs?


Solution

  • The solution was relatively simple, just adding the -u flag:

    - name: Test Python Script
      run: |
         python -u python_script.py
    

    From man python:

     -u     Force stdin, stdout and stderr to  be  totally  unbuffered.   On systems  where  it matters, also put stdin, stdout and stderr in
    binary mode.