-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Describe the bug
In my company CI pipeline with GitHub Actions, recently a weird behavior started to appear when I ran a script that outputed a new environment variable with print:
echo "IMAGE_NAME=$(python -m buggy_deployment_manager --silent build $ENV .)" >> $GITHUB_ENVThis week or so, we've discovered it started to break all of our workflow jobs (GHA) with:
Error: Unable to process file command 'env' successfully.
Error: Invalid environment variable format '***.dkr.ecr.***.amazonaws.com/some-image-name'
Which usually happens when some unsupported character goes into the GITHUB_ENV file.
Going deep into the problem I found out that there was a newline being outputed to $GITHUB_ENV, although there was no print statement other than only one in the buggy_deployment_manager module, and no logging or etc was being held in the stdout buffer explicitly.
With pdb and flushing all print outputs, I've discovered that the context manager Status from rich actually (somehow and to somewhere) inside this buggy_deployment_manager prints out a newline to echo once it ends. This \n only appeared with echo, which is a weird behavior, I don't think it was supposed to happen or why it happened.
To Reproduce
Create a script named bug.py with:
from rich.status import Status
print("1 ", end="")
with Status("Go"):
print("2 ", end="")
print("3 ", end="")And run with:
#!/bin/bash
echo "WHAT=$(python bug.py)"Instead of:
WHAT=1 2 3
It will write:
WHAT=1 2
3
Platform
I've used locally on MacOS 12.0.1, Ubuntu 20.04 and within our CI runner ( Debian 11 ) with:
- Python 3.8.10, 3.9.7, 3.9.8;