As per GitHub's recent announcement, github action's set-output
is going to be deprecated next year. I was able to use the new format (echo "{name}={value}" >> $GITHUB_OUTPUT
) in workflow file, and it works. But we also have a custom GitHub action(private one) written in python and we are also using set-output
there in main.py
as:
output_matrix = json.dumps(jsondata)
print(f"::set-output name=output_matrix::{output_matrix}")
What I have tried so far is :
print(f"output_matrix = {output_matrix} >> $GITHUB_OUTPUT")
but this doesn't seem to help. Any solution how we can use set-output
's new format inside custom github action python file.
CodePudding user response:
I made a test here using this workflow implementation and this python script.
What you can do in a python script is the same implementation for outputs variables as for environments variables.
Example for ENVIRONMENTS variables: (here is another topic about it)
import os
env_file = os.getenv('GITHUB_ENV')
hello='hello'
with open(env_file, "a") as myfile:
myfile.write(f"TEST={hello}")
Example for OUTPUTS variables:
import os
output_file = os.getenv('GITHUB_OUTPUT')
hello='hello'
with open(output_file, "a") as myfile:
myfile.write(f"TEST={hello}")
Note that this implementation was working even before the update regarding the ::set-output
depreciation.
CodePudding user response:
Did you try with:
os.environ['GITHUB_OUTPUT'] = f"output_matrix = {output_matrix}"