New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace set-output
command
#1986
Conversation
Use `{ cmd1; cmd2; } >> file` instead of individual redirects per shellcheck ([SC2129](https://www.shellcheck.net/wiki/SC2129)).
The build no longer shows the following annotations, so it looks like these changes are working as intended! 🎉
|
@parkerbxyz please can you make your branch up to date with main ? it will fix CI issues not related to your PR :) |
Codecov Report
@@ Coverage Diff @@
## main #1986 +/- ##
==========================================
+ Coverage 82.68% 82.71% +0.02%
==========================================
Files 157 157
Lines 3384 3384
==========================================
+ Hits 2798 2799 +1
+ Misses 586 585 -1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the catch :)
Let's hope you know what you are doing, else release CI jobs are broken :D :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parkerbxyz, thanks for taking a pass at this.
@@ -2757,7 +2757,7 @@ def manage_output_variables(): | |||
updated_versions = 1 | |||
break | |||
if updated_versions == 1: | |||
print("::set-output name=has_updated_versions::1") | |||
print('"has_updated_versions=1" >>"$GITHUB_OUTPUT"') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Bash changes look correct at a glance, but I suspect printing Bash syntax from Python has no special effect. See EnricoMi/publish-unit-test-result-action#360 for an example of the correct syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid you're right... I'll rollback the PR to not break behaviour until we have a working solution ( cc @parkerbxyz )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect printing Bash syntax from Python has no special effect
In that case, is it working as expected without my changes?
How about something like this?
import shlex, subprocess
add_to_output_cmd = 'echo "has_updated_versions=1" >>"$GITHUB_OUTPUT"'
add_to_output_args = shlex.split(add_to_output_cmd)
subprocess.run(add_to_output_args)
print('"has_updated_versions=1" >>"$GITHUB_OUTPUT"') | |
add_to_output_cmd = 'echo "has_updated_versions=1" >>"$GITHUB_OUTPUT"' | |
add_to_output_args = shlex.split(add_to_output_cmd) | |
subprocess.run(add_to_output_args) |
This reverts commit 2561f74.
@@ -2757,7 +2757,7 @@ def manage_output_variables(): | |||
updated_versions = 1 | |||
break | |||
if updated_versions == 1: | |||
print("::set-output name=has_updated_versions::1") | |||
print('"has_updated_versions=1" >>"$GITHUB_OUTPUT"') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect printing Bash syntax from Python has no special effect
In that case, is it working as expected without my changes?
How about something like this?
import shlex, subprocess
add_to_output_cmd = 'echo "has_updated_versions=1" >>"$GITHUB_OUTPUT"'
add_to_output_args = shlex.split(add_to_output_cmd)
subprocess.run(add_to_output_args)
print('"has_updated_versions=1" >>"$GITHUB_OUTPUT"') | |
add_to_output_cmd = 'echo "has_updated_versions=1" >>"$GITHUB_OUTPUT"' | |
add_to_output_args = shlex.split(add_to_output_cmd) | |
subprocess.run(add_to_output_args) |
@@ -822,7 +822,7 @@ def display_header(): | |||
logging.info("") | |||
|
|||
def check_results(self): | |||
print(f"::set-output name=has_updated_sources::{str(self.has_updated_sources)}") | |||
print(f'"has_updated_sources={str(self.has_updated_sources)}" >>"$GITHUB_OUTPUT"') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(f'"has_updated_sources={str(self.has_updated_sources)}" >>"$GITHUB_OUTPUT"') | |
add_to_output_cmd = f'echo "has_updated_sources={str(has_updated_sources)}" >>"$GITHUB_OUTPUT"' | |
add_to_output_args = shlex.split(add_to_output_cmd) | |
subprocess.run(add_to_output_args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could work, but it will update $GITHUB_OUTPUT within MegaLinter docker image
Will Github Action workflow retrieve the variable from inside the docker image ? if not we have to find another way (maybe some dummy file in artifacts that we could check for existence ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the existing code looks correct, just deprecated. The goal here is simply to append to the file named GITHUB_OUTPUT
, so we can achieve that without spawning a process.
from os import environ
output_file = environ["GITHUB_OUTPUT"]
with open(output_file, "a", encoding="utf-8") as output_stream:
output_stream.write(f"has_updated_sources={str(self.has_updated_sources)}\n")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kurt-von-Laven print(), not output_stream.write() ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last line could be replaced with:
output_stream.write(f"has_updated_sources={str(self.has_updated_sources)}\n")
Any preference?
Just saw your previous message. To be clear, we don’t want to overwrite the environment variable GITHUB_OUTPUT
, which is essentially the path to a magic dummy file that gets sourced at the beginning of each subsequent step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer the write option , it's more readable that a print that we expect more to be just a line in the console :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parkerbxyz maybe u'd like to ressuscitate your PR and update it ? :) ( ps: just been rickrolled... 😠 🤣 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me. I updated the code snippet accordingly.
Ha ha, the meme that will never die.
Replaces the soon-to-be deprecated
set-output
command.Reference: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
Readiness Checklist
Author/Contributor
Reviewing Maintainer
breaking
if this is a large fundamental changeautomation
,bug
,documentation
,enhancement
,infrastructure
, orperformance