Skip to content
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

Merged
merged 5 commits into from Oct 23, 2022
Merged

Conversation

parkerbxyz
Copy link
Contributor

@parkerbxyz parkerbxyz commented Oct 21, 2022

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

  • Add entry to the CHANGELOG listing the change and linking to the corresponding issue (if appropriate)
  • If documentation is needed for this change, has that been included in this pull request

Reviewing Maintainer

  • Label as breaking if this is a large fundamental change
  • Label as either automation, bug, documentation, enhancement, infrastructure, or performance

@parkerbxyz
Copy link
Contributor Author

The build no longer shows the following annotations, so it looks like these changes are working as intended! 🎉

Tests + Deploy Docker Image - DEV

The set-output command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

@parkerbxyz parkerbxyz marked this pull request as ready for review October 22, 2022 02:06
@nvuillam
Copy link
Member

@parkerbxyz please can you make your branch up to date with main ? it will fix CI issues not related to your PR :)

@codecov-commenter
Copy link

Codecov Report

Merging #1986 (9a01349) into main (e957998) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            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     
Impacted Files Coverage Δ
megalinter/MegaLinter.py 83.53% <100.00%> (ø)
megalinter/reporters/UpdatedSourcesReporter.py 89.74% <0.00%> (+2.56%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@nvuillam nvuillam left a 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

@nvuillam nvuillam merged commit 2561f74 into oxsecurity:main Oct 23, 2022
Copy link
Collaborator

@Kurt-von-Laven Kurt-von-Laven left a 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"')
Copy link
Collaborator

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.

Copy link
Member

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 )

Copy link
Contributor Author

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)
Suggested change
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)

nvuillam pushed a commit that referenced this pull request Oct 23, 2022
@@ -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"')
Copy link
Contributor Author

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)
Suggested change
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"')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

Copy link
Member

@nvuillam nvuillam Oct 23, 2022

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 ...

Copy link
Collaborator

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")

Copy link
Member

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() ?

Copy link
Collaborator

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.

Copy link
Member

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 :)

Copy link
Member

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... 😠 🤣 )

Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants